Skip to content

Remove Global Error handler.#2260

Merged
lalitb merged 18 commits intoopen-telemetry:mainfrom
lalitb:remove-global-error-handler
Nov 5, 2024
Merged

Remove Global Error handler.#2260
lalitb merged 18 commits intoopen-telemetry:mainfrom
lalitb:remove-global-error-handler

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.

@codecov
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/

lalitb and others added 2 commits November 4, 2024 18:04
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
Co-authored-by: Cijo Thomas <cithomas@microsoft.com>
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 !!)

connyay added a commit to connyay/sdk-core that referenced this pull request Apr 23, 2025
Sushisource pushed a commit to connyay/sdk-core that referenced this pull request May 6, 2025
@mdecimus
Copy link

Hi,

We just migrated from opentelemetry-otlp 0.25 and found out about this change. The otel_* macros seem to support only tracing which is an issue for us as we do not use it. Do you have any plans to support custom logging mechanisms or would you accept a PR for this?

@cijothomas
Copy link
Member

Hi,

We just migrated from opentelemetry-otlp 0.25 and found out about this change. The otel_* macros seem to support only tracing which is an issue for us as we do not use it. Do you have any plans to support custom logging mechanisms or would you accept a PR for this?

Yes, we just started with tracing, and more improvements are needed, including providing a different feature-flag, that'd fire callbacks instead of using tracing.
#2697 (comment)

Can you submit a new issue with some more details on the proposal, or can send a draft PR to support this?

@mdecimus
Copy link

Thanks, I've just opened #2992 where I also explained another minor issue related to SdkLogRecord.

meryl-c added a commit to apollographql/router that referenced this pull request Oct 14, 2025
takumi-earth pushed a commit to earthlings-dev/opentelemetry-rust that referenced this pull request Jan 27, 2026
copybara-service bot pushed a commit to project-oak/oak that referenced this pull request Feb 3, 2026
0.28 introduces a large number of significant breaking changes that we
need to address all at once:

open-telemetry/opentelemetry-rust#2260
set_error_handler is removed

open-telemetry/opentelemetry-rust#2227
.init() becomes .build() on metrics builders.
.try_init() is no longer needed (also becomes .build())

open-telemetry/opentelemetry-rust#2575
Metric exporters are created via .builder() now

open-telemetry/opentelemetry-rust#2597
Metrics exporter can be added in commonly used configuration (which works for us) using .with_periodic_exporter

open-telemetry/opentelemetry-rust#2221
Logger creation API changed

* noop removed from public API
It's added back in a future version but that will require tonic update.

open-telemetry/opentelemetry-rust#2210
AsyncInstruments are no longer allowed to call `observe` outside of a
callback, because this usage was incorrect. For some reason, we were
using ObservableGauge in oak_private_memory; possibly because regular
gauge wasn't available. So we add support for sync gauages here and use
that.

0.29 introduces a few breaking changes as well:
open-telemetry/opentelemetry-rust#2790
* Exporter builders now return a different error type

For full details see:
https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-sdk/CHANGELOG.md

Change-Id: I3d7ff01858fde0f39307c2a64c354b7468b5b909
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

3 participants