Skip to content

Commit e99bb97

Browse files
authored
Merge branch 'main' into value-map-collect
2 parents 66cb25a + 16f80c2 commit e99bb97

File tree

7 files changed

+70
-48
lines changed

7 files changed

+70
-48
lines changed

opentelemetry-sdk/src/metrics/internal/histogram.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct HistogramTracker<T> {
1313
buckets: Mutex<Buckets<T>>,
1414
}
1515

16-
impl<T> Aggregator<T> for HistogramTracker<T>
16+
impl<T> Aggregator for HistogramTracker<T>
1717
where
1818
T: Number,
1919
{
@@ -85,7 +85,7 @@ impl<T: Number> Buckets<T> {
8585
/// Summarizes a set of measurements as a histogram with explicitly defined
8686
/// buckets.
8787
pub(crate) struct Histogram<T: Number> {
88-
value_map: ValueMap<T, HistogramTracker<T>>,
88+
value_map: ValueMap<HistogramTracker<T>>,
8989
bounds: Vec<f64>,
9090
record_min_max: bool,
9191
record_sum: bool,

opentelemetry-sdk/src/metrics/internal/last_value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ where
1313
pub(crate) value: T::AtomicTracker,
1414
}
1515

16-
impl<T> Aggregator<T> for Assign<T>
16+
impl<T> Aggregator for Assign<T>
1717
where
1818
T: Number,
1919
{
@@ -39,7 +39,7 @@ where
3939

4040
/// Summarizes a set of measurements as the last one made.
4141
pub(crate) struct LastValue<T: Number> {
42-
value_map: ValueMap<T, Assign<T>>,
42+
value_map: ValueMap<Assign<T>>,
4343
start: Mutex<SystemTime>,
4444
}
4545

opentelemetry-sdk/src/metrics/internal/mod.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ use crate::metrics::AttributeSet;
2323
pub(crate) static STREAM_OVERFLOW_ATTRIBUTES: Lazy<Vec<KeyValue>> =
2424
Lazy::new(|| vec![KeyValue::new("otel.metric.overflow", "true")]);
2525

26-
pub(crate) trait Aggregator<T>
27-
where
28-
T: Number,
29-
{
26+
pub(crate) trait Aggregator {
3027
/// A static configuration that is needed in order to initialize aggregator.
3128
/// E.g. bucket_size at creation time .
3229
type InitConfig;
@@ -50,10 +47,9 @@ where
5047
///
5148
/// This structure is parametrized by an `Operation` that indicates how
5249
/// updates to the underlying value trackers should be performed.
53-
pub(crate) struct ValueMap<T, A>
50+
pub(crate) struct ValueMap<A>
5451
where
55-
T: Number,
56-
A: Aggregator<T>,
52+
A: Aggregator,
5753
{
5854
/// Trackers store the values associated with different attribute sets.
5955
trackers: RwLock<HashMap<Vec<KeyValue>, Arc<A>>>,
@@ -67,10 +63,9 @@ where
6763
config: A::InitConfig,
6864
}
6965

70-
impl<T, A> ValueMap<T, A>
66+
impl<A> ValueMap<A>
7167
where
72-
T: Number,
73-
A: Aggregator<T>,
68+
A: Aggregator,
7469
{
7570
fn new(config: A::InitConfig) -> Self {
7671
ValueMap {

opentelemetry-sdk/src/metrics/internal/precomputed_sum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{collections::HashMap, mem::replace, ops::DerefMut, sync::Mutex, time::
77

88
/// Summarizes a set of pre-computed sums as their arithmetic sum.
99
pub(crate) struct PrecomputedSum<T: Number> {
10-
value_map: ValueMap<T, Assign<T>>,
10+
value_map: ValueMap<Assign<T>>,
1111
monotonic: bool,
1212
start: Mutex<SystemTime>,
1313
reported: Mutex<HashMap<Vec<KeyValue>, T>>,

opentelemetry-sdk/src/metrics/internal/sum.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ where
1616
value: T::AtomicTracker,
1717
}
1818

19-
impl<T> Aggregator<T> for Increment<T>
19+
impl<T> Aggregator for Increment<T>
2020
where
2121
T: Number,
2222
{
@@ -42,7 +42,7 @@ where
4242

4343
/// Summarizes a set of measurements made as their arithmetic sum.
4444
pub(crate) struct Sum<T: Number> {
45-
value_map: ValueMap<T, Increment<T>>,
45+
value_map: ValueMap<Increment<T>>,
4646
monotonic: bool,
4747
start: Mutex<SystemTime>,
4848
}

opentelemetry-sdk/src/trace/config.rs

+31-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! can be set for the default OpenTelemetry limits and Sampler.
55
use crate::trace::{span_limit::SpanLimits, IdGenerator, RandomIdGenerator, Sampler, ShouldSample};
66
use crate::Resource;
7-
use opentelemetry::global::{handle_error, Error};
7+
use opentelemetry::otel_warn;
88
use std::borrow::Cow;
99
use std::env;
1010
use std::str::FromStr;
@@ -125,13 +125,14 @@ impl Default for Config {
125125
"always_on" => Box::new(Sampler::AlwaysOn),
126126
"always_off" => Box::new(Sampler::AlwaysOff),
127127
"traceidratio" => {
128-
let ratio = sampler_arg.and_then(|r| r.parse::<f64>().ok());
128+
let ratio = sampler_arg.as_ref().and_then(|r| r.parse::<f64>().ok());
129129
if let Some(r) = ratio {
130130
Box::new(Sampler::TraceIdRatioBased(r))
131131
} else {
132-
handle_error(
133-
Error::Other(String::from(
134-
"Missing or invalid OTEL_TRACES_SAMPLER_ARG value. Falling back to default: 1.0"))
132+
otel_warn!(
133+
name: "TracerProvider.Config.InvalidSamplerArgument",
134+
message = "OTEL_TRACES_SAMPLER is set to 'traceidratio' but OTEL_TRACES_SAMPLER_ARG environment variable is missing or invalid. OTEL_TRACES_SAMPLER_ARG must be a valid float between 0.0 and 1.0 representing the desired sampling probability (0.0 = no traces sampled, 1.0 = all traces sampled, 0.5 = 50% of traces sampled). Falling back to default ratio: 1.0 (100% sampling)",
135+
otel_traces_sampler_arg = format!("{:?}", sampler_arg)
135136
);
136137
Box::new(Sampler::TraceIdRatioBased(1.0))
137138
}
@@ -143,43 +144,51 @@ impl Default for Config {
143144
Box::new(Sampler::ParentBased(Box::new(Sampler::AlwaysOff)))
144145
}
145146
"parentbased_traceidratio" => {
146-
let ratio = sampler_arg.and_then(|r| r.parse::<f64>().ok());
147+
let ratio = sampler_arg.as_ref().and_then(|r| r.parse::<f64>().ok());
147148
if let Some(r) = ratio {
148149
Box::new(Sampler::ParentBased(Box::new(Sampler::TraceIdRatioBased(
149150
r,
150151
))))
151152
} else {
152-
handle_error(
153-
Error::Other(String::from(
154-
"Missing or invalid OTEL_TRACES_SAMPLER_ARG value. Falling back to default: 1.0"
155-
)));
153+
otel_warn!(
154+
name: "TracerProvider.Config.InvalidSamplerArgument",
155+
message = "OTEL_TRACES_SAMPLER is set to 'parentbased_traceidratio' but OTEL_TRACES_SAMPLER_ARG environment variable is missing or invalid. OTEL_TRACES_SAMPLER_ARG must be a valid float between 0.0 and 1.0 representing the desired sampling probability (0.0 = no traces sampled, 1.0 = all traces sampled, 0.5 = 50% of traces sampled). Falling back to default ratio: 1.0 (100% sampling)",
156+
otel_traces_sampler_arg = format!("{:?}", sampler_arg)
157+
);
156158
Box::new(Sampler::ParentBased(Box::new(Sampler::TraceIdRatioBased(
157159
1.0,
158160
))))
159161
}
160162
}
161163
"parentbased_jaeger_remote" => {
162-
handle_error(
163-
Error::Other(String::from(
164-
"Unimplemented parentbased_jaeger_remote sampler. Falling back to default: parentbased_always_on"
165-
)));
164+
otel_warn!(
165+
name: "TracerProvider.Config.UnsupportedSampler",
166+
message = "OTEL_TRACES_SAMPLER is set to 'parentbased_jaeger_remote' which is not implemented in this SDK version. Using fallback sampler: ParentBased(AlwaysOn). Configure an alternative sampler using OTEL_TRACES_SAMPLER"
167+
);
166168
Box::new(Sampler::ParentBased(Box::new(Sampler::AlwaysOn)))
167169
}
168170
"jaeger_remote" => {
169-
handle_error(
170-
Error::Other(String::from("Unimplemented jaeger_remote sampler. Falling back to default: parentbased_always_on")));
171+
otel_warn!(
172+
name: "TracerProvider.Config.UnsupportedSampler",
173+
message = "OTEL_TRACES_SAMPLER is set to 'jaeger_remote' which is implemented in this SDK version. Using fallback sampler: ParentBased(AlwaysOn). Configure an alternative sampler using OTEL_TRACES_SAMPLER"
174+
);
171175
Box::new(Sampler::ParentBased(Box::new(Sampler::AlwaysOn)))
172176
}
173177
"xray" => {
174-
handle_error(
175-
Error::Other(String::from("Unimplemented xray sampler. Falling back to default: parentbased_always_on")));
178+
otel_warn!(
179+
name: "TracerProvider.Config.UnsupportedSampler",
180+
message = "OTEL_TRACES_SAMPLER is set to 'xray'. AWS X-Ray sampler is not implemented in this SDK version. Using fallback sampler: ParentBased(AlwaysOn). Configure an alternative sampler using OTEL_TRACES_SAMPLER"
181+
);
176182
Box::new(Sampler::ParentBased(Box::new(Sampler::AlwaysOn)))
177183
}
178184
s => {
179-
handle_error(
180-
Error::Other(format!("Unrecognised OTEL_TRACES_SAMPLER value: {}. Falling back to default: parentbased_always_on",
181-
s
182-
)));
185+
otel_warn!(
186+
name: "TracerProvider.Config.InvalidSamplerType",
187+
message = format!(
188+
"Unrecognized sampler type '{}' in OTEL_TRACES_SAMPLER environment variable. Valid values are: always_on, always_off, traceidratio, parentbased_always_on, parentbased_always_off, parentbased_traceidratio. Using fallback sampler: ParentBased(AlwaysOn)",
189+
s
190+
),
191+
);
183192
Box::new(Sampler::ParentBased(Box::new(Sampler::AlwaysOn)))
184193
}
185194
}

opentelemetry-sdk/src/trace/span_processor.rs

+27-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use futures_util::{
4545
stream::{self, FusedStream, FuturesUnordered},
4646
StreamExt as _,
4747
};
48-
use opentelemetry::global;
48+
use opentelemetry::{otel_debug, otel_error};
4949
use opentelemetry::{
5050
trace::{TraceError, TraceResult},
5151
Context,
@@ -134,7 +134,11 @@ impl SpanProcessor for SimpleSpanProcessor {
134134
.and_then(|mut exporter| futures_executor::block_on(exporter.export(vec![span])));
135135

136136
if let Err(err) = result {
137-
global::handle_error(err);
137+
// TODO: check error type, and log `error` only if the error is user-actiobable, else log `debug`
138+
otel_debug!(
139+
name: "SimpleProcessor.OnEnd.Error",
140+
reason = format!("{:?}", err)
141+
);
138142
}
139143
}
140144

@@ -246,7 +250,10 @@ impl<R: RuntimeChannel> SpanProcessor for BatchSpanProcessor<R> {
246250
let result = self.message_sender.try_send(BatchMessage::ExportSpan(span));
247251

248252
if let Err(err) = result {
249-
global::handle_error(TraceError::Other(err.into()));
253+
otel_debug!(
254+
name: "BatchSpanProcessor.OnEnd.ExportQueueingFailed",
255+
reason = format!("{:?}", TraceError::Other(err.into()))
256+
);
250257
}
251258
}
252259

@@ -313,14 +320,22 @@ impl<R: RuntimeChannel> BatchSpanProcessorInternal<R> {
313320
let result = export_task.await;
314321

315322
if let Some(channel) = res_channel {
323+
// If a response channel is provided, attempt to send the export result through it.
316324
if let Err(result) = channel.send(result) {
317-
global::handle_error(TraceError::from(format!(
318-
"failed to send flush result: {:?}",
319-
result
320-
)));
325+
otel_debug!(
326+
name: "BatchSpanProcessor.Flush.SendResultError",
327+
reason = format!("{:?}", result)
328+
);
321329
}
322330
} else if let Err(err) = result {
323-
global::handle_error(err);
331+
// If no channel is provided and the export operation encountered an error,
332+
// log the error directly here.
333+
// TODO: Consider returning the status instead of logging it.
334+
otel_error!(
335+
name: "BatchSpanProcessor.Flush.ExportError",
336+
reason = format!("{:?}", err),
337+
message = "Failed during the export process"
338+
);
324339
}
325340

326341
Ok(())
@@ -354,7 +369,10 @@ impl<R: RuntimeChannel> BatchSpanProcessorInternal<R> {
354369
let export_task = self.export();
355370
let task = async move {
356371
if let Err(err) = export_task.await {
357-
global::handle_error(err);
372+
otel_error!(
373+
name: "BatchSpanProcessor.Export.Error",
374+
reason = format!("{}", err)
375+
);
358376
}
359377

360378
Ok(())

0 commit comments

Comments
 (0)