Skip to content

Commit fb44ffd

Browse files
author
alrex
authored
Merge branch 'master' into issue_1008
2 parents 32b4207 + affe911 commit fb44ffd

File tree

68 files changed

+635
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+635
-319
lines changed

Diff for: exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/exporter.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ def _translate_to_datadog(self, spans):
189189

190190
def _get_trace_ids(span):
191191
"""Extract tracer ids from span"""
192-
ctx = span.get_context()
192+
ctx = span.get_span_context()
193193
trace_id = ctx.trace_id
194194
span_id = ctx.span_id
195195

196196
if isinstance(span.parent, trace_api.Span):
197-
parent_id = span.parent.get_context().span_id
197+
parent_id = span.parent.get_span_context().span_id
198198
elif isinstance(span.parent, trace_api.SpanContext):
199199
parent_id = span.parent.span_id
200200
else:
@@ -255,13 +255,13 @@ def _get_exc_info(span):
255255

256256

257257
def _get_origin(span):
258-
ctx = span.get_context()
258+
ctx = span.get_span_context()
259259
origin = ctx.trace_state.get(DD_ORIGIN)
260260
return origin
261261

262262

263263
def _get_sampling_rate(span):
264-
ctx = span.get_context()
264+
ctx = span.get_span_context()
265265
return (
266266
span.sampler.rate
267267
if ctx.trace_flags.sampled

Diff for: exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/propagator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def inject(
8686
context: typing.Optional[Context] = None,
8787
) -> None:
8888
span = get_current_span(context)
89-
span_context = span.get_context()
89+
span_context = span.get_span_context()
9090
if span_context == trace.INVALID_SPAN_CONTEXT:
9191
return
9292
sampled = (trace.TraceFlags.SAMPLED & span.context.trace_flags) != 0

Diff for: exporter/opentelemetry-exporter-datadog/src/opentelemetry/exporter/datadog/spanprocessor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(
8282
self.worker_thread.start()
8383

8484
def on_start(self, span: Span) -> None:
85-
ctx = span.get_context()
85+
ctx = span.get_span_context()
8686
trace_id = ctx.trace_id
8787

8888
with self.traces_lock:
@@ -102,7 +102,7 @@ def on_end(self, span: Span) -> None:
102102
logger.warning("Already shutdown, dropping span.")
103103
return
104104

105-
ctx = span.get_context()
105+
ctx = span.get_span_context()
106106
trace_id = ctx.trace_id
107107

108108
with self.traces_lock:

Diff for: exporter/opentelemetry-exporter-datadog/tests/test_datadog_exporter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_translate_to_datadog(self):
178178
span_context = trace_api.SpanContext(
179179
trace_id, span_id, is_remote=False
180180
)
181-
parent_context = trace_api.SpanContext(
181+
parent_span_context = trace_api.SpanContext(
182182
trace_id, parent_id, is_remote=False
183183
)
184184
other_context = trace_api.SpanContext(
@@ -191,14 +191,14 @@ def test_translate_to_datadog(self):
191191
trace._Span(
192192
name=span_names[0],
193193
context=span_context,
194-
parent=parent_context,
194+
parent=parent_span_context,
195195
kind=trace_api.SpanKind.CLIENT,
196196
instrumentation_info=instrumentation_info,
197197
resource=Resource({}),
198198
),
199199
trace._Span(
200200
name=span_names[1],
201-
context=parent_context,
201+
context=parent_span_context,
202202
parent=None,
203203
instrumentation_info=instrumentation_info,
204204
resource=resource_without_service,

Diff for: exporter/opentelemetry-exporter-datadog/tests/test_datadog_format.py

+23-21
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_malformed_headers(self):
5151
malformed_parent_id_key: self.serialized_parent_id,
5252
},
5353
)
54-
).get_context()
54+
).get_span_context()
5555

5656
self.assertNotEqual(context.trace_id, int(self.serialized_trace_id))
5757
self.assertNotEqual(context.span_id, int(self.serialized_parent_id))
@@ -64,7 +64,7 @@ def test_missing_trace_id(self):
6464
}
6565

