Skip to content

Commit

Permalink
CP-49876: Create spans for observer.py itself
Browse files Browse the repository at this point in the history
Creates two spans for observer.py, one for the entire script and one for
the opentelemtry import statements. This fixes the current discrepancy
between the sm script span and the outer xapi span.

Signed-off-by: Steven Woods <[email protected]>
  • Loading branch information
snwoods committed Jul 29, 2024
1 parent 0623d8d commit 29344a7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python3/packages/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
passed script without any instrumentation.
"""

import time

def to_otel_timestamp(ts):
return int(ts * 1000000000)

observer_ts_start = to_otel_timestamp(time.time())
observer_mono_start = time.monotonic()

def current_otel_time():
return observer_ts_start + to_otel_timestamp(time.monotonic() - observer_mono_start)

import configparser
import functools
import inspect
Expand Down Expand Up @@ -117,6 +128,9 @@ def _init_tracing(configs: List[str], config_dir: str):

# On 3.10-3.12, the import of wrapt might trigger warnings, filter them:
simplefilter(action="ignore", category=DeprecationWarning)

import_ts_start = current_otel_time()

import wrapt # type: ignore[import-untyped]
from opentelemetry import context, trace
from opentelemetry.baggage.propagation import W3CBaggagePropagator
Expand All @@ -127,6 +141,8 @@ def _init_tracing(configs: List[str], config_dir: str):
from opentelemetry.trace.propagation.tracecontext import (
TraceContextTextMapPropagator,
)

import_ts_end = current_otel_time()
except ImportError as err:
syslog.error("missing opentelemetry dependencies: %s", err)
return _span_noop, _patch_module_noop
Expand Down Expand Up @@ -359,6 +375,12 @@ def _patch_module(module_name):
for m in module_names:
_patch_module(m)

# Create spans to track observer.py's setup duration
t = tracers[0]
with t.start_as_current_span("observer.py:init_tracing", start_time=observer_ts_start):
import_span = t.start_span("observer.py:imports", start_time=import_ts_start)
import_span.end(end_time=import_ts_end)

return span_of_tracers, _patch_module


Expand Down

0 comments on commit 29344a7

Please sign in to comment.