Skip to content

Commit 972e2ab

Browse files
toumorokoshic24t
andauthored
Adding trace.get_tracer (#430)
It's fairly common to need to retrieve tracers, and as such adding the additional tracer_source() call to every retrieval of a tracer can add to a lot of extra boilerplate at minimal semantic value. It would be uncommon for one to use multiple tracer_source objects, as typically one would want all tracers to be created and behave in a similar way (e.g. passed to the same span processor). Co-Authored-By: Chris Kleinknecht <[email protected]>
1 parent 5a0dae9 commit 972e2ab

File tree

15 files changed

+75
-14
lines changed

15 files changed

+75
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
5959
trace.tracer_source().add_span_processor(
6060
SimpleExportSpanProcessor(ConsoleSpanExporter())
6161
)
62-
tracer = trace.tracer_source().get_tracer(__name__)
62+
tracer = trace.get_tracer(__name__)
6363
with tracer.start_as_current_span('foo'):
6464
with tracer.start_as_current_span('bar'):
6565
with tracer.start_as_current_span('baz'):

examples/basic_tracer/tracer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
# We tell OpenTelemetry who it is that is creating spans. In this case, we have
4242
# no real name (no setup.py), so we make one up. If we had a version, we would
4343
# also specify it here.
44-
tracer = trace.tracer_source().get_tracer(__name__)
44+
tracer = trace.get_tracer(__name__)
4545

4646
# SpanExporter receives the spans and send them to the target location.
4747
span_processor = BatchExportSpanProcessor(exporter)

examples/http/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# The preferred tracer implementation must be set, as the opentelemetry-api
4343
# defines the interface with a no-op implementation.
4444
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
45-
tracer = trace.tracer_source().get_tracer(__name__)
45+
tracer = trace.get_tracer(__name__)
4646

4747
# SpanExporter receives the spans and send them to the target location.
4848
span_processor = BatchExportSpanProcessor(exporter)

examples/opentelemetry-example-app/src/opentelemetry_example_app/flask_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def hello():
6767
version = pkg_resources.get_distribution(
6868
"opentelemetry-example-app"
6969
).version
70-
tracer = trace.tracer_source().get_tracer(__name__, version)
70+
tracer = trace.get_tracer(__name__, version)
7171
with tracer.start_as_current_span("example-request"):
7272
requests.get("http://www.example.com")
7373
return "hello"

examples/opentracing/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
redis_cache = RedisCache(opentracing_tracer)
2929

3030
# Appication code uses an OpenTelemetry Tracer as usual.
31-
tracer = trace.tracer_source().get_tracer(__name__)
31+
tracer = trace.get_tracer(__name__)
3232

3333

3434
@redis_cache

ext/opentelemetry-ext-dbapi/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Usage
1515
from opentelemetry.ext.dbapi import trace_integration
1616
1717
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
18-
tracer = trace.tracer_source().get_tracer(__name__)
18+
tracer = trace.get_tracer(__name__)
1919
# Ex: mysql.connector
2020
trace_integration(tracer_source(), mysql.connector, "connect", "mysql")
2121

ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _before_flask_request():
6161
otel_wsgi.get_header_from_environ, environ
6262
)
6363

64-
tracer = trace.tracer_source().get_tracer(__name__, __version__)
64+
tracer = trace.get_tracer(__name__, __version__)
6565

6666
attributes = otel_wsgi.collect_request_attributes(environ)
6767
if flask_request.url_rule:

ext/opentelemetry-ext-jaeger/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ gRPC is still not supported by this implementation.
3636
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
3737
3838
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
39-
tracer = trace.tracer_source().get_tracer(__name__)
39+
tracer = trace.get_tracer(__name__)
4040
4141
# create a JaegerSpanExporter
4242
jaeger_exporter = jaeger.JaegerSpanExporter(

ext/opentelemetry-ext-jaeger/examples/jaeger_exporter_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
77

88
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
9-
tracer = trace.tracer_source().get_tracer(__name__)
9+
tracer = trace.get_tracer(__name__)
1010

1111
# create a JaegerSpanExporter
1212
jaeger_exporter = jaeger.JaegerSpanExporter(

ext/opentelemetry-ext-opentracing-shim/src/opentelemetry/ext/opentracing_shim/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
trace.set_preferred_tracer_source_implementation(lambda T: TracerSource())
3737
3838
# Create an OpenTelemetry Tracer.
39-
otel_tracer = trace.tracer_source().get_tracer(__name__)
39+
otel_tracer = trace.get_tracer(__name__)
4040
4141
# Create an OpenTracing shim.
4242
shim = create_tracer(otel_tracer)

0 commit comments

Comments
 (0)