-
Notifications
You must be signed in to change notification settings - Fork 571
fix: Fix stack-overflow inducing infinite feedback loop when calling tracing::event!
after SdkLoggerProvider::shutdown
#3162
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
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3162 +/- ##
=====================================
Coverage 80.6% 80.6%
=====================================
Files 126 126
Lines 22195 22198 +3
=====================================
+ Hits 17898 17901 +3
Misses 4297 4297 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
f48bcd5
to
407c081
Compare
I am aware that this is likely not the most optimal solution, as the bug ultimately lies in the integration between the otel_sdk and the tracing subscriber. An alternative would be to add a public method |
407c081
to
92fa1ba
Compare
// cycle. This may occur when integrating with the `tracing` crate due to | ||
// `otel_warn!` possibly calling `tracing::warn!` under the hood, which will emit | ||
// the warning back into the otel log processor. | ||
if matches!((record.event_name, record.target()), (Some(event_name), Some(target_name)) if !(event_name == Self::AFTER_SHUTDOWN_WARNING_NAME && target_name == env!("CARGO_CRATE_NAME"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think we can hardcode our way out. We need to find why Context based suppression is not working and fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointer, it seems that unlike SdkTracer, SdkLogger does not discard logs when the provider is shutdown. The PR has been adjusted accordingly
92fa1ba
to
63b6e18
Compare
// cycle. This may occur when integrating with the `tracing` crate due to | ||
// `otel_warn!` possibly calling `tracing::warn!` under the hood, which will emit | ||
// the warning back into the otel log processor. | ||
if matches!((record.event_name, record.target()), (Some(event_name), Some(target_name)) if !(event_name == Self::AFTER_SHUTDOWN_WARNING_NAME && target_name == env!("CARGO_CRATE_NAME"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointer, it seems that unlike SdkTracer, SdkLogger does not discard logs when the provider is shutdown. The PR has been adjusted accordingly
@@ -33,7 +33,7 @@ impl opentelemetry::logs::Logger for SdkLogger { | |||
|
|||
/// Emit a `LogRecord`. | |||
fn emit(&self, mut record: Self::LogRecord) { | |||
if Context::is_current_telemetry_suppressed() { | |||
if Context::is_current_telemetry_suppressed() || self.provider.is_shutdown() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also suppresses the warning logs emitted when a log is sent after the LoggerProvider is shutdown, effectively hiding the log.
63b6e18
to
4eac469
Compare
@lalitb @cijothomas The PR is ready for you guys to have another look. @cijothomas Is this what you had in mind when you mentioned "Context based suppression"? Do note that since logs sent to a BatchLogProcessor with a shutdown provider are no longer propagated to the underlying loggers, the original log warning of a log being emitted after shutdown is no longer emitted. Is this an acceptable trade off for you guys? |
Note that the build is currently failing due to a recent version of serde including some breaking changes. This issue is tackled in another PR: #3165 |
…`tracing::event!` after `SdkLoggerProvider::shutdown`
4eac469
to
2f95832
Compare
Closing in favour of #3172, which follows the maintainer's suggestions of fixing context suppression for |
Fixes #3161
Design discussion issue (if applicable) #
Changes
When integrating the opentelemetry crate with the tracing_subscriber crate, calling tracing::event! and its derivates after the SdkLoggerProvider has been called leads to a stack overflow due to BatchLogProcessor::emit using otel_warn! when trying to report the mpsc::TrySendError:Disconnected error.
This PR prevents
otel_warn!
from being called when handling thempsc::TrySendError:Disconnected
error inBatchLogProcessor::emit
if the name of the log record is the same as that emitted by theotel_warn!
in the same branch.Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes