Skip to content

Commit 583e618

Browse files
committedMar 4, 2021
Replaced Tracer.use_span() with opentelemetry.trace.use_span()
1 parent aa31e73 commit 583e618

File tree

26 files changed

+19
-50
lines changed

26 files changed

+19
-50
lines changed
 

‎instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,6 @@ def test_span_not_recording(self):
289289
mock_span = mock.Mock()
290290
mock_span.is_recording.return_value = False
291291
mock_tracer.start_span.return_value = mock_span
292-
mock_tracer.use_span.return_value.__enter__ = mock_span
293-
mock_tracer.use_span.return_value.__exit__ = True
294292
db_integration = AiopgIntegration(
295293
mock_tracer, "testcomponent", connection_attributes
296294
)
@@ -322,7 +320,7 @@ def test_span_failed(self):
322320
self.assertIs(
323321
span.status.status_code, trace_api.status.StatusCode.ERROR
324322
)
325-
self.assertEqual(span.status.description, "Test Exception")
323+
self.assertEqual(span.status.description, "Exception: Test Exception")
326324

327325
def test_executemany(self):
328326
db_integration = AiopgIntegration(self.tracer, "testcomponent")

‎instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py

-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ def test_not_recording(self):
8282
mock_span = Mock()
8383
mock_span.is_recording.return_value = False
8484
mock_tracer.start_span.return_value = mock_span
85-
mock_tracer.use_span.return_value.__enter__ = mock_span
86-
mock_tracer.use_span.return_value.__exit__ = True
8785
with patch("opentelemetry.trace.get_tracer") as tracer:
8886
tracer.return_value = mock_tracer
8987
ec2 = boto.ec2.connect_to_region("us-west-2")

‎instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_instrumentation.py

-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ def test_not_recording(self):
8181
mock_span = Mock()
8282
mock_span.is_recording.return_value = False
8383
mock_tracer.start_span.return_value = mock_span
84-
mock_tracer.use_span.return_value.__enter__ = mock_span
85-
mock_tracer.use_span.return_value.__exit__ = True
8684
with patch("opentelemetry.trace.get_tracer") as tracer:
8785
tracer.return_value = mock_tracer
8886
ec2 = self.session.create_client("ec2", region_name="us-west-2")

‎instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _trace_prerun(self, *args, **kwargs):
137137
operation_name, context=tracectx, kind=trace.SpanKind.CONSUMER
138138
)
139139

140-
activation = self._tracer.use_span(span, end_on_exit=True)
140+
activation = trace.use_span(span, end_on_exit=True)
141141
activation.__enter__()
142142
utils.attach_span(task, task_id, (span, activation))
143143

@@ -186,7 +186,7 @@ def _trace_before_publish(self, *args, **kwargs):
186186
span.set_attribute(_TASK_NAME_KEY, task.name)
187187
utils.set_attributes_from_context(span, kwargs)
188188

189-
activation = self._tracer.use_span(span, end_on_exit=True)
189+
activation = trace.use_span(span, end_on_exit=True)
190190
activation.__enter__()
191191
utils.attach_span(task, task_id, (span, activation), is_publish=True)
192192

‎instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ def test_span_not_recording(self):
146146
mock_span = mock.Mock()
147147
mock_span.is_recording.return_value = False
148148
mock_tracer.start_span.return_value = mock_span
149-
mock_tracer.use_span.return_value.__enter__ = mock_span
150-
mock_tracer.use_span.return_value.__exit__ = True
151149
db_integration = dbapi.DatabaseApiIntegration(
152150
mock_tracer, "testcomponent", connection_attributes
153151
)
@@ -179,7 +177,7 @@ def test_span_failed(self):
179177
self.assertIs(
180178
span.status.status_code, trace_api.status.StatusCode.ERROR
181179
)
182-
self.assertEqual(span.status.description, "Test Exception")
180+
self.assertEqual(span.status.description, "Exception: Test Exception")
183181

