This commit is contained in:
Родитель
6e813434d5
Коммит
698ca4119b
|
@ -7,10 +7,13 @@ from opentelemetry.sdk._logs import LoggingHandler
|
|||
from opentelemetry.util.types import Attributes
|
||||
|
||||
|
||||
_APPLICATION_INSIGHTS_EVENT_MARKER_ATTRIBUTE = "APPLICATION_INSIGHTS_EVENT_MARKER_ATTRIBUTE"
|
||||
_APPLICATION_INSIGHTS_EVENT_MARKER_ATTRIBUTE = (
|
||||
"APPLICATION_INSIGHTS_EVENT_MARKER_ATTRIBUTE"
|
||||
)
|
||||
_event_logger = getLogger(__name__)
|
||||
_event_logger.propagate = False
|
||||
|
||||
|
||||
class _AzureMonitorOpenTelemetryEventHandler(LoggingHandler):
|
||||
@staticmethod
|
||||
def _get_attributes(record: LogRecord) -> Attributes:
|
||||
|
@ -18,14 +21,17 @@ class _AzureMonitorOpenTelemetryEventHandler(LoggingHandler):
|
|||
attributes[_APPLICATION_INSIGHTS_EVENT_MARKER_ATTRIBUTE] = True
|
||||
return attributes
|
||||
|
||||
|
||||
class _AzureMonitorEventsExtension:
|
||||
_initialized = False
|
||||
|
||||
def _initialize():
|
||||
if not _AzureMonitorEventsExtension._initialized:
|
||||
_event_logger.addHandler(_AzureMonitorOpenTelemetryEventHandler())
|
||||
_event_logger.setLevel(INFO)
|
||||
_AzureMonitorEventsExtension._initialized = True
|
||||
|
||||
|
||||
def track_event(name: str, custom_dimensions: Optional[Dict[str, str]] = None):
|
||||
_AzureMonitorEventsExtension._initialize()
|
||||
_event_logger.info(name, extra=custom_dimensions)
|
||||
|
|
|
@ -10,6 +10,6 @@ configure_azure_monitor()
|
|||
|
||||
# Use the track_event() api to send custom event telemetry
|
||||
# Takes event name and custom dimensions
|
||||
track_event("Test event", {"key1":"value1", "key2":"value2"})
|
||||
track_event("Test event", {"key1": "value1", "key2": "value2"})
|
||||
|
||||
input()
|
||||
|
|
|
@ -31,9 +31,7 @@ if not version:
|
|||
setup(
|
||||
name=PACKAGE_NAME,
|
||||
version=version,
|
||||
description="Microsoft {} for Python".format(
|
||||
PACKAGE_PPRINT_NAME
|
||||
),
|
||||
description="Microsoft {} for Python".format(PACKAGE_PPRINT_NAME),
|
||||
long_description=open("README.md", "r").read(),
|
||||
long_description_content_type="text/markdown",
|
||||
license="MIT License",
|
||||
|
|
Загрузка…
Ссылка в новой задаче