Skip to content

Commit

Permalink
Merge branch 'master' into issue_1008
Browse files Browse the repository at this point in the history
  • Loading branch information
alrex authored Oct 8, 2020
2 parents 32b4207 + affe911 commit fb44ffd
Show file tree
Hide file tree
Showing 68 changed files with 635 additions and 319 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ def _translate_to_datadog(self, spans):

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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def inject(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(
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:
Expand All @@ -102,7 +102,7 @@ def on_end(self, span: Span) -> None:
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_translate_to_datadog(self):
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(
Expand All @@ -191,14 +191,14 @@ def test_translate_to_datadog(self):
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_malformed_headers(self):
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))
Expand All @@ -64,7 +64,7 @@ def test_missing_trace_id(self):
}

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):
Expand All @@ -74,12 +74,12 @@ def test_missing_parent_id(self):
}

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,
{
Expand All @@ -89,31 +89,31 @@ def test_context_propagation(self):
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 = {}
Expand All @@ -136,7 +136,7 @@ def test_context_propagation(self):

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,
{
Expand All @@ -145,20 +145,22 @@ def test_sampling_priority_auto_reject(self):
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 = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
foo.set_attribute("my_atribbute", True)
foo.add_event("event in foo", {"name": "foo1"})
with tracer.start_as_current_span(
"bar", links=[trace.Link(foo.get_context())]
"bar", links=[trace.Link(foo.get_span_context())]
) as bar:
time.sleep(0.2)
bar.set_attribute("speed", 100.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def _translate_to_jaeger(spans: Span):
jaeger_spans = []

for span in spans:
ctx = span.get_context()
ctx = span.get_span_context()
trace_id = ctx.trace_id
span_id = ctx.span_id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def test_translate_to_jaeger(self):
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(
Expand Down Expand Up @@ -190,13 +190,13 @@ def test_translate_to_jaeger(self):
trace._Span(
name=span_names[0],
context=span_context,
parent=parent_context,
parent=parent_span_context,
events=(event,),
links=(link,),
kind=trace_api.SpanKind.CLIENT,
),
trace._Span(
name=span_names[1], context=parent_context, parent=None
name=span_names[1], context=parent_span_context, parent=None
),
trace._Span(
name=span_names[2], context=other_context, parent=None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_translate_to_collector(self):
trace_flags=TraceFlags(TraceFlags.SAMPLED),
trace_state=trace_api.TraceState({"testKey": "testValue"}),
)
parent_context = trace_api.SpanContext(
parent_span_context = trace_api.SpanContext(
trace_id, parent_id, is_remote=False
)
other_context = trace_api.SpanContext(
Expand All @@ -118,27 +118,27 @@ def test_translate_to_collector(self):
context=other_context, attributes=link_attributes
)
link_2 = trace_api.Link(
context=parent_context, attributes=link_attributes
context=parent_span_context, attributes=link_attributes
)
span_1 = trace._Span(
name="test1",
context=span_context,
parent=parent_context,
parent=parent_span_context,
events=(event,),
links=(link_1,),
kind=trace_api.SpanKind.CLIENT,
)
span_2 = trace._Span(
name="test2",
context=parent_context,
context=parent_span_context,
parent=None,
kind=trace_api.SpanKind.SERVER,
)
span_3 = trace._Span(
name="test3",
context=other_context,
links=(link_2,),
parent=span_2.get_context(),
parent=span_2.get_span_context(),
)
otel_spans = [span_1, span_2, span_3]
otel_spans[0].start(start_time=start_times[0])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _translate_to_zipkin(self, spans: Sequence[Span]):

zipkin_spans = []
for span in spans:
context = span.get_context()
context = span.get_span_context()
trace_id = context.trace_id
span_id = context.span_id

Expand Down Expand Up @@ -205,7 +205,7 @@ def _translate_to_zipkin(self, spans: Sequence[Span]):

if isinstance(span.parent, Span):
zipkin_span["parentId"] = format(
span.parent.get_context().span_id, "016x"
span.parent.get_span_context().span_id, "016x"
)
elif isinstance(span.parent, SpanContext):
zipkin_span["parentId"] = format(span.parent.span_id, "016x")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_export(self):
is_remote=False,
trace_flags=TraceFlags(TraceFlags.SAMPLED),
)
parent_context = trace_api.SpanContext(
parent_span_context = trace_api.SpanContext(
trace_id, parent_id, is_remote=False
)
other_context = trace_api.SpanContext(
Expand Down Expand Up @@ -157,12 +157,12 @@ def test_export(self):
trace._Span(
name=span_names[0],
context=span_context,
parent=parent_context,
parent=parent_span_context,
events=(event,),
links=(link,),
),
trace._Span(
name=span_names[1], context=parent_context, parent=None
name=span_names[1], context=parent_span_context, parent=None
),
trace._Span(
name=span_names[2], context=other_context, parent=None
Expand Down Expand Up @@ -328,12 +328,14 @@ def test_zero_padding(self):
is_remote=False,
trace_flags=TraceFlags(TraceFlags.SAMPLED),
)
parent_context = trace_api.SpanContext(
parent_span_context = trace_api.SpanContext(
trace_id, parent_id, is_remote=False
)

otel_span = trace._Span(
name=span_names[0], context=span_context, parent=parent_context,
name=span_names[0],
context=span_context,
parent=parent_span_context,
)

otel_span.start(start_time=start_time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AiopgInstrumentor(BaseInstrumentor):

def _instrument(self, **kwargs):
"""Integrate with PostgreSQL aiopg library.
aiopg: https://github.com/aio-libs/aiopg
aiopg: https://github.com/aio-libs/aiopg
"""

tracer_provider = kwargs.get("tracer_provider")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ async def wrapped_connection(
args: typing.Tuple[typing.Any, typing.Any],
kwargs: typing.Dict[typing.Any, typing.Any],
):
"""Add object proxy to connection object.
"""
"""Add object proxy to connection object."""
connection = await connect_method(*args, **kwargs)
# pylint: disable=protected-access
self.get_connection_attributes(connection._conn)
Expand Down Expand Up @@ -109,10 +108,14 @@ async def traced_execution(
self._populate_span(span, *args)
try:
result = await query_method(*args, **kwargs)
span.set_status(Status(StatusCanonicalCode.OK))
if span.is_recording():
span.set_status(Status(StatusCanonicalCode.OK))
return result
except Exception as ex: # pylint: disable=broad-except
span.set_status(Status(StatusCanonicalCode.UNKNOWN, str(ex)))
if span.is_recording():
span.set_status(
Status(StatusCanonicalCode.UNKNOWN, str(ex))
)
raise ex


Expand Down
Loading

0 comments on commit fb44ffd

Please sign in to comment.