Skip to content

Commit b35c0d6

Browse files
authored
Feat/remove timeout from detectors (#2332)
1 parent 506a4f9 commit b35c0d6

File tree

5 files changed

+27
-37
lines changed

5 files changed

+27
-37
lines changed

opentelemetry-sdk/CHANGELOG.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
## vNext
44

5-
- *Breaking* SimpleLogProcessor modified to be generic over `LogExporter` to
6-
avoid dynamic dispatch to invoke exporter. If you were using
7-
`with_simple_exporter` to add `LogExporter` with SimpleLogProcessor, this is a
8-
transparent change.
9-
[#2338](https://github.com/open-telemetry/opentelemetry-rust/pull/2338)
5+
- *Breaking*
6+
- SimpleLogProcessor modified to be generic over `LogExporter` to
7+
avoid dynamic dispatch to invoke exporter. If you were using
8+
`with_simple_exporter` to add `LogExporter` with SimpleLogProcessor, this is a
9+
transparent change.
10+
[#2338](https://github.com/open-telemetry/opentelemetry-rust/pull/2338)
11+
- `ResourceDetector.detect()` no longer supports timeout option.
1012

1113
## 0.27.1
1214

opentelemetry-sdk/src/resource/env.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use crate::resource::{Resource, ResourceDetector};
66
use opentelemetry::{Key, KeyValue, Value};
77
use std::env;
8-
use std::time::Duration;
98

109
const OTEL_RESOURCE_ATTRIBUTES: &str = "OTEL_RESOURCE_ATTRIBUTES";
1110
const OTEL_SERVICE_NAME: &str = "OTEL_SERVICE_NAME";
@@ -20,7 +19,7 @@ pub struct EnvResourceDetector {
2019
}
2120

2221
impl ResourceDetector for EnvResourceDetector {
23-
fn detect(&self, _timeout: Duration) -> Resource {
22+
fn detect(&self) -> Resource {
2423
match env::var(OTEL_RESOURCE_ATTRIBUTES) {
2524
Ok(s) if !s.is_empty() => construct_otel_resources(s),
2625
Ok(_) | Err(_) => Resource::new(vec![]), // return empty resource
@@ -72,7 +71,7 @@ fn construct_otel_resources(s: String) -> Resource {
7271
pub struct SdkProvidedResourceDetector;
7372

7473
impl ResourceDetector for SdkProvidedResourceDetector {
75-
fn detect(&self, _timeout: Duration) -> Resource {
74+
fn detect(&self) -> Resource {
7675
Resource::new(vec![KeyValue::new(
7776
super::SERVICE_NAME,
7877
env::var(OTEL_SERVICE_NAME)
@@ -81,7 +80,7 @@ impl ResourceDetector for SdkProvidedResourceDetector {
8180
.map(Value::from)
8281
.or_else(|| {
8382
EnvResourceDetector::new()
84-
.detect(Duration::from_secs(0))
83+
.detect()
8584
.get(Key::new(super::SERVICE_NAME))
8685
})
8786
.unwrap_or_else(|| "unknown_service".into()),
@@ -96,7 +95,6 @@ mod tests {
9695
};
9796
use crate::resource::{EnvResourceDetector, Resource, ResourceDetector};
9897
use opentelemetry::{Key, KeyValue, Value};
99-
use std::time::Duration;
10098

10199
#[test]
102100
fn test_read_from_env() {
@@ -110,7 +108,7 @@ mod tests {
110108
],
111109
|| {
112110
let detector = EnvResourceDetector::new();
113-
let resource = detector.detect(Duration::from_secs(5));
111+
let resource = detector.detect();
114112
assert_eq!(
115113
resource,
116114
Resource::new(vec![
@@ -124,21 +122,21 @@ mod tests {
124122
);
125123

126124
let detector = EnvResourceDetector::new();
127-
let resource = detector.detect(Duration::from_secs(5));
125+
let resource = detector.detect();
128126
assert!(resource.is_empty());
129127
}
130128

131129
#[test]
132130
fn test_sdk_provided_resource_detector() {
133131
// Ensure no env var set
134-
let no_env = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
132+
let no_env = SdkProvidedResourceDetector.detect();
135133
assert_eq!(
136134
no_env.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
137135
Some(Value::from("unknown_service")),
138136
);
139137

140138
temp_env::with_var(OTEL_SERVICE_NAME, Some("test service"), || {
141-
let with_service = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
139+
let with_service = SdkProvidedResourceDetector.detect();
142140
assert_eq!(
143141
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
144142
Some(Value::from("test service")),
@@ -149,7 +147,7 @@ mod tests {
149147
OTEL_RESOURCE_ATTRIBUTES,
150148
Some("service.name=test service1"),
151149
|| {
152-
let with_service = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
150+
let with_service = SdkProvidedResourceDetector.detect();
153151
assert_eq!(
154152
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
155153
Some(Value::from("test service1")),
@@ -164,7 +162,7 @@ mod tests {
164162
(OTEL_RESOURCE_ATTRIBUTES, Some("service.name=test service3")),
165163
],
166164
|| {
167-
let with_service = SdkProvidedResourceDetector.detect(Duration::from_secs(1));
165+
let with_service = SdkProvidedResourceDetector.detect();
168166
assert_eq!(
169167
with_service.get(Key::from_static_str(crate::resource::SERVICE_NAME)),
170168
Some(Value::from("test service"))

opentelemetry-sdk/src/resource/mod.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use std::borrow::Cow;
3535
use std::collections::{hash_map, HashMap};
3636
use std::ops::Deref;
3737
use std::sync::Arc;
38-
use std::time::Duration;
3938

4039
/// Inner structure of `Resource` holding the actual data.
4140
/// This structure is designed to be shared among `Resource` instances via `Arc`.
@@ -54,14 +53,11 @@ pub struct Resource {
5453

5554
impl Default for Resource {
5655
fn default() -> Self {
57-
Self::from_detectors(
58-
Duration::from_secs(0),
59-
vec![
60-
Box::new(SdkProvidedResourceDetector),
61-
Box::new(TelemetryResourceDetector),
62-
Box::new(EnvResourceDetector::new()),
63-
],
64-
)
56+
Self::from_detectors(vec![
57+
Box::new(SdkProvidedResourceDetector),
58+
Box::new(TelemetryResourceDetector),
59+
Box::new(EnvResourceDetector::new()),
60+
])
6561
}
6662
}
6763

@@ -137,10 +133,10 @@ impl Resource {
137133
/// Create a new `Resource` from resource detectors.
138134
///
139135
/// timeout will be applied to each detector.
140-
pub fn from_detectors(timeout: Duration, detectors: Vec<Box<dyn ResourceDetector>>) -> Self {
136+
pub fn from_detectors(detectors: Vec<Box<dyn ResourceDetector>>) -> Self {
141137
let mut resource = Resource::empty();
142138
for detector in detectors {
143-
let detected_res = detector.detect(timeout);
139+
let detected_res = detector.detect();
144140
// This call ensures that if the Arc is not uniquely owned,
145141
// the data is cloned before modification, preserving safety.
146142
// If the Arc is uniquely owned, it simply returns a mutable reference to the data.
@@ -262,13 +258,12 @@ pub trait ResourceDetector {
262258
///
263259
/// If source information to construct a Resource is invalid, for example,
264260
/// missing required values. an empty Resource should be returned.
265-
fn detect(&self, timeout: Duration) -> Resource;
261+
fn detect(&self) -> Resource;
266262
}
267263

268264
#[cfg(test)]
269265
mod tests {
270266
use super::*;
271-
use std::time;
272267

273268
#[test]
274269
fn new_resource() {
@@ -368,10 +363,7 @@ mod tests {
368363
],
369364
|| {
370365
let detector = EnvResourceDetector::new();
371-
let resource = Resource::from_detectors(
372-
time::Duration::from_secs(5),
373-
vec![Box::new(detector)],
374-
);
366+
let resource = Resource::from_detectors(vec![Box::new(detector)]);
375367
assert_eq!(
376368
resource,
377369
Resource::new(vec![

opentelemetry-sdk/src/resource/telemetry.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::resource::ResourceDetector;
22
use crate::Resource;
33
use opentelemetry::KeyValue;
4-
use std::time::Duration;
54

65
/// Detect the telemetry SDK information used to capture data recorded by the instrumentation libraries.
76
///
@@ -16,7 +15,7 @@ use std::time::Duration;
1615
pub struct TelemetryResourceDetector;
1716

1817
impl ResourceDetector for TelemetryResourceDetector {
19-
fn detect(&self, _timeout: Duration) -> Resource {
18+
fn detect(&self) -> Resource {
2019
Resource::new(vec![
2120
KeyValue::new(super::TELEMETRY_SDK_NAME, "opentelemetry"),
2221
KeyValue::new(super::TELEMETRY_SDK_LANGUAGE, "rust"),

opentelemetry-zipkin/src/exporter/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use opentelemetry_semantic_conventions as semcov;
1919
use std::borrow::Cow;
2020
use std::net::SocketAddr;
2121
use std::sync::Arc;
22-
use std::time::Duration;
2322

2423
/// Zipkin span exporter
2524
#[derive(Debug)]
@@ -112,7 +111,7 @@ impl ZipkinPipelineBuilder {
112111
(config, Endpoint::new(service_name, self.service_addr))
113112
} else {
114113
let service_name = SdkProvidedResourceDetector
115-
.detect(Duration::from_secs(0))
114+
.detect()
116115
.get(semcov::resource::SERVICE_NAME.into())
117116
.unwrap()
118117
.to_string();

0 commit comments

Comments
 (0)