open-telemetry / opentelemetry-python

OpenTelemetry Python API and SDK
https://opentelemetry.io
Apache License 2.0
1.76k stars 614 forks source link

Record logger name as the instrumentation scope name #3810

Closed tm0nk closed 2 days ago

tm0nk commented 6 months ago

Description

Fixes issue #2485 Record logger name as the instrumentation scope name

Approach: Cache one Logger object per Python logger name in LoggingHandler. The @lru_cache annotation on get_logger requires Python 3.2 or later.

The Open Telemetry Spec specifies that the Logger Name SHOULD be recorded as the Instrumentation Scope name. Reference: https://github.com/open-telemetry/opentelemetry-specification/pull/2359

This has already been implemented in Open Telemetry Java, but not in Open Telemetry Python.

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

I've modified many of the tests in test_export.py to include an assert that tests that the logger name and instrumentation scope name are the same.

Will be happy to modify others to do the same validation.

Does This PR Require a Contrib Repo Change?

No, this brings Open Telemetry Python in line with the existing Open Telemetry spec.

Answer the following question based on these examples of changes that would require a Contrib Repo Change:

Checklist:

linux-foundation-easycla[bot] commented 6 months ago

CLA Signed

The committers listed above are authorized under a signed CLA.

srikanthccv commented 6 months ago

Overall LGTM, Please address the failed checks.

tm0nk commented 6 months ago

Thanks @srikanthccv I've addressed the failed lint check. I'm working on the missing CLA authorization. I'm contributing as a Snowflake employee, so the CLA authorization needs more than just my approval...

tm0nk commented 6 months ago

There is still one failing lint check: method-cache-max-size-none Let me do some research to see about how best to size the cache. Since something similar is already implemented for OpenTelemetry Java, I may draw inspiration from there.

lzchen commented 5 months ago

@tm0nk

This is a great contribution. Please add some benchmark tests to see the implications of multiple calls to get_logger and fix the build when you can. Also as discussed in the Python SIG, using a cache is probably necessary to save us from multiple creations of objects when calling get_logger multiple times.

lzchen commented 3 months ago

@tm0nk

Gentle ping on this issue. Are you still working on this? We will be reassigning this issue if we don't hear back from you.

lzchen commented 3 months ago

@tm0nk

Gentle ping on this. Are you still planning to work on this?

tm0nk commented 2 days ago

@sfc-gh-jopel has opened a PR with these changes: https://github.com/open-telemetry/opentelemetry-python/pull/4208

He will be following up on getting this fix merged. Thanks @sfc-gh-jopel!