Skip to content

Commit a5e2061

Browse files
authored
Global error handler cleanup - Jaeger Remote sampler (#2257)
1 parent 40b1869 commit a5e2061

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

opentelemetry-sdk/src/trace/sampler/jaeger_remote/rate_limit.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use opentelemetry::trace::TraceError;
21
use std::time::SystemTime;
32

43
// leaky bucket based rate limit
@@ -9,6 +8,7 @@ pub(crate) struct LeakyBucket {
98
bucket_size: f64,
109
last_time: SystemTime,
1110
}
11+
use opentelemetry::otel_debug;
1212

1313
impl LeakyBucket {
1414
pub(crate) fn new(bucket_size: f64, span_per_sec: f64) -> LeakyBucket {
@@ -53,10 +53,12 @@ impl LeakyBucket {
5353
false
5454
}
5555
}
56-
Err(_) => {
57-
opentelemetry::global::handle_error(TraceError::Other(
58-
"jaeger remote sampler gets rewinded timestamp".into(),
59-
));
56+
Err(err) => {
57+
otel_debug!(
58+
name: "JaegerRemoteSampler.LeakyBucket.ClockAdjustment",
59+
message = "Jaeger remote sampler detected a rewind in system clock",
60+
reason = format!("{:?}", err),
61+
);
6062
true
6163
}
6264
}

opentelemetry-sdk/src/trace/sampler/jaeger_remote/sampler.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::trace::{Sampler, ShouldSample};
55
use futures_util::{stream, StreamExt as _};
66
use http::Uri;
77
use opentelemetry::trace::{Link, SamplingResult, SpanKind, TraceError, TraceId};
8-
use opentelemetry::{global, Context, KeyValue};
8+
use opentelemetry::{otel_warn, Context, KeyValue};
99
use opentelemetry_http::HttpClient;
1010
use std::str::FromStr;
1111
use std::sync::Arc;
@@ -203,7 +203,13 @@ impl JaegerRemoteSampler {
203203
// send request
204204
match Self::request_new_strategy(&client, endpoint.clone()).await {
205205
Ok(remote_strategy_resp) => strategy.update(remote_strategy_resp),
206-
Err(err_msg) => global::handle_error(TraceError::Other(err_msg.into())),
206+
Err(err_msg) => {
207+
otel_warn!(
208+
name: "JaegerRemoteSampler.FailedToFetchStrategy",
209+
message= "Failed to fetch the sampling strategy from the remote endpoint. The last successfully fetched configuration will be used if available; otherwise, the default sampler will be applied until a successful configuration fetch.",
210+
reason = format!("{}", err_msg),
211+
);
212+
}
207213
};
208214
} else {
209215
// shutdown

opentelemetry-sdk/src/trace/sampler/jaeger_remote/sampling_strategy.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::trace::sampler::jaeger_remote::remote::{
44
};
55
use crate::trace::sampler::sample_based_on_probability;
66
use opentelemetry::trace::{
7-
SamplingDecision, SamplingResult, TraceContextExt, TraceError, TraceId, TraceState,
7+
SamplingDecision, SamplingResult, TraceContextExt, TraceId, TraceState,
88
};
9-
use opentelemetry::{global, Context};
9+
use opentelemetry::{otel_warn, Context};
1010
use std::collections::HashMap;
1111
use std::fmt::{Debug, Formatter};
1212
use std::sync::Mutex;
@@ -107,9 +107,10 @@ impl Inner {
107107
}
108108
})
109109
.unwrap_or_else(|_err| {
110-
global::handle_error(TraceError::Other(
111-
"jaeger remote sampler mutex poisoned".into(),
112-
))
110+
otel_warn!(
111+
name: "JaegerRemoteSampler.MutexPoisoned",
112+
message = "Unable to update Jaeger Remote sampling strategy: the sampler's internal mutex is poisoned, likely due to a panic in another thread holding the lock. No further attempts to update the strategy will be made until the application or process restarts, and the last known configuration will continue to be used.",
113+
);
113114
});
114115
}
115116

@@ -137,7 +138,13 @@ impl Inner {
137138
(_, _, Some(probabilistic)) => {
138139
Some(Strategy::Probabilistic(probabilistic.sampling_rate))
139140
}
140-
_ => None,
141+
_ => {
142+
otel_warn!(
143+
name: "JaegerRemoteSampler.InvalidStrategyReceived",
144+
message = "Invalid sampling strategy received from the remote endpoint. Expected one of: OperationSampling, RateLimitingSampling, or ProbabilisticSampling. Continuing to use the previous strategy or default sampler until a successful update.",
145+
);
146+
None
147+
}
141148
}
142149
}
143150

0 commit comments

Comments
 (0)