Skip to content

Commit 7376cd1

Browse files
authored
fix setting resource on custom log processor (#79)
1 parent 6c11cd8 commit 7376cd1

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

src/config.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,12 @@ impl MetricReader for BoxedMetricReader {
405405

406406
/// Boxed log processor for dynamic dispatch
407407
#[derive(Debug)]
408-
pub(crate) struct BoxedLogProcessor {
409-
inner: Box<dyn LogProcessor + Send + Sync>,
410-
}
408+
pub(crate) struct BoxedLogProcessor(Box<dyn LogProcessor + Send + Sync>);
411409

412410
impl BoxedLogProcessor {
413411
/// Create a new boxed log processor.
414412
pub fn new(processor: Box<dyn LogProcessor + Send + Sync>) -> Self {
415-
Self { inner: processor }
413+
Self(processor)
416414
}
417415
}
418416

@@ -422,15 +420,26 @@ impl LogProcessor for BoxedLogProcessor {
422420
log_record: &mut opentelemetry_sdk::logs::SdkLogRecord,
423421
instrumentation_scope: &opentelemetry::InstrumentationScope,
424422
) {
425-
self.inner.emit(log_record, instrumentation_scope);
423+
self.0.emit(log_record, instrumentation_scope);
426424
}
427425

428426
fn force_flush(&self) -> opentelemetry_sdk::error::OTelSdkResult {
429-
self.inner.force_flush()
427+
self.0.force_flush()
428+
}
429+
430+
fn shutdown_with_timeout(
431+
&self,
432+
timeout: std::time::Duration,
433+
) -> opentelemetry_sdk::error::OTelSdkResult {
434+
self.0.shutdown_with_timeout(timeout)
430435
}
431436

432437
fn shutdown(&self) -> opentelemetry_sdk::error::OTelSdkResult {
433-
self.inner.shutdown()
438+
self.0.shutdown()
439+
}
440+
441+
fn set_resource(&mut self, resource: &opentelemetry_sdk::Resource) {
442+
self.0.set_resource(resource);
434443
}
435444
}
436445

tests/test_basic_exports.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::sync::Arc;
44

55
use insta::assert_debug_snapshot;
6+
use opentelemetry::KeyValue;
67
use opentelemetry_sdk::{
78
Resource,
89
logs::{InMemoryLogExporter, SimpleLogProcessor},
@@ -49,7 +50,12 @@ fn test_basic_span() {
4950
.with_advanced_options(
5051
AdvancedOptions::default()
5152
.with_id_generator(DeterministicIdGenerator::new())
52-
.with_log_processor(SimpleLogProcessor::new(log_exporter.clone())),
53+
.with_log_processor(SimpleLogProcessor::new(log_exporter.clone()))
54+
.with_resource(
55+
Resource::builder_empty()
56+
.with_attribute(KeyValue::new("resource.key", "value"))
57+
.build(),
58+
),
5359
)
5460
.finish()
5561
.unwrap();
@@ -120,7 +126,7 @@ fn test_basic_span() {
120126
"code.lineno",
121127
),
122128
value: I64(
123-
27,
129+
32,
124130
),
125131
},
126132
KeyValue {
@@ -246,7 +252,7 @@ fn test_basic_span() {
246252
"code.lineno",
247253
),
248254
value: I64(
249-
28,
255+
33,
250256
),
251257
},
252258
KeyValue {
@@ -402,7 +408,7 @@ fn test_basic_span() {
402408
"code.lineno",
403409
),
404410
value: I64(
405-
28,
411+
33,
406412
),
407413
},
408414
KeyValue {
@@ -564,7 +570,7 @@ fn test_basic_span() {
564570
"code.lineno",
565571
),
566572
value: I64(
567-
29,
573+
34,
568574
),
569575
},
570576
KeyValue {
@@ -700,7 +706,7 @@ fn test_basic_span() {
700706
"code.lineno",
701707
),
702708
value: I64(
703-
29,
709+
34,
704710
),
705711
},
706712
KeyValue {
@@ -842,7 +848,7 @@ fn test_basic_span() {
842848
"code.lineno",
843849
),
844850
value: I64(
845-
30,
851+
35,
846852
),
847853
},
848854
KeyValue {
@@ -978,7 +984,7 @@ fn test_basic_span() {
978984
"code.lineno",
979985
),
980986
value: I64(
981-
30,
987+
35,
982988
),
983989
},
984990
KeyValue {
@@ -1120,7 +1126,7 @@ fn test_basic_span() {
11201126
"code.lineno",
11211127
),
11221128
value: I64(
1123-
27,
1129+
32,
11241130
),
11251131
},
11261132
KeyValue {
@@ -1292,7 +1298,7 @@ fn test_basic_span() {
12921298
"code.lineno",
12931299
),
12941300
Int(
1295-
31,
1301+
36,
12961302
),
12971303
),
12981304
),
@@ -1459,7 +1465,7 @@ fn test_basic_span() {
14591465
"code.lineno",
14601466
),
14611467
Int(
1462-
32,
1468+
37,
14631469
),
14641470
),
14651471
),

0 commit comments

Comments
 (0)