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

Update gettracer #1854

Merged
merged 8 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/open-telemetry/opentelemetry-python/compare/v1.2.0-0.21b0...HEAD)

- Updated get_tracer to return an empty string when passed an invalid name
([#1854](https://github.com/open-telemetry/opentelemetry-python/pull/1854))

## [1.2.0, 0.21b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.2.0-0.21b0) - 2021-05-11

### Added
Expand Down
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
18 changes: 13 additions & 5 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,27 @@ def test_invalid_instrumentation_info(self):
tracer1 = tracer_provider.get_tracer("")
with self.assertLogs(level=ERROR):
tracer2 = tracer_provider.get_tracer(None)
self.assertEqual(
tracer1.instrumentation_info, tracer2.instrumentation_info
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for this test to be moved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believed that having the more granular tests for the individual tracer would provide more information upon failing; then, this test just makes sure that the two tracers created are identical, which is asserted after each individual attribute is checked. I'm not sure if that's good practice, though, so I'd appreciate the feedback!

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, "")

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, "")

self.assertEqual(
tracer1.instrumentation_info, tracer2.instrumentation_info
)

def test_span_processor_for_source(self):
tracer_provider = trace.TracerProvider()
tracer1 = tracer_provider.get_tracer("instr1")
Expand Down