forked from microsoft/opentelemetry-distro-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_events.py
More file actions
39 lines (32 loc) · 1.11 KB
/
Copy pathcustom_events.py
File metadata and controls
39 lines (32 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import os
from logging import getLogger, INFO
from microsoft.opentelemetry import use_microsoft_opentelemetry
# Connection string can also be passed directly:
# azure_monitor_connection_string="InstrumentationKey=..."
use_microsoft_opentelemetry(
enable_azure_monitor=True,
azure_monitor_connection_string=os.environ.get("APPLICATIONINSIGHTS_CONNECTION_STRING", ""),
logger_name=__name__,
)
logger = getLogger(__name__)
logger.setLevel(INFO)
# You can send `customEvent` telemetry using a special `microsoft` attribute key through logging
# The name of the `customEvent` will correspond to the value of the attribute`
logger.info(
"Hello World!",
extra={
"microsoft.custom_event.name": "test-custom-event-1",
"additional_attrs": "genai",
},
)
# You can also populate fields like client_Ip with attribute `client.address`
logger.info(
"This entry will have a custom client_Ip",
extra={
"microsoft.custom_event.name": "test-custom-event-2",
"client.address": "197.168.1.1",
},
)
input()