6666
ctx = FORMAT.extract(get_as_list, carrier)
67-
span_context = get_current_span(ctx).get_context()
67+
span_context = get_current_span(ctx).get_span_context()
6868
self.assertEqual(span_context.trace_id, trace_api.INVALID_TRACE_ID)
6969

7070
def test_missing_parent_id(self):
@@ -74,12 +74,12 @@ def test_missing_parent_id(self):
7474
}
7575

7676
ctx = FORMAT.extract(get_as_list, carrier)
77-
span_context = get_current_span(ctx).get_context()
77+
span_context = get_current_span(ctx).get_span_context()
7878
self.assertEqual(span_context.span_id, trace_api.INVALID_SPAN_ID)
7979

8080
def test_context_propagation(self):
8181
"""Test the propagation of Datadog headers."""
82-
parent_context = get_current_span(
82+
parent_span_context = get_current_span(
8383
FORMAT.extract(
8484
get_as_list,
8585
{
@@ -89,31 +89,31 @@ def test_context_propagation(self):
8989
FORMAT.ORIGIN_KEY: self.serialized_origin,
9090
},
9191
)
92-
).get_context()
92+
).get_span_context()
9393

9494
self.assertEqual(
95-
parent_context.trace_id, int(self.serialized_trace_id)
95+
parent_span_context.trace_id, int(self.serialized_trace_id)
9696
)
9797
self.assertEqual(
98-
parent_context.span_id, int(self.serialized_parent_id)
98+
parent_span_context.span_id, int(self.serialized_parent_id)
9999
)
100-
self.assertEqual(parent_context.trace_flags, constants.AUTO_KEEP)
100+
self.assertEqual(parent_span_context.trace_flags, constants.AUTO_KEEP)
101101
self.assertEqual(
102-
parent_context.trace_state.get(constants.DD_ORIGIN),
102+
parent_span_context.trace_state.get(constants.DD_ORIGIN),
103103
self.serialized_origin,
104104
)
105-
self.assertTrue(parent_context.is_remote)
105+
self.assertTrue(parent_span_context.is_remote)
106106

107107
child = trace._Span(
108108
"child",
109109
trace_api.SpanContext(
110-
parent_context.trace_id,
110+
parent_span_context.trace_id,
111111
trace_api.RandomIdsGenerator().generate_span_id(),
112112
is_remote=False,
113-
trace_flags=parent_context.trace_flags,
114-
trace_state=parent_context.trace_state,
113+
trace_flags=parent_span_context.trace_flags,
114+
trace_state=parent_span_context.trace_state,
115115
),
116-
parent=parent_context,
116+
parent=parent_span_context,
117117
)
118118

119119
child_carrier = {}
@@ -136,7 +136,7 @@ def test_context_propagation(self):
136136

137137
def test_sampling_priority_auto_reject(self):
138138
"""Test sampling priority rejected."""
139-
parent_context = get_current_span(
139+
parent_span_context = get_current_span(
140140
FORMAT.extract(
141141
get_as_list,
142142
{
@@ -145,20 +145,22 @@ def test_sampling_priority_auto_reject(self):
145145
FORMAT.SAMPLING_PRIORITY_KEY: str(constants.AUTO_REJECT),
146146
},
147147
)
148-
).get_context()
148+
).get_span_context()
149149

150-
self.assertEqual(parent_context.trace_flags, constants.AUTO_REJECT)
150+
self.assertEqual(
151+
parent_span_context.trace_flags, constants.AUTO_REJECT
152+
)
151153

