We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dce07f5 commit 18d13dbCopy full SHA for 18d13db
1 file changed
src/croudtech_gcp_otel/logging.py
@@ -62,14 +62,15 @@ def _get_trace_context(self, record):
62
from opentelemetry import trace
63
64
span = trace.get_current_span()
65
- if span and span.is_recording():
66
- ctx = span.get_span_context()
67
- if ctx.is_valid:
68
- return (
69
- format(ctx.trace_id, '032x'),
70
- format(ctx.span_id, '016x'),
71
- ctx.trace_flags.sampled
72
- )
+ span_context = span.get_span_context() if span else None
+
+ # Check if we have a valid, recording span
+ if span_context and span_context.is_valid:
+ return (
+ format(span_context.trace_id, '032x'),
+ format(span_context.span_id, '016x'),
+ span_context.trace_flags.sampled if hasattr(span_context.trace_flags, 'sampled') else False
73
+ )
74
except ImportError:
75
pass
76
except Exception:
0 commit comments