184182
def test_executemany(self):
185183
db_integration = dbapi.DatabaseApiIntegration(

‎instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
collect_request_attributes,
2525
)
2626
from opentelemetry.propagate import extract
27-
from opentelemetry.trace import SpanKind, get_tracer
27+
from opentelemetry.trace import SpanKind, get_tracer, use_span
2828
from opentelemetry.util.http import get_excluded_urls, get_traced_request_attrs
2929

3030
try:
@@ -118,7 +118,7 @@ def process_request(self, request):
118118
for key, value in attributes.items():
119119
span.set_attribute(key, value)
120120

121-
activation = tracer.use_span(span, end_on_exit=True)
121+
activation = use_span(span, end_on_exit=True)
122122
activation.__enter__()
123123

124124
request.META[self._environ_activation_key] = activation

‎instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py

-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ def test_not_recording(self):
146146
mock_span = Mock()
147147
mock_span.is_recording.return_value = False
148148
mock_tracer.start_span.return_value = mock_span
149-
mock_tracer.use_span.return_value.__enter__ = mock_span
150-
mock_tracer.use_span.return_value.__exit__ = True
151149
with patch("opentelemetry.trace.get_tracer") as tracer:
152150
tracer.return_value = mock_tracer
153151
Client().get("/traced/")

‎instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from elasticsearch_dsl import Search
2424

2525
import opentelemetry.instrumentation.elasticsearch
26+
from opentelemetry import trace
2627
from opentelemetry.instrumentation.elasticsearch import (
2728
ElasticsearchInstrumentor,
2829
)
@@ -94,8 +95,6 @@ def test_span_not_recording(self, request_mock):
9495
mock_span = mock.Mock()
9596
mock_span.is_recording.return_value = False
9697
mock_tracer.start_span.return_value = mock_span
97-
mock_tracer.use_span.return_value.__enter__ = mock_span
98-
mock_tracer.use_span.return_value.__exit__ = mock_span
9998
with mock.patch("opentelemetry.trace.get_tracer") as tracer:
10099
tracer.return_value = mock_tracer
101100
Elasticsearch()
@@ -174,7 +173,9 @@ def _test_trace_error(self, code, exc):
174173
span = spans[0]
175174
self.assertFalse(span.status.is_ok)
176175
self.assertEqual(span.status.status_code, code)
177-
self.assertEqual(span.status.description, str(exc))
176+
self.assertEqual(
177+
span.status.description, "{}: {}".format(type(exc).__name__, exc)
178+
)
178179

179180
def test_parent(self, request_mock):
180181
request_mock.return_value = (1, {}, {})
@@ -201,7 +202,7 @@ def test_multithread(self, request_mock):
201202
# 2. Trace something from thread-2, make thread-1 join before finishing.
202203
# 3. Check the spans got different parents, and are in the expected order.
203204
def target1(parent_span):
204-
with self.tracer.use_span(parent_span):
205+
with trace.use_span(parent_span):
205206
es.get(index="test-index", doc_type="tweet", id=1)
206207
ev.set()
207208
ev.wait()

‎instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __call__(self, env, start_response):
120120
for key, value in attributes.items():
121121
span.set_attribute(key, value)
122122

123-
activation = self._tracer.use_span(span, end_on_exit=True)
123+
activation = trace.use_span(span, end_on_exit=True)
124124
activation.__enter__()
125125
env[_ENVIRON_SPAN_KEY] = span
126126
env[_ENVIRON_ACTIVATION_KEY] = activation

‎instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py

-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ def test_traced_not_recording(self):
199199
mock_span = Mock()
200200
mock_span.is_recording.return_value = False
201201
mock_tracer.start_span.return_value = mock_span
202-
mock_tracer.use_span.return_value.__enter__ = mock_span
203-
mock_tracer.use_span.return_value.__exit__ = mock_span
204202
with patch("opentelemetry.trace.get_tracer") as tracer:
205203
tracer.return_value = mock_tracer
206204
self.client().simulate_get(path="/hello?q=abc")

‎instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _before_request():
138138
for key, value in attributes.items():
139139
span.set_attribute(key, value)
140140