152154
child = trace._Span(
153155
"child",
154156
trace_api.SpanContext(
155-
parent_context.trace_id,
157+
parent_span_context.trace_id,
156158
trace_api.RandomIdsGenerator().generate_span_id(),
157159
is_remote=False,
158-
trace_flags=parent_context.trace_flags,
159-
trace_state=parent_context.trace_state,
160+
trace_flags=parent_span_context.trace_flags,
161+
trace_state=parent_span_context.trace_state,
160162
),
161-
parent=parent_context,
163+
parent=parent_span_context,
162164
)
163165

164166
child_carrier = {}

Diff for: exporter/opentelemetry-exporter-jaeger/examples/jaeger_exporter_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
foo.set_attribute("my_atribbute", True)
3535
foo.add_event("event in foo", {"name": "foo1"})
3636
with tracer.start_as_current_span(
37-
"bar", links=[trace.Link(foo.get_context())]
37+
"bar", links=[trace.Link(foo.get_span_context())]
3838
) as bar:
3939
time.sleep(0.2)
4040
bar.set_attribute("speed", 100.0)

Diff for: exporter/opentelemetry-exporter-jaeger/src/opentelemetry/exporter/jaeger/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def _translate_to_jaeger(spans: Span):
192192
jaeger_spans = []
193193

194194
for span in spans:
195-
ctx = span.get_context()
195+
ctx = span.get_span_context()
196196
trace_id = ctx.trace_id
197197
span_id = ctx.span_id
198198

