Skip to content

Commit e4db217

Browse files
committed
libname -> module name
1 parent b7c688c commit e4db217

File tree

18 files changed

+44
-59
lines changed

18 files changed

+44
-59
lines changed

README.md

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

examples/basic_tracer/tracer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
# We tell OpenTelemetry who it is that is creating spans. In this case, we have
4343
# no real name (no setup.py), so we make one up. If we had a version, we would
4444
# also specify it here.
45-
tracer = trace.tracer_source().get_tracer(
46-
"opentelemetry-examples-basic-tracer"
47-
)
45+
tracer = trace.tracer_source().get_tracer(__name__)
4846

4947
# SpanExporter receives the spans and send them to the target location.
5048
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("opentelemetry-example-http")
45+
tracer = trace.tracer_source().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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def hello():
7171
version = pkg_resources.get_distribution(
7272
"opentelemetry-example-app"
7373
).version
74-
tracer = trace.tracer_source().get_tracer(
75-
"opentelemetry-example-app", version
76-
)
74+
tracer = trace.tracer_source().get_tracer(__name__, version)
7775
with tracer.start_as_current_span("example-request"):
7876
requests.get("http://www.example.com")
7977
return "hello"

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

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

64-
tracer = trace.tracer_source().get_tracer(
65-
"opentelemetry-ext-flask", __version__
66-
)
64+
tracer = trace.tracer_source().get_tracer(__name__, __version__)
6765

6866
attributes = otel_wsgi.collect_request_attributes(environ)
6967
if flask_request.url_rule:

ext/opentelemetry-ext-http-requests/src/opentelemetry/ext/http_requests/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def enable(tracer_source):
4848
# Guard against double instrumentation
4949
disable()
5050

51-
tracer = tracer_source.get_tracer(
52-
"opentelemetry-ext-http-requests", __version__
53-
)
51+
tracer = tracer_source.get_tracer(__name__, __version__)
5452

5553
wrapped = Session.request
5654

ext/opentelemetry-ext-http-requests/tests/test_requests_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ def setspanattr(key, value):
5555
spec_set=True,
5656
return_value=self.span_context_manager,
5757
)
58-
self.start_as_current_span = self.start_span_patcher.start()
5958

6059
mocked_response = requests.models.Response()
6160
mocked_response.status_code = 200
@@ -67,15 +66,16 @@ def setspanattr(key, value):
6766
spec_set=True,
6867
return_value=mocked_response,
6968
)
69+
70+
self.start_as_current_span = self.start_span_patcher.start()
7071
self.send = self.send_patcher.start()
7172

7273
opentelemetry.ext.http_requests.enable(self.tracer_source)
7374
distver = pkg_resources.get_distribution(
7475
"opentelemetry-ext-http-requests"
7576
).version
7677
self.get_tracer.assert_called_with(
77-
"opentelemetry-ext-http-requests", distver
78-
)
78+
opentelemetry.ext.http_requests.__name__, distver)
7979