141-
activation = tracer.use_span(span, end_on_exit=True)
141+
activation = trace.use_span(span, end_on_exit=True)
142142
activation.__enter__()
143143
flask_request_environ[_ENVIRON_ACTIVATION_KEY] = activation
144144
flask_request_environ[_ENVIRON_SPAN_KEY] = span

‎instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py

-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ def test_not_recording(self):
125125
mock_span = Mock()
126126
mock_span.is_recording.return_value = False
127127
mock_tracer.start_span.return_value = mock_span
128-
mock_tracer.use_span.return_value.__enter__ = mock_span
129-
mock_tracer.use_span.return_value.__exit__ = mock_span
130128
with patch("opentelemetry.trace.get_tracer") as tracer:
131129
tracer.return_value = mock_tracer
132130
self.client.get("/hello/123")

‎instrumentation/opentelemetry-instrumentation-jinja2/tests/test_jinja2.py

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ def test_render_not_recording(self):
5959
mock_span = mock.Mock()
6060
mock_span.is_recording.return_value = False
6161
mock_tracer.start_span.return_value = mock_span
62-
mock_tracer.use_span.return_value.__enter__ = mock_span
63-
mock_tracer.use_span.return_value.__exit__ = mock_span
6462
with mock.patch("opentelemetry.trace.get_tracer") as tracer:
6563
tracer.return_value = mock_tracer
6664
jinja2.environment.Template("Hello {{name}}!")

‎instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py

-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ def test_not_recording(self):
121121
mock_span = mock.Mock()
122122
mock_span.is_recording.return_value = False
123123
mock_tracer.start_span.return_value = mock_span
124-
mock_tracer.use_span.return_value.__enter__ = mock_span
125-
mock_tracer.use_span.return_value.__exit__ = True
126124
Psycopg2Instrumentor().instrument()
127125
with mock.patch("opentelemetry.trace.get_tracer") as tracer:
128126
tracer.return_value = mock_tracer

‎instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py

-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ def test_set_not_recording(self):
8484
mock_span = mock.Mock()
8585
mock_span.is_recording.return_value = False
8686
mock_tracer.start_span.return_value = mock_span
87-
mock_tracer.use_span.return_value.__enter__ = mock_span
88-
mock_tracer.use_span.return_value.__exit__ = True
8987
with mock.patch("opentelemetry.trace.get_tracer") as tracer:
9088
tracer.return_value = mock_tracer
9189
client = self.make_client([b"STORED\r\n"])

‎instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py

-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ def test_not_recording(self):
7676
mock_span = mock.Mock()
7777
mock_span.is_recording.return_value = False
7878
mock_tracer.start_span.return_value = mock_span
79-
mock_tracer.use_span.return_value.__enter__ = mock_span
80-
mock_tracer.use_span.return_value.__exit__ = True
8179
mock_event = MockEvent({})
8280
command_tracer = CommandTracer(mock_tracer)
8381
command_tracer.started(event=mock_event)

‎instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _before_traversal(event):
8383
for key, value in attributes.items():
8484
span.set_attribute(key, value)
8585

86-
activation = tracer.use_span(span, end_on_exit=True)
86+
activation = trace.use_span(span, end_on_exit=True)
8787
activation.__enter__()
8888
request_environ[_ENVIRON_ACTIVATION_KEY] = activation
8989
request_environ[_ENVIRON_SPAN_KEY] = span

‎instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py

-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ def test_not_recording(self):
104104
mock_span = Mock()
105105
mock_span.is_recording.return_value = False
106106
mock_tracer.start_span.return_value = mock_span
107-
mock_tracer.use_span.return_value.__enter__ = mock_span
108-
mock_tracer.use_span.return_value.__exit__ = True
109107
with patch("opentelemetry.trace.get_tracer"):
110108
self.client.get("/hello/123")
111109
span_list = self.memory_exporter.get_finished_spans()

