-
Notifications
You must be signed in to change notification settings - Fork 421
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
Improve internal opentelemetry logging #2128
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2128 +/- ##
=====================================
Coverage 78.3% 78.3%
=====================================
Files 121 121
Lines 20767 20804 +37
=====================================
+ Hits 16268 16300 +32
- Misses 4499 4504 +5 ☔ View full report in Codecov by Sentry. |
…emetry-rust into log-handler-using-tracing
@@ -12,16 +12,16 @@ rust-version = "1.65" | |||
|
|||
[dependencies] | |||
log = { workspace = true, optional = true } | |||
opentelemetry = { version = "0.25", path = "../opentelemetry", features = ["logs"] } | |||
opentelemetry = { version = "0.25", path = "../opentelemetry", features = ["logs","experimental-internal-debugging"] } |
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.
name of the experimental flag - experimental-internal-debugging
?
.with_filter(filter_fn(|meta| meta.target().starts_with("opentelemetry"))) // Custom filter function | ||
.with_filter(env_filter); | ||
tracing_subscriber::registry() | ||
.with(internal_log_layer) |
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.
as the internal_log_layer
can be added only after the LoggerProvider
is created, any internal logs till that time won't be logged. This would be the case for logs and traces, and not metrics.
@@ -157,6 +157,9 @@ where | |||
event: &tracing::Event<'_>, | |||
_ctx: tracing_subscriber::layer::Context<'_, S>, | |||
) { | |||
if event.metadata().target().starts_with("opentelemetry") { | |||
return; | |||
} |
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.
To prevent infinite logging, events with the target prefix opentelemetry
are suppressed at the on_event
level. Suppressing at the enabled
level would block these events from reaching other layers (both higher and lower in the order). While suppressing at the on_event
level introduces a minimal overhead (~ .6% in stress test), this approach is safer as it ensures that if the application owner forgets to handle suppression, the application won't crash with a stack overflow. We need to discuss the best approach based on these considerations.
/// - `target`: The component or module generating the log. This identifies which crate or system part is logging the message (e.g., "opentelemetry-sdk", "opentelemetry-otlp"). | ||
/// - `name`: The operation or action being logged. This provides context on what the system is doing at the time the log is emitted (e.g., "sdk_initialization", "exporter_start"). | ||
/// - `signal`: The type of telemetry data related to the log. This could be "trace", "metric", or "log", representing the OpenTelemetry signal. | ||
/// |
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.
The target
, name
, and signal
fields are mandatory. While recommendations are provided for what these fields should contain, their values are not strictly enforced. Further discussion is needed to determine whether a more specific representation or stricter validation should be implemented for these fields.
tracing_subscriber::registry().with(layer).init(); | ||
|
||
error!(name: "my-event-name", target: "my-system", event_id = 20, user_name = "otel", user_email = "[email protected]", message = "This is an example message"); | ||
let env_filter = EnvFilter::from_default_env(); |
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.
this example is to show the usage of appender-tracing, and we can leave it untouched. We need to fix https://github.com/open-telemetry/opentelemetry-rust/tree/main/examples/self-diagnostics to showcase this, if needed.
I am unsure if we need to show this with a full blown example, but no harm doing it in https://github.com/open-telemetry/opentelemetry-rust/tree/main/examples/self-diagnostics
@@ -49,6 +50,9 @@ impl opentelemetry::logs::LoggerProvider for LoggerProvider { | |||
attributes: Option<Vec<opentelemetry::KeyValue>>, | |||
) -> Logger { | |||
let name = name.into(); | |||
otel_info!(target: "opentelemetry-sdk", name: "logger_versioned_creation", signal: "log", |
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.
target
I think the usage of component name for target looks good. Though we need to discuss further about making it even more specific, like opentelemetry-sdk.log.logemitter?
name
Looks good. We need to develop conventions. (like using "." vs "_" separator).
signal
I don't think this is required. Target+Name should be sufficient.
message
I think we should only promote key/values pairs, and leave the message out, unless there is a strong need.
Lets also use a named field as that is proved much faster : #2001
@@ -0,0 +1,130 @@ | |||
#![allow(unused_macros)] | |||
/// Macro for logging messages at the general log level in OpenTelemetry. |
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.
a warning at the top to indicate that this meant for user by OpenTelemetry components itself.
Fixes #1146
Changes
Created the draft PR to discuss the approach as mentioned here
Have added comment on some of the open issues.
Sample out of the appender-tracing example:
Scenario 1: only output internal
error
:Scenario 2: output
info
and above:Scenario 3: output 'debug' and above:
Please provide a brief description of the changes here.
Merge requirement checklist
CHANGELOG.md
files updated for non-trivial, user-facing changes