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

Remove Global Error handler. #2260

Merged
merged 18 commits into from
Nov 5, 2024

Conversation

lalitb
Copy link
Member

@lalitb lalitb commented Oct 28, 2024

Fixes #2175

Needs #2259 #2257 #2256 to be merged first.

Changes

  • Removed global::set_error_handler and global::handle_error, as the global_handle_error usage inside the opentelemetry crates has already been replaced with global::otel_info, otel_warn, otel_debug and otel_error

Migration Guide:

📌Note: This setup requires the internal-logs feature to be enabled for the OpenTelemetry crates. This feature is enabled by default, so application should ensure not to disable it explicitly for these crates in its Cargo.toml.

This guide explains how to migrate from global::set_error_handler to a new setup with otel_* macros and Tokio tracing. If your application previously used global::set_error_handler, remove it as part of this migration. If not, this configuration ensures errors previously going to eprintln! are now handled through structured tracing.

Step 1: Remove set_error_handler (if used)
If your code currently sets a custom error handler using global::set_error_handler, remove this line and any associated custom handler function.

// Remove any custom error handler
// global::set_error_handler(custom_error_handler).unwrap();

Step 2: Internal OpenTelemetry Logs Filter and Layer:
Set up a layer to handle OpenTelemetry internal logs and stop them from propagating to tracing bridge/appender.

  1. Internal OpenTelemetry Logs Filter and Layer:
    • This layer captures logs with the opentelemetry prefix and prints them to eprintln!.
use tracing_subscriber::filter::filter_fn;
use tracing_subscriber::fmt::Layer;

let opentelemetry_layer = Layer::new()
    .with_writer(std::io::stderr)
    .with_filter(filter_fn(|metadata| metadata.target().starts_with("opentelemetry")));
  1. Bridge Layer for OpenTelemetry Tracing (Excludes OpenTelemetry Internal Logs)::
    • To prevent logs with the opentelemetry prefix from propagating further, apply a filter_fn in this layer that excludes any logs with the opentelemetry target prefix.
use opentelemetry_appender_tracing::layer;

let non_opentelemetry_filter = filter_fn(|metadata| !metadata.target().starts_with("opentelemetry"));
let otel_bridge_layer = layer::OpenTelemetryTracingBridge::new(&cloned_provider)
   .with_filter(non_opentelemetry_filter);

Step 3: Register Layers in the Tracing Registry

use tracing_subscriber::prelude::*;

tracing_subscriber::registry()
    .with(opentelemetry_layer)       // OpenTelemetry internal logs (filtered out)
    .with(otel_bridge_layer)         // OpenTelemetry tracing bridge
    .init();

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@lalitb lalitb requested a review from a team as a code owner October 28, 2024 18:59
Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

Given this is breaking change, we need to add it to changelog. and also show a migration guide for anyone who were relying on this previously.

Copy link

codecov bot commented Nov 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.5%. Comparing base (eca53b2) to head (c61db83).
Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2260   +/-   ##
=====================================
  Coverage   79.4%   79.5%           
=====================================
  Files        121     121           
  Lines      20981   20960   -21     
=====================================
- Hits       16673   16671    -2     
+ Misses      4308    4289   -19     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lalitb
Copy link
Member Author

lalitb commented Nov 3, 2024

Given this is breaking change, we need to add it to changelog. and also show a migration guide for anyone who were relying on this previously.

Done/

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

LGTM.
I'll try our self-diagnostics with few scenarios later and make suggestions, if any. (I am a customer of the internal logs !!)

@lalitb lalitb merged commit 91f44ff into open-telemetry:main Nov 5, 2024
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove global error handler in favor of internal logs
2 participants