8080
def tearDown(self):
8181
opentelemetry.ext.http_requests.disable()

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("myapp")
39+
tracer = trace.tracer_source().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("myapp")
9+
tracer = trace.tracer_source().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: 2 additions & 6 deletions
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("myapp")
39+
otel_tracer = trace.tracer_source().get_tracer(__name__)
4040
4141
# Create an OpenTracing shim.
4242
shim = create_tracer(otel_tracer)
@@ -110,11 +110,7 @@ def create_tracer(otel_tracer_source):
110110
The created :class:`TracerShim`.
111111
"""
112112

113-
return TracerShim(
114-
otel_tracer_source.get_tracer(
115-
"opentelemetry-ext-opentracing-shim", __version__
116-
)
117-
)
113+
return TracerShim(otel_tracer_source.get_tracer(__name__, __version__))
118114

119115

120116
class SpanContextShim(opentracing.SpanContext):

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ class OpenTelemetryMiddleware:
164164

165165
def __init__(self, wsgi):
166166
self.wsgi = wsgi
167-
self.tracer = trace.tracer_source().get_tracer(
168-
"opentelemetry-ext-wsgi", __version__
169-
)
167+
self.tracer = trace.tracer_source().get_tracer(__name__, __version__)
170168

171169
@staticmethod
172170
def _create_start_response(span, start_response):

opentelemetry-api/src/opentelemetry/trace/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
2828
To get a tracer, you need to provide the package name from which you are
2929
calling the tracer APIs to OpenTelemetry by calling `TracerSource.get_tracer`
30-
with the name and version of your package.
30+
with the calling module name and the version of your package.
3131
3232
The tracer supports creating spans that are "attached" or "detached" from the
3333
context. New spans are "attached" to the context in that they are
@@ -36,7 +36,7 @@
3636
3737
from opentelemetry import trace
3838
39-
tracer = trace.tracer_source().get_tracer("my-instrumentation-library")
39+
tracer = trace.tracer_source().get_tracer(__name__)
4040
4141
# Create a new root span, set it as the current span in context
4242
with tracer.start_as_current_span("parent"):
@@ -378,7 +378,7 @@ class TracerSource:
378378
# pylint:disable=no-self-use,unused-argument
379379
def get_tracer(
380380
self,
381-
instrumenting_library_name: str,
381+
instrumenting_module_name: str,
382382
instrumenting_library_version: str = "",
383383
) -> "Tracer":
384384
"""Returns a `Tracer` for use by the given instrumentation library.
@@ -390,14 +390,13 @@ def get_tracer(
390390
vs. a functional tracer).
391391
392392
Args:
393-
instrumenting_library_name: The name of the instrumenting library.
394-
This should *not* be the name of the library that is
395-
instrumented but the name of the instrumentation library.
396-
E.g., instead of ``"requests"``,
397-
``"opentelemetry-ext-http-requests"``.
398-
399-
This should be the ``pip install``-able name of the library
400-
rather than the module name (see also the next argument).
393+
instrumenting_module_name: The name of the instrumenting module
394+
(usually just ``__name__``).
395+
396+
This should *not* be the name of the module that is
397+
instrumented but the name of the module doing the instrumentation.
398+
E.g., instead of ``"requests"``, use
399+
``"opentelemetry.ext.http_requests"``.
401400
402401
instrumenting_library_version: Optional. The version string of the
403402
instrumenting library. Usually this should be the same as

opentelemetry-api/tests/test_implementation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TestAPIOnlyImplementation(unittest.TestCase):
2727

2828
def test_tracer(self):
2929
tracer_source = trace.TracerSource()
30-
tracer = tracer_source.get_tracer("opentelemetry-api")
30+
tracer = tracer_source.get_tracer(__name__)
3131
with tracer.start_span("test") as span:
3232
self.assertEqual(span.get_context(), trace.INVALID_SPAN_CONTEXT)
3333
self.assertEqual(span, trace.INVALID_SPAN)

opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def generate_trace_id() -> int:
329329

330330

331331
class InstrumentationInfo:
332-
"""Immutable information about an instrumentation library.
332+
"""Immutable information about an instrumentation library module.
333333
334334
See `TracerSource.get_tracer` for the meaning of the properties.
335335
"""
@@ -516,16 +516,16 @@ def __init__(
516516

517517
def get_tracer(
518518
self,
519-
instrumenting_library_name: str,
519+
instrumenting_module_name: str,
520520
instrumenting_library_version: str = "",
521521
) -> "trace_api.Tracer":
522-
if not instrumenting_library_name: # Reject empty strings too.
523-
instrumenting_library_name = "ERROR:MISSING LIB NAME"
524-
logger.error("get_tracer called with missing library name.")
522+
if not instrumenting_module_name: # Reject empty strings too.
523+
instrumenting_module_name = "ERROR:MISSING MODULE NAME"
524+
logger.error("get_tracer called with missing module name.")
525525
return Tracer(
526526
self,
527527
InstrumentationInfo(
528-
instrumenting_library_name, instrumenting_library_version
528+
instrumenting_module_name, instrumenting_library_version
529529
),
530530
)
531531

opentelemetry-sdk/tests/test_implementation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TestSDKImplementation(unittest.TestCase):
2828
"""
2929

3030
def test_tracer(self):
31-
tracer = trace.TracerSource().get_tracer("opentelemetery-sdk")
31+
tracer = trace.TracerSource().get_tracer(__name__)
3232
with tracer.start_span("test") as span:
3333
self.assertNotEqual(span.get_context(), INVALID_SPAN_CONTEXT)
3434
self.assertNotEqual(span, INVALID_SPAN)