Diff for: exporter/opentelemetry-exporter-jaeger/tests/test_jaeger_exporter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_translate_to_jaeger(self):
144144
span_context = trace_api.SpanContext(
145145
trace_id, span_id, is_remote=False
146146
)
147-
parent_context = trace_api.SpanContext(
147+
parent_span_context = trace_api.SpanContext(
148148
trace_id, parent_id, is_remote=False
149149
)
150150
other_context = trace_api.SpanContext(
@@ -190,13 +190,13 @@ def test_translate_to_jaeger(self):
190190
trace._Span(
191191
name=span_names[0],
192192
context=span_context,
193-
parent=parent_context,
193+
parent=parent_span_context,
194194
events=(event,),
195195
links=(link,),
196196
kind=trace_api.SpanKind.CLIENT,
197197
),
198198
trace._Span(
199-
name=span_names[1], context=parent_context, parent=None
199+
name=span_names[1], context=parent_span_context, parent=None
200200
),
201201
trace._Span(
202202
name=span_names[2], context=other_context, parent=None

Diff for: exporter/opentelemetry-exporter-opencensus/tests/test_otcollector_trace_exporter.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_translate_to_collector(self):
9696
trace_flags=TraceFlags(TraceFlags.SAMPLED),
9797
trace_state=trace_api.TraceState({"testKey": "testValue"}),
9898
)
99-
parent_context = trace_api.SpanContext(
99+
parent_span_context = trace_api.SpanContext(
100100
trace_id, parent_id, is_remote=False
101101
)
102102
other_context = trace_api.SpanContext(
@@ -118,27 +118,27 @@ def test_translate_to_collector(self):
118118
context=other_context, attributes=link_attributes
119119
)
120120
link_2 = trace_api.Link(
121-
context=parent_context, attributes=link_attributes
121+
context=parent_span_context, attributes=link_attributes
122122
)
123123
span_1 = trace._Span(
124124
name="test1",
125125
context=span_context,
126-
parent=parent_context,
126+
parent=parent_span_context,
127127
events=(event,),
128128
links=(link_1,),
129129
kind=trace_api.SpanKind.CLIENT,
130130
)
131131
span_2 = trace._Span(
132132
name="test2",
133-
context=parent_context,
133+
context=parent_span_context,
134134
parent=None,
135135
kind=trace_api.SpanKind.SERVER,
136136
)
137137
span_3 = trace._Span(
138138
name="test3",
139139
context=other_context,
140140
links=(link_2,),
141-
parent=span_2.get_context(),
141+
parent=span_2.get_span_context(),
142142
)
143143
otel_spans = [span_1, span_2, span_3]
144144
otel_spans[0].start(start_time=start_times[0])

Diff for: exporter/opentelemetry-exporter-zipkin/src/opentelemetry/exporter/zipkin/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _translate_to_zipkin(self, spans: Sequence[Span]):
159159

160160
zipkin_spans = []
161161
for span in spans:
162-
context = span.get_context()
162+
context = span.get_span_context()
163163
trace_id = context.trace_id
164164
span_id = context.span_id
165165

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

206206
if isinstance(span.parent, Span):
207207
zipkin_span["parentId"] = format(
208-
span.parent.get_context().span_id, "016x"
208+
span.parent.get_span_context().span_id, "016x"
209209
)
210210
elif isinstance(span.parent, SpanContext):
211211
zipkin_span["parentId"] = format(span.parent.span_id, "016x")

Diff for: exporter/opentelemetry-exporter-zipkin/tests/test_zipkin_exporter.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_export(self):
127127
is_remote=False,
128128
trace_flags=TraceFlags(TraceFlags.SAMPLED),
129129
)
130-
parent_context = trace_api.SpanContext(
130+
parent_span_context = trace_api.SpanContext(
131131
trace_id, parent_id, is_remote=False
132132
)
133133
other_context = trace_api.SpanContext(
@@ -157,12 +157,12 @@ def test_export(self):
157157
trace._Span(
158158
name=span_names[0],
159159
context=span_context,
160-
parent=parent_context,
160+
parent=parent_span_context,
161161
events=(event,),
162162
links=(link,),
163163
),
164164
trace._Span(
165-
name=span_names[1], context=parent_context, parent=None
165+
name=span_names[1], context=parent_span_context, parent=None
166166
),
167167
trace._Span(
168168
name=span_names[2], context=other_context, parent=None
@@ -328,12 +328,14 @@ def test_zero_padding(self):
328328
is_remote=False,
329329
trace_flags=TraceFlags(TraceFlags.SAMPLED),
330330
)
331-
parent_context = trace_api.SpanContext(
331+
parent_span_context = trace_api.SpanContext(
332332
trace_id, parent_id, is_remote=False
333333
)
334334

335335
otel_span = trace._Span(
336-
name=span_names[0], context=span_context, parent=parent_context,
336+
name=span_names[0],
337+
context=span_context,
338+
parent=parent_span_context,
337339
)
338340

339341
otel_span.start(start_time=start_time)

Diff for: instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class AiopgInstrumentor(BaseInstrumentor):
6363

6464
def _instrument(self, **kwargs):
6565
"""Integrate with PostgreSQL aiopg library.
66-
aiopg: https://github.com/aio-libs/aiopg
66+
aiopg: https://github.com/aio-libs/aiopg
6767
"""
6868

6969
tracer_provider = kwargs.get("tracer_provider")

Diff for: instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ async def wrapped_connection(
3737
args: typing.Tuple[typing.Any, typing.Any],
3838
kwargs: typing.Dict[typing.Any, typing.Any],
3939
):
40-
"""Add object proxy to connection object.
41-
"""
40+
"""Add object proxy to connection object."""
4241
connection = await connect_method(*args, **kwargs)
4342
# pylint: disable=protected-access
4443
self.get_connection_attributes(connection._conn)
@@ -109,10 +108,14 @@ async def traced_execution(
109108
self._populate_span(span, *args)
110109
try:
111110
result = await query_method(*args, **kwargs)
112-
span.set_status(Status(StatusCanonicalCode.OK))
111+
if span.is_recording():
112+
span.set_status(Status(StatusCanonicalCode.OK))
113113
return result
114114
except Exception as ex: # pylint: disable=broad-except
115-
span.set_status(Status(StatusCanonicalCode.UNKNOWN, str(ex)))
115+
if span.is_recording():
116+
span.set_status(
117+
Status(StatusCanonicalCode.UNKNOWN, str(ex))
118+
)
116119
raise ex
117120

118121

0 commit comments

Comments
 (0)