|
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT License. |
| 3 | + |
| 4 | +from opentelemetry.sdk._logs import LogData, LogRecordProcessor |
| 5 | +from opentelemetry.sdk.trace import ReadableSpan, SpanProcessor |
| 6 | + |
| 7 | +from azure.monitor.opentelemetry.exporter._quickpulse._live_metrics import _QuickpulseManager |
| 8 | + |
| 9 | + |
| 10 | +# pylint: disable=protected-access |
| 11 | +class _QuickpulseLogRecordProcessor(LogRecordProcessor): |
| 12 | + def __init__(self): |
| 13 | + super().__init__() |
| 14 | + self.call_on_emit = hasattr(super(), 'on_emit') |
| 15 | + |
| 16 | + def on_emit(self, log_data: LogData) -> None: # type: ignore |
| 17 | + qpm = _QuickpulseManager._instance |
| 18 | + if qpm: |
| 19 | + qpm._record_log_record(log_data) |
| 20 | + if self.call_on_emit: |
| 21 | + super().on_emit(log_data) # type: ignore[safe-super] |
| 22 | + else: |
| 23 | + # this method was removed in opentelemetry-sdk and replaced with on_emit |
| 24 | + super().emit(log_data) # type: ignore[safe-super,misc] # pylint: disable=no-member |
| 25 | + |
| 26 | + def emit(self, log_data: LogData) -> None: |
| 27 | + self.on_emit(log_data) |
| 28 | + |
| 29 | + def shutdown(self): |
| 30 | + pass |
| 31 | + |
| 32 | + def force_flush(self, timeout_millis: int = 30000): |
| 33 | + super().force_flush(timeout_millis=timeout_millis) # type: ignore[safe-super] |
| 34 | + |
| 35 | + |
| 36 | +# pylint: disable=protected-access |
| 37 | +class _QuickpulseSpanProcessor(SpanProcessor): |
| 38 | + |
| 39 | + def on_end(self, span: ReadableSpan) -> None: |
| 40 | + qpm = _QuickpulseManager._instance |
| 41 | + if qpm: |
| 42 | + qpm._record_span(span) |
| 43 | + return super().on_end(span) |
0 commit comments