-
Notifications
You must be signed in to change notification settings - Fork 593
fix: Explore how to achieve telemetry suppression with OTLP #3084
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,13 @@ | ||||||||||
| use opentelemetry::trace::{TraceContextExt, Tracer}; | ||||||||||
| use opentelemetry::KeyValue; | ||||||||||
| use opentelemetry::{global, InstrumentationScope}; | ||||||||||
| use opentelemetry::{Context, KeyValue}; | ||||||||||
| use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; | ||||||||||
| use opentelemetry_otlp::{LogExporter, MetricExporter, SpanExporter}; | ||||||||||
| use opentelemetry_sdk::logs::SdkLoggerProvider; | ||||||||||
| use opentelemetry_sdk::metrics::SdkMeterProvider; | ||||||||||
| use opentelemetry_sdk::trace::SdkTracerProvider; | ||||||||||
| use opentelemetry_sdk::Resource; | ||||||||||
| use std::cell::RefCell; | ||||||||||
| use std::error::Error; | ||||||||||
| use std::sync::OnceLock; | ||||||||||
| use tracing::info; | ||||||||||
|
|
@@ -59,33 +60,37 @@ fn init_logs() -> SdkLoggerProvider { | |||||||||
| .build() | ||||||||||
| } | ||||||||||
|
|
||||||||||
| #[tokio::main] | ||||||||||
| async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> { | ||||||||||
| let logger_provider = init_logs(); | ||||||||||
| thread_local! { | ||||||||||
| static SUPPRESS_GUARD: RefCell<Option<opentelemetry::ContextGuard>> = const { RefCell::new(None) }; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // #[tokio::main] | ||||||||||
|
||||||||||
| // #[tokio::main] |
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.
can we ask tokio::main macro's to provide on_start/on_end callback..similar to the way they offer on_panic..?
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.
todo: cleanup http one and confirm it does not need this technique by default.
todo: see if the client authors offer a way to opt-out of telemetry.
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.
check if this can be wrapped inside std::thread
Copilot
AI
Jul 25, 2025
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.
[nitpick] The comment spans multiple lines but uses single-line comment syntax. Consider using proper multi-line comment format or clarify the reasoning more concisely in a single line.
| .worker_threads(1) // Don't think this matters as no matter how many threads | |
| // are created, we intercept the thread start to set suppress guard. | |
| .worker_threads(1) /* Don't think this matters as no matter how many threads | |
| are created, we intercept the thread start to set suppress guard. */ |
Copilot
AI
Jul 25, 2025
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 init_logs() function is not async but is being wrapped in an async block unnecessarily. Consider calling it directly: let logger_provider = init_logs();
| let logger_provider = rt.block_on(async { init_logs() }); | |
| let logger_provider = init_logs(); |
Copilot
AI
Jul 25, 2025
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 init_traces() function is not async but is being wrapped in an async block unnecessarily. Consider calling it directly: let tracer_provider = init_traces();
| let tracer_provider = rt.block_on(async { init_traces() }); | |
| let tracer_provider = init_traces(); |
Copilot
AI
Jul 25, 2025
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 init_metrics() function is not async but is being wrapped in an async block unnecessarily. Consider calling it directly: let meter_provider = init_metrics();
| let meter_provider = rt.block_on(async { init_metrics() }); | |
| let meter_provider = init_metrics(); |
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.
If user's application relies on tokio, then they can create a Rt themselves, and wrap their main method inside rt.blockon({...app code..}), ensuring telemetry initialization is outside of it.