Merge 0dbdc448e7 into sapling-pr-archive-ehhuang

This commit is contained in:
ehhuang 2025-10-20 11:20:50 -07:00 committed by GitHub
commit c29b8605b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,6 +4,7 @@
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.
import os
import threading
from typing import Any
@ -60,6 +61,7 @@ class TelemetryAdapter(Telemetry):
# Recreating the telemetry adapter multiple times will result in duplicate span processors.
# Since the library client can be recreated multiple times in a notebook,
# the kernel will hold on to the span processor and cause duplicate spans to be written.
if os.environ.get("OTEL_EXPORTER_OTLP_ENDPOINT"):
if _TRACER_PROVIDER is None:
provider = TracerProvider()
trace.set_tracer_provider(provider)
@ -77,6 +79,8 @@ class TelemetryAdapter(Telemetry):
metric_reader = PeriodicExportingMetricReader(OTLPMetricExporter())
metric_provider = MeterProvider(metric_readers=[metric_reader])
metrics.set_meter_provider(metric_provider)
else:
logger.warning("OTEL_EXPORTER_OTLP_ENDPOINT is not set, skipping telemetry")
self.meter = metrics.get_meter(__name__)
self._lock = _global_lock