Add enabled checks for logs API, SDK, and processors - #5500
Open
saisharan0103 wants to merge 1 commit into
Open
Conversation
…No `Enabled` support across API, SDK, and processors Closes open-telemetry#5360
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #5360 reported that the logs API only exposes
Logger.emit, leaving instrumentation without a public enabled predicate to avoid constructing expensiveLogRecordobjects. The SDK logger also only had a private_is_enabled()configurator check and did not consult registeredLogRecordProcessorinstances or processor interest for the current context, instrumentation scope, severity number, and event name.This adds a public
enabled(context=None, severity_number=None, event_name=None)method to the API logger surface.NoOpLoggerreturnsfalse, andProxyLoggerforwards the check to the real logger.The SDK now exposes an optional default
LogRecordProcessor.enabled(context, instrumentation_scope, severity_number, event_name)hook and implements the multi-processor predicate so it returnsfalsewith no processors, returnsfalseonly when every registered processor returnsfalse, and returnstruewhen any processor returnstrue.Logger.enablednow combines the existing logger configurator gate with the multi-processor predicate.emitcallsenabledwith the record or parameter context, severity, and event before creating or forwarding the writable record.Updated files:
opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.pyopentelemetry-api/tests/logs/test_proxy.pyopentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.pyopentelemetry-sdk/tests/logs/test_logs.pyopentelemetry-sdk/tests/logs/test_multi_log_processor.pyruff check opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py opentelemetry-api/tests/logs/test_proxy.py opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/__init__.py opentelemetry-sdk/tests/logs/test_logs.py opentelemetry-sdk/tests/logs/test_multi_log_processor.pyreports no new findings on the changed files.Ran
pytest -xlocally with no new failures.