‎instrumentation/opentelemetry-instrumentation-redis/tests/test_redis.py

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ def test_not_recording(self):
4242
mock_span = mock.Mock()
4343
mock_span.is_recording.return_value = False
4444
mock_tracer.start_span.return_value = mock_span
45-
mock_tracer.use_span.return_value.__enter__ = mock_span
46-
mock_tracer.use_span.return_value.__exit__ = True
4745
with mock.patch("opentelemetry.trace.get_tracer") as tracer:
4846
with mock.patch.object(redis_client, "connection"):
4947
tracer.return_value = mock_tracer

‎instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def _before_cur_exec(self, conn, cursor, statement, *args):
9898
self._operation_name(db_name, statement),
9999
kind=trace.SpanKind.CLIENT,
100100
)
101-
with self.tracer.use_span(self.current_span, end_on_exit=False):
101+
with trace.use_span(self.current_span, end_on_exit=False):
102102
if self.current_span.is_recording():
103103
self.current_span.set_attribute(_STMT, statement)
104104
self.current_span.set_attribute("db.system", self.vendor)

‎instrumentation/opentelemetry-instrumentation-sqlalchemy/tests/test_sqlalchemy.py

-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ def test_not_recording(self):
4343
mock_span = mock.Mock()
4444
mock_span.is_recording.return_value = False
4545
mock_tracer.start_span.return_value = mock_span
46-
mock_tracer.use_span.return_value.__enter__ = mock_span
47-
mock_tracer.use_span.return_value.__exit__ = True
4846
with mock.patch("opentelemetry.trace.get_tracer") as tracer:
4947
tracer.return_value = mock_tracer
5048
engine = create_engine("sqlite:///:memory:")

‎instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def _start_span(tracer, handler, start_time) -> _TraceContext:
208208
for key, value in attributes.items():
209209
span.set_attribute(key, value)
210210

211-
activation = tracer.use_span(span, end_on_exit=True)
211+
activation = trace.use_span(span, end_on_exit=True)
212212
activation.__enter__()
213213
ctx = _TraceContext(activation, span, token)
214214
setattr(handler, _HANDLER_CONTEXT_KEY, ctx)

‎instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def fetch_async(tracer, func, _, args, kwargs):
6464
for key, value in attributes.items():
6565
span.set_attribute(key, value)
6666

67-
with tracer.use_span(span):
67+
with trace.use_span(span):
6868
inject(type(request.headers).__setitem__, request.headers)
6969
future = func(*args, **kwargs)
7070
future.add_done_callback(

‎instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py

-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ def test_not_recording(self):
157157
mock_span = Mock()
158158
mock_span.is_recording.return_value = False
159159
mock_tracer.start_span.return_value = mock_span
160-
mock_tracer.use_span.return_value.__enter__ = mock_span
161-
mock_tracer.use_span.return_value.__exit__ = True
162160
with patch("opentelemetry.trace.get_tracer") as tracer:
163161
tracer.return_value = mock_tracer
164162
self.fetch("/")

‎instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def __call__(self, environ, start_response):
218218
)
219219

220220
try:
221-
with self.tracer.use_span(span):
221+
with trace.use_span(span):
222222
start_response = self._create_start_response(
223223
span, start_response
224224
)
@@ -239,7 +239,7 @@ def __call__(self, environ, start_response):
239239
# behavior as little as possible).
240240
def _end_span_after_iterating(iterable, span, tracer, token):
241241
try:
242-
with tracer.use_span(span):
242+
with trace.use_span(span):
243243
for yielded in iterable:
244244
yield yielded
245245
finally:

‎instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py

-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ def test_wsgi_not_recording(self):
129129
mock_span = mock.Mock()
130130
mock_span.is_recording.return_value = False
131131
mock_tracer.start_span.return_value = mock_span
132-
mock_tracer.use_span.return_value.__enter__ = mock_span
133-
mock_tracer.use_span.return_value.__exit__ = mock_span
134132
with mock.patch("opentelemetry.trace.get_tracer") as tracer:
135133
tracer.return_value = mock_tracer
136134
app = otel_wsgi.OpenTelemetryMiddleware(simple_wsgi)

0 commit comments

Comments
 (0)