|
11 | 11 | from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
|
12 | 12 | from opentelemetry.trace import SpanKind
|
13 | 13 |
|
| 14 | +from azure.monitor.opentelemetry.exporter._constants import _SAMPLE_RATE_KEY |
14 | 15 | from azure.monitor.opentelemetry.exporter import _utils
|
15 | 16 | from azure.monitor.opentelemetry.exporter._generated.models import (
|
16 | 17 | MessageData,
|
|
45 | 46 | "code.",
|
46 | 47 | ]
|
47 | 48 |
|
| 49 | +_STANDARD_AZURE_MONITOR_ATTRIBUTES = [ |
| 50 | + _SAMPLE_RATE_KEY, |
| 51 | +] |
| 52 | + |
48 | 53 |
|
49 | 54 | class AzureMonitorTraceExporter(BaseExporter, SpanExporter):
|
50 | 55 | """Azure Monitor Trace exporter for OpenTelemetry."""
|
@@ -420,9 +425,13 @@ def _convert_span_to_envelope(span: ReadableSpan) -> TelemetryItem:
|
420 | 425 | if target:
|
421 | 426 | data.target = str(target)[:1024]
|
422 | 427 |
|
| 428 | + # sampleRate |
| 429 | + if _SAMPLE_RATE_KEY in span.attributes: |
| 430 | + envelope.sample_rate = span.attributes[_SAMPLE_RATE_KEY] |
| 431 | + |
423 | 432 | data.properties = _utils._filter_custom_properties(
|
424 | 433 | span.attributes,
|
425 |
| - lambda key, val: not _is_opentelemetry_standard_attribute(key) |
| 434 | + lambda key, val: not _is_standard_attribute(key) |
426 | 435 | )
|
427 | 436 | if span.links:
|
428 | 437 | # Max length for value is 8192
|
@@ -450,7 +459,7 @@ def _convert_span_events_to_envelopes(span: ReadableSpan) -> Sequence[TelemetryI
|
450 | 459 | )
|
451 | 460 | properties = _utils._filter_custom_properties(
|
452 | 461 | event.attributes,
|
453 |
| - lambda key, val: not _is_opentelemetry_standard_attribute(key) |
| 462 | + lambda key, val: not _is_standard_attribute(key) |
454 | 463 | )
|
455 | 464 | if event.name == "exception":
|
456 | 465 | envelope.name = 'Microsoft.ApplicationInsights.Exception'
|
@@ -545,11 +554,12 @@ def _check_instrumentation_span(span: ReadableSpan) -> None:
|
545 | 554 | _utils.add_instrumentation(name)
|
546 | 555 |
|
547 | 556 |
|
548 |
| -def _is_opentelemetry_standard_attribute(key: str) -> bool: |
| 557 | +def _is_standard_attribute(key: str) -> bool: |
549 | 558 | for prefix in _STANDARD_OPENTELEMETRY_ATTRIBUTE_PREFIXES:
|
550 | 559 | if key.startswith(prefix):
|
551 | 560 | return True
|
552 |
| - return False |
| 561 | + return key in _STANDARD_AZURE_MONITOR_ATTRIBUTES |
| 562 | + |
553 | 563 |
|
554 | 564 | def _get_azure_sdk_target_source(attributes: Attributes) -> Optional[str]:
|
555 | 565 | # Currently logic only works for ServiceBus and EventHub
|
|
0 commit comments