opentelemetry-sdk/tests/trace/export/test_export.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def shutdown(self):
4545
class TestSimpleExportSpanProcessor(unittest.TestCase):
4646
def test_simple_span_processor(self):
4747
tracer_source = trace.TracerSource()
48-
tracer = tracer_source.get_tracer("opentelemetry-sdk")
48+
tracer = tracer_source.get_tracer(__name__)
4949

5050
spans_names_list = []
5151

@@ -70,7 +70,7 @@ def test_simple_span_processor_no_context(self):
7070
not it is ever the active span.
7171
"""
7272
tracer_source = trace.TracerSource()
73-
tracer = tracer_source.get_tracer("opentelemetry-sdk")
73+
tracer = tracer_source.get_tracer(__name__)
7474

7575
spans_names_list = []
7676

opentelemetry-sdk/tests/trace/export/test_in_memory_span_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class TestInMemorySpanExporter(unittest.TestCase):
2727
def setUp(self):
2828
self.tracer_source = trace.TracerSource()
29-
self.tracer = self.tracer_source.get_tracer("opentelemetry-sdk")
29+
self.tracer = self.tracer_source.get_tracer(__name__)
3030
self.memory_exporter = InMemorySpanExporter()
3131
span_processor = export.SimpleExportSpanProcessor(self.memory_exporter)
3232
self.tracer_source.add_span_processor(span_processor)

opentelemetry-sdk/tests/trace/test_trace.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
def new_tracer() -> trace_api.Tracer:
28-
return trace.TracerSource().get_tracer("opentelemetry-sdk")
28+
return trace.TracerSource().get_tracer(__name__)
2929

3030

3131
class TestTracer(unittest.TestCase):
@@ -119,7 +119,7 @@ def test_default_sampler(self):
119119

120120
def test_sampler_no_sampling(self):
121121
tracer_source = trace.TracerSource(sampling.ALWAYS_OFF)
122-
tracer = tracer_source.get_tracer("opentelemetry-sdk")
122+
tracer = tracer_source.get_tracer(__name__)
123123

124124
# Check that the default tracer creates no-op spans if the sampler
125125
# decides not to sampler
@@ -179,7 +179,7 @@ def test_invalid_instrumentation_info(self):
179179
self.assertTrue(span1.is_recording_events())
180180
self.assertEqual(tracer1.instrumentation_info.version, "")
181181
self.assertEqual(
182-
tracer1.instrumentation_info.name, "ERROR:MISSING LIB NAME"
182+
tracer1.instrumentation_info.name, "ERROR:MISSING MODULE NAME"
183183
)
184184

185185
def test_span_processor_for_source(self):
@@ -404,7 +404,7 @@ def test_sampling_attributes(self):
404404
)
405405
)
406406

407-
self.tracer = tracer_source.get_tracer("opentelemetry-sdk")
407+
self.tracer = tracer_source.get_tracer(__name__)
408408

409409
with self.tracer.start_as_current_span("root2") as root:
410410
self.assertEqual(len(root.attributes), 2)
@@ -578,9 +578,9 @@ def test_ended_span(self):
578578

579579
def test_error_status(self):
580580
try:
581-
with trace.TracerSource().get_tracer(
582-
"opentelemetry-sdk"
583-
).start_span("root") as root:
581+
with trace.TracerSource().get_tracer(__name__).start_span(
582+
"root"
583+
) as root:
584584
raise Exception("unknown")
585585
except Exception: # pylint: disable=broad-except
586586
pass
@@ -612,7 +612,7 @@ def on_end(self, span: "trace.Span") -> None:
612612
class TestSpanProcessor(unittest.TestCase):
613613
def test_span_processor(self):
614614
tracer_source = trace.TracerSource()
615-
tracer = tracer_source.get_tracer("opentelemetry-sdk")
615+
tracer = tracer_source.get_tracer(__name__)
616616

617617
spans_calls_list = [] # filled by MySpanProcessor
618618
expected_list = [] # filled by hand
@@ -681,7 +681,7 @@ def test_span_processor(self):
681681

682682
def test_add_span_processor_after_span_creation(self):
683683
tracer_source = trace.TracerSource()
684-
tracer = tracer_source.get_tracer("opentelemetry-sdk")
684+
tracer = tracer_source.get_tracer(__name__)
685685

686686
spans_calls_list = [] # filled by MySpanProcessor
687687
expected_list = [] # filled by hand

0 commit comments

Comments
 (0)