Skip to content

Commit 866bae7

Browse files
refactor(appender-tracing): cleanup OpenTelemetryTracingBridge API
1 parent 453f7a1 commit 866bae7

2 files changed

Lines changed: 29 additions & 48 deletions

File tree

opentelemetry-appender-tracing/CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
## vNext
44

55
- Add custom `InstrumentationScope` support via
6-
`OpenTelemetryTracingBridge::with_scope()` and
76
`OpenTelemetryTracingBridge::builder_with_scope()`.
87
[3415](https://github.com/open-telemetry/opentelemetry-rust/issues/3415)
98

opentelemetry-appender-tracing/src/layer.rs

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -325,17 +325,12 @@ where
325325
/// Creates a bridge using the default OpenTelemetry logger scope.
326326
///
327327
/// The default scope uses an empty scope name for the appender logger.
328-
/// Use [`Self::with_scope`] or [`Self::builder_with_scope`] to provide a
328+
/// Use [`Self::builder_with_scope`] to provide a
329329
/// custom [`InstrumentationScope`].
330330
pub fn new(provider: &P) -> Self {
331331
Self::builder(provider).build()
332332
}
333333

334-
/// Creates the bridge with a custom OpenTelemetry [`InstrumentationScope`].
335-
pub fn with_scope(provider: &P, scope: InstrumentationScope) -> Self {
336-
Self::builder_with_scope(provider, scope).build()
337-
}
338-
339334
/// Creates a builder using the default OpenTelemetry logger scope.
340335
pub fn builder(provider: &P) -> OpenTelemetryTracingBridgeBuilder<P, L> {
341336
OpenTelemetryTracingBridgeBuilder {
@@ -868,48 +863,35 @@ mod tests {
868863
.with_schema_url("https://opentelemetry.io/schemas/1.0.0")
869864
.with_attributes([KeyValue::new("scope-key", "scope-value")])
870865
.build();
871-
let subscribers = [
872-
tracing_subscriber::registry().with(
873-
layer::OpenTelemetryTracingBridge::builder_with_scope(
874-
&logger_provider,
875-
scope.clone(),
876-
)
866+
let subscriber = tracing_subscriber::registry().with(
867+
layer::OpenTelemetryTracingBridge::builder_with_scope(&logger_provider, scope.clone())
877868
.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-
}
869+
);
870+
871+
let _guard = tracing::subscriber::set_default(subscriber);
872+
873+
error!(name: "scoped-event", target: "my-system", event_id = 20);
874+
assert!(logger_provider.force_flush().is_ok());
875+
876+
let exported_logs = exporter
877+
.get_emitted_logs()
878+
.expect("Logs are expected to be exported.");
879+
assert_eq!(exported_logs.len(), 1);
880+
let log = exported_logs
881+
.first()
882+
.expect("At least one log is expected to be present.");
883+
884+
let instrumentation_scope = &log.instrumentation;
885+
assert_eq!(instrumentation_scope.name(), "test.scope");
886+
assert_eq!(instrumentation_scope.version(), Some("1.2.3"));
887+
assert_eq!(
888+
instrumentation_scope.schema_url(),
889+
Some("https://opentelemetry.io/schemas/1.0.0")
890+
);
891+
assert!(instrumentation_scope
892+
.attributes()
893+
.eq([KeyValue::new("scope-key", "scope-value")].iter()));
894+
exporter.reset();
913895
}
914896

915897
#[test]

0 commit comments

Comments
 (0)