Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/titiler/core/titiler/core/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

from typing_extensions import ParamSpec

from titiler.core import __version__

try:
from opentelemetry import trace
from opentelemetry.trace import Span, Status, StatusCode

tracer = trace.get_tracer("titiler.core", __version__)
tracer = None
except ImportError:
trace = None
Span = None
Expand All @@ -27,10 +25,11 @@

def add_span_attributes(attributes: Dict[str, Any]) -> None:
"""Adds attributes to the current active span."""
if not tracer:
if tracer is None:
return
span = trace.get_current_span()
if span and span.is_recording():
# Avoid unnecessary is_recording() call if span is None
if span is not None and span.is_recording():
span.set_attributes(attributes)


Expand Down