Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert invalid inputs (None and empty string) to empty string for tracer name #17

Closed
wants to merge 8 commits into from
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1809])(https://github.com/open-telemetry/opentelemetry-python/pull/1809)
- Fixed sequence values in OTLP exporter not translating
([#1818](https://github.com/open-telemetry/opentelemetry-python/pull/1818))
- Update get_tracer to return an empty string when passed an invalid name
(TBD)

### Removed
- Moved `opentelemetry-instrumentation` to contrib repository.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ def get_tracer(
instrumenting_library_version: str = "",
) -> "trace_api.Tracer":
if not instrumenting_module_name: # Reject empty strings too.
instrumenting_module_name = "ERROR:MISSING MODULE NAME"
instrumenting_module_name = ""
logger.error("get_tracer called with missing module name.")
return Tracer(
self.sampler,
Expand Down
11 changes: 9 additions & 2 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,22 @@ def test_invalid_instrumentation_info(self):
self.assertEqual(
tracer1.instrumentation_info, tracer2.instrumentation_info
)

self.assertIsInstance(
tracer1.instrumentation_info, InstrumentationInfo
)
span1 = tracer1.start_span("foo")
self.assertTrue(span1.is_recording())
self.assertEqual(tracer1.instrumentation_info.version, "")
self.assertEqual(
tracer1.instrumentation_info.name, "ERROR:MISSING MODULE NAME"
self.assertEqual(tracer1.instrumentation_info.name, "")

eddyleelin marked this conversation as resolved.
Show resolved Hide resolved
self.assertIsInstance(
tracer2.instrumentation_info, InstrumentationInfo
)
span2 = tracer2.start_span("bar")
self.assertTrue(span2.is_recording())
self.assertEqual(tracer2.instrumentation_info.version, "")
self.assertEqual(tracer2.instrumentation_info.name, "")
kxyr marked this conversation as resolved.
Show resolved Hide resolved

def test_span_processor_for_source(self):
tracer_provider = trace.TracerProvider()
Expand Down