Skip to content

Commit 1bef051

Browse files
test(appender-tracing): cover both with_scope and builder_with_scope paths
1 parent e741241 commit 1bef051

1 file changed

Lines changed: 42 additions & 27 deletions

File tree

  • opentelemetry-appender-tracing/src

opentelemetry-appender-tracing/src/layer.rs

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -868,33 +868,48 @@ mod tests {
868868
.with_schema_url("https://opentelemetry.io/schemas/1.0.0")
869869
.with_attributes([KeyValue::new("scope-key", "scope-value")])
870870
.build();
871-
872-
let subscriber = tracing_subscriber::registry().with(
873-
layer::OpenTelemetryTracingBridge::builder_with_scope(&logger_provider, scope).build(),
874-
);
875-
let _guard = tracing::subscriber::set_default(subscriber);
876-
877-
error!(name: "scoped-event", target: "my-system", event_id = 20);
878-
assert!(logger_provider.force_flush().is_ok());
879-
880-
let exported_logs = exporter
881-
.get_emitted_logs()
882-
.expect("Logs are expected to be exported.");
883-
assert_eq!(exported_logs.len(), 1);
884-
let log = exported_logs
885-
.first()
886-
.expect("At least one log is expected to be present.");
887-
888-
let instrumentation_scope = &log.instrumentation;
889-
assert_eq!(instrumentation_scope.name(), "test.scope");
890-
assert_eq!(instrumentation_scope.version(), Some("1.2.3"));
891-
assert_eq!(
892-
instrumentation_scope.schema_url(),
893-
Some("https://opentelemetry.io/schemas/1.0.0")
894-
);
895-
assert!(instrumentation_scope
896-
.attributes()
897-
.eq([KeyValue::new("scope-key", "scope-value")].iter()));
871+
let subscribers = [
872+
tracing_subscriber::registry().with(
873+
layer::OpenTelemetryTracingBridge::builder_with_scope(
874+
&logger_provider,
875+
scope.clone(),
876+
)
877+
.build(),
878+
),
879+
tracing_subscriber::registry().with(layer::OpenTelemetryTracingBridge::with_scope(
880+
&logger_provider,
881+
scope,
882+
)),
883+
];
884+
885+
for subscriber in subscribers {
886+
let _guard = tracing::subscriber::set_default(subscriber);
887+
888+
error!(name: "scoped-event", target: "my-system", event_id = 20);
889+
assert!(logger_provider.force_flush().is_ok());
890+
891+
let exported_logs = exporter
892+
.get_emitted_logs()
893+
.expect("Logs are expected to be exported.");
894+
assert_eq!(exported_logs.len(), 1);
895+
let log = exported_logs
896+
.first()
897+
.expect("At least one log is expected to be present.");
898+
899+
let instrumentation_scope = &log.instrumentation;
900+
assert_eq!(instrumentation_scope.name(), "test.scope");
901+
assert_eq!(instrumentation_scope.version(), Some("1.2.3"));
902+
assert_eq!(
903+
instrumentation_scope.schema_url(),
904+
Some("https://opentelemetry.io/schemas/1.0.0")
905+
);
906+
assert!(instrumentation_scope.attributes().eq([KeyValue::new(
907+
"scope-key",
908+
"scope-value"
909+
)]
910+
.iter()));
911+
exporter.reset();
912+
}
898913
}
899914

900915
#[test]

0 commit comments

Comments
 (0)