mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-31 14:11:50 +08:00
Parent is now always passed in via Context, intead of Span or SpanContext (#1146)
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
This commit is contained in:
@ -189,12 +189,12 @@ class DatadogSpanExporter(SpanExporter):
|
||||
|
||||
def _get_trace_ids(span):
|
||||
"""Extract tracer ids from span"""
|
||||
ctx = span.get_context()
|
||||
ctx = span.get_span_context()
|
||||
trace_id = ctx.trace_id
|
||||
span_id = ctx.span_id
|
||||
|
||||
if isinstance(span.parent, trace_api.Span):
|
||||
parent_id = span.parent.get_context().span_id
|
||||
parent_id = span.parent.get_span_context().span_id
|
||||
elif isinstance(span.parent, trace_api.SpanContext):
|
||||
parent_id = span.parent.span_id
|
||||
else:
|
||||
@ -255,13 +255,13 @@ def _get_exc_info(span):
|
||||
|
||||
|
||||
def _get_origin(span):
|
||||
ctx = span.get_context()
|
||||
ctx = span.get_span_context()
|
||||
origin = ctx.trace_state.get(DD_ORIGIN)
|
||||
return origin
|
||||
|
||||
|
||||
def _get_sampling_rate(span):
|
||||
ctx = span.get_context()
|
||||
ctx = span.get_span_context()
|
||||
return (
|
||||
span.sampler.rate
|
||||
if ctx.trace_flags.sampled
|
||||
|
@ -86,7 +86,7 @@ class DatadogFormat(TextMapPropagator):
|
||||
context: typing.Optional[Context] = None,
|
||||
) -> None:
|
||||
span = get_current_span(context)
|
||||
span_context = span.get_context()
|
||||
span_context = span.get_span_context()
|
||||
if span_context == trace.INVALID_SPAN_CONTEXT:
|
||||
return
|
||||
sampled = (trace.TraceFlags.SAMPLED & span.context.trace_flags) != 0
|
||||
|
@ -82,7 +82,7 @@ class DatadogExportSpanProcessor(SpanProcessor):
|
||||
self.worker_thread.start()
|
||||
|
||||
def on_start(self, span: Span) -> None:
|
||||
ctx = span.get_context()
|
||||
ctx = span.get_span_context()
|
||||
trace_id = ctx.trace_id
|
||||
|
||||
with self.traces_lock:
|
||||
@ -102,7 +102,7 @@ class DatadogExportSpanProcessor(SpanProcessor):
|
||||
logger.warning("Already shutdown, dropping span.")
|
||||
return
|
||||
|
||||
ctx = span.get_context()
|
||||
ctx = span.get_span_context()
|
||||
trace_id = ctx.trace_id
|
||||
|
||||
with self.traces_lock:
|
||||
|
@ -178,7 +178,7 @@ class TestDatadogSpanExporter(unittest.TestCase):
|
||||
span_context = trace_api.SpanContext(
|
||||
trace_id, span_id, is_remote=False
|
||||
)
|
||||
parent_context = trace_api.SpanContext(
|
||||
parent_span_context = trace_api.SpanContext(
|
||||
trace_id, parent_id, is_remote=False
|
||||
)
|
||||
other_context = trace_api.SpanContext(
|
||||
@ -191,14 +191,14 @@ class TestDatadogSpanExporter(unittest.TestCase):
|
||||
trace._Span(
|
||||
name=span_names[0],
|
||||
context=span_context,
|
||||
parent=parent_context,
|
||||
parent=parent_span_context,
|
||||
kind=trace_api.SpanKind.CLIENT,
|
||||
instrumentation_info=instrumentation_info,
|
||||
resource=Resource({}),
|
||||
),
|
||||
trace._Span(
|
||||
name=span_names[1],
|
||||
context=parent_context,
|
||||
context=parent_span_context,
|
||||
parent=None,
|
||||
instrumentation_info=instrumentation_info,
|
||||
resource=resource_without_service,
|
||||
|
@ -51,7 +51,7 @@ class TestDatadogFormat(unittest.TestCase):
|
||||
malformed_parent_id_key: self.serialized_parent_id,
|
||||
},
|
||||
)
|
||||
).get_context()
|
||||
).get_span_context()
|
||||
|
||||
self.assertNotEqual(context.trace_id, int(self.serialized_trace_id))
|
||||
self.assertNotEqual(context.span_id, int(self.serialized_parent_id))
|
||||
@ -64,7 +64,7 @@ class TestDatadogFormat(unittest.TestCase):
|
||||
}
|
||||
|
||||
ctx = FORMAT.extract(get_as_list, carrier)
|
||||
span_context = get_current_span(ctx).get_context()
|
||||
span_context = get_current_span(ctx).get_span_context()
|
||||
self.assertEqual(span_context.trace_id, trace_api.INVALID_TRACE_ID)
|
||||
|
||||
def test_missing_parent_id(self):
|
||||
@ -74,12 +74,12 @@ class TestDatadogFormat(unittest.TestCase):
|
||||
}
|
||||
|
||||
ctx = FORMAT.extract(get_as_list, carrier)
|
||||
span_context = get_current_span(ctx).get_context()
|
||||
span_context = get_current_span(ctx).get_span_context()
|
||||
self.assertEqual(span_context.span_id, trace_api.INVALID_SPAN_ID)
|
||||
|
||||
def test_context_propagation(self):
|
||||
"""Test the propagation of Datadog headers."""
|
||||
parent_context = get_current_span(
|
||||
parent_span_context = get_current_span(
|
||||
FORMAT.extract(
|
||||
get_as_list,
|
||||
{
|
||||
@ -89,31 +89,31 @@ class TestDatadogFormat(unittest.TestCase):
|
||||
FORMAT.ORIGIN_KEY: self.serialized_origin,
|
||||
},
|
||||
)
|
||||
).get_context()
|
||||
).get_span_context()
|
||||
|
||||
self.assertEqual(
|
||||
parent_context.trace_id, int(self.serialized_trace_id)
|
||||
parent_span_context.trace_id, int(self.serialized_trace_id)
|
||||
)
|
||||
self.assertEqual(
|
||||
parent_context.span_id, int(self.serialized_parent_id)
|
||||
parent_span_context.span_id, int(self.serialized_parent_id)
|
||||
)
|
||||
self.assertEqual(parent_context.trace_flags, constants.AUTO_KEEP)
|
||||
self.assertEqual(parent_span_context.trace_flags, constants.AUTO_KEEP)
|
||||
self.assertEqual(
|
||||
parent_context.trace_state.get(constants.DD_ORIGIN),
|
||||
parent_span_context.trace_state.get(constants.DD_ORIGIN),
|
||||
self.serialized_origin,
|
||||
)
|
||||
self.assertTrue(parent_context.is_remote)
|
||||
self.assertTrue(parent_span_context.is_remote)
|
||||
|
||||
child = trace._Span(
|
||||
"child",
|
||||
trace_api.SpanContext(
|
||||
parent_context.trace_id,
|
||||
parent_span_context.trace_id,
|
||||
trace_api.RandomIdsGenerator().generate_span_id(),
|
||||
is_remote=False,
|
||||
trace_flags=parent_context.trace_flags,
|
||||
trace_state=parent_context.trace_state,
|
||||
trace_flags=parent_span_context.trace_flags,
|
||||
trace_state=parent_span_context.trace_state,
|
||||
),
|
||||
parent=parent_context,
|
||||
parent=parent_span_context,
|
||||
)
|
||||
|
||||
child_carrier = {}
|
||||
@ -136,7 +136,7 @@ class TestDatadogFormat(unittest.TestCase):
|
||||
|
||||
def test_sampling_priority_auto_reject(self):
|
||||
"""Test sampling priority rejected."""
|
||||
parent_context = get_current_span(
|
||||
parent_span_context = get_current_span(
|
||||
FORMAT.extract(
|
||||
get_as_list,
|
||||
{
|
||||
@ -145,20 +145,22 @@ class TestDatadogFormat(unittest.TestCase):
|
||||
FORMAT.SAMPLING_PRIORITY_KEY: str(constants.AUTO_REJECT),
|
||||
},
|
||||
)
|
||||
).get_context()
|
||||
).get_span_context()
|
||||
|
||||
self.assertEqual(parent_context.trace_flags, constants.AUTO_REJECT)
|
||||
self.assertEqual(
|
||||
parent_span_context.trace_flags, constants.AUTO_REJECT
|
||||
)
|
||||
|
||||
child = trace._Span(
|
||||
"child",
|
||||
trace_api.SpanContext(
|
||||
parent_context.trace_id,
|
||||
parent_span_context.trace_id,
|
||||
trace_api.RandomIdsGenerator().generate_span_id(),
|
||||
is_remote=False,
|
||||
trace_flags=parent_context.trace_flags,
|
||||
trace_state=parent_context.trace_state,
|
||||
trace_flags=parent_span_context.trace_flags,
|
||||
trace_state=parent_span_context.trace_state,
|
||||
),
|
||||
parent=parent_context,
|
||||
parent=parent_span_context,
|
||||
)
|
||||
|
||||
child_carrier = {}
|
||||
|
Reference in New Issue
Block a user