Skip to content

Commit 04f4631

Browse files
davidbarskyhawkw
andauthoredOct 22, 2020
core: rename Subscriber to Collect (#1015)
This PR renames the following: - `tracing_core::Subscriber` to `tracing_core::Collect` - `tracing_subscriber::layer::Layer` to `tracing_subscriber::layer::Subscribe` Authored-by: David Barsksy <[email protected]> Co-authored-by: Eliza Weisman <[email protected]>
1 parent fa4d7ac commit 04f4631

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed
 

‎tracing-opentelemetry/src/layer.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use std::fmt;
55
use std::marker;
66
use std::time::SystemTime;
77
use tracing_core::span::{self, Attributes, Id, Record};
8-
use tracing_core::{field, Event, Subscriber};
8+
use tracing_core::{field, Collect, Event};
99
#[cfg(feature = "tracing-log")]
1010
use tracing_log::NormalizeEvent;
11-
use tracing_subscriber::layer::Context;
1211
use tracing_subscriber::registry::LookupSpan;
13-
use tracing_subscriber::Layer;
12+
use tracing_subscriber::subscribe::Context;
13+
use tracing_subscriber::Subscribe;
1414

1515
static SPAN_NAME_FIELD: &str = "otel.name";
1616
static SPAN_KIND_FIELD: &str = "otel.kind";
@@ -29,7 +29,7 @@ pub struct OpenTelemetryLayer<S, T> {
2929

3030
impl<S> Default for OpenTelemetryLayer<S, api::NoopTracer>
3131
where
32-
S: Subscriber + for<'span> LookupSpan<'span>,
32+
S: Collect + for<'span> LookupSpan<'span>,
3333
{
3434
fn default() -> Self {
3535
OpenTelemetryLayer::new(api::NoopTracer {})
@@ -43,7 +43,7 @@ where
4343
/// # Examples
4444
///
4545
/// ```rust,no_run
46-
/// use tracing_subscriber::layer::SubscriberExt;
46+
/// use tracing_subscriber::subscribe::CollectorExt;
4747
/// use tracing_subscriber::Registry;
4848
///
4949
/// // Use the tracing subscriber `Registry`, or any other subscriber
@@ -53,7 +53,7 @@ where
5353
/// ```
5454
pub fn layer<S>() -> OpenTelemetryLayer<S, api::NoopTracer>
5555
where
56-
S: Subscriber + for<'span> LookupSpan<'span>,
56+
S: Collect + for<'span> LookupSpan<'span>,
5757
{
5858
OpenTelemetryLayer::default()
5959
}
@@ -261,7 +261,7 @@ impl<'a> field::Visit for SpanAttributeVisitor<'a> {
261261

262262
impl<S, T> OpenTelemetryLayer<S, T>
263263
where
264-
S: Subscriber + for<'span> LookupSpan<'span>,
264+
S: Collect + for<'span> LookupSpan<'span>,
265265
T: api::Tracer + PreSampledTracer + 'static,
266266
{
267267
/// Set the [`Tracer`] that this layer will use to produce and track
@@ -275,7 +275,7 @@ where
275275
/// ```rust,no_run
276276
/// use opentelemetry::{api::Provider, sdk};
277277
/// use tracing_opentelemetry::OpenTelemetryLayer;
278-
/// use tracing_subscriber::layer::SubscriberExt;
278+
/// use tracing_subscriber::subscribe::CollectorExt;
279279
/// use tracing_subscriber::Registry;
280280
///
281281
/// // Create a jaeger exporter for a `trace-demo` service.
@@ -325,7 +325,7 @@ where
325325
///
326326
/// ```rust,no_run
327327
/// use opentelemetry::{api::Provider, sdk};
328-
/// use tracing_subscriber::layer::SubscriberExt;
328+
/// use tracing_subscriber::subscribe::CollectorExt;
329329
/// use tracing_subscriber::Registry;
330330
///
331331
/// // Create a jaeger exporter for a `trace-demo` service.
@@ -424,9 +424,9 @@ where
424424
}
425425
}
426426

427-
impl<S, T> Layer<S> for OpenTelemetryLayer<S, T>
427+
impl<S, T> Subscribe<S> for OpenTelemetryLayer<S, T>
428428
where
429-
S: Subscriber + for<'span> LookupSpan<'span>,
429+
S: Collect + for<'span> LookupSpan<'span>,
430430
T: api::Tracer + PreSampledTracer + 'static,
431431
{
432432
/// Creates an [OpenTelemetry `Span`] for the corresponding [tracing `Span`].
@@ -627,7 +627,7 @@ mod tests {
627627
let tracer = TestTracer(Arc::new(Mutex::new(None)));
628628
let subscriber = tracing_subscriber::registry().with(layer().with_tracer(tracer.clone()));
629629

630-
tracing::subscriber::with_default(subscriber, || {
630+
tracing::collect::with_default(subscriber, || {
631631
tracing::debug_span!("static_name", otel.name = dynamic_name.as_str());
632632
});
633633

@@ -640,7 +640,7 @@ mod tests {
640640
let tracer = TestTracer(Arc::new(Mutex::new(None)));
641641
let subscriber = tracing_subscriber::registry().with(layer().with_tracer(tracer.clone()));
642642

643-
tracing::subscriber::with_default(subscriber, || {
643+
tracing::collect::with_default(subscriber, || {
644644
tracing::debug_span!("request", otel.kind = "Server");
645645
});
646646

@@ -661,7 +661,7 @@ mod tests {
661661
)));
662662
let _g = existing_cx.attach();
663663

664-
tracing::subscriber::with_default(subscriber, || {
664+
tracing::collect::with_default(subscriber, || {
665665
tracing::debug_span!("request", otel.kind = "Server");
666666
});
667667

‎tracing-opentelemetry/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
//! ```
5454
//! use opentelemetry::{api::Provider, sdk};
5555
//! use tracing::{error, span};
56-
//! use tracing_subscriber::layer::SubscriberExt;
56+
//! use tracing_subscriber::subscribe::CollectorExt;
5757
//! use tracing_subscriber::Registry;
5858
//!
5959
//! // Create a new tracer
@@ -65,7 +65,7 @@
6565
//! let subscriber = Registry::default().with(telemetry);
6666
//!
6767
//! // Trace executed code
68-
//! tracing::subscriber::with_default(subscriber, || {
68+
//! tracing::collect::with_default(subscriber, || {
6969
//! // Spans will be sent to the configured OpenTelemetry exporter
7070
//! let root = span!(tracing::Level::TRACE, "app_start", work_units = 2);
7171
//! let _enter = root.enter();
@@ -98,7 +98,7 @@
9898
)]
9999
#![cfg_attr(docsrs, deny(broken_intra_doc_links))]
100100

101-
/// Implementation of the trace::Layer as a source of OpenTelemetry data.
101+
/// Implementation of the trace::Subscriber as a source of OpenTelemetry data.
102102
mod layer;
103103
/// Span extension which enables OpenTelemetry context management.
104104
mod span_ext;

‎tracing-opentelemetry/src/span_ext.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ pub trait OpenTelemetrySpanExt {
7474

7575
impl OpenTelemetrySpanExt for tracing::Span {
7676
fn set_parent(&self, parent_context: &api::Context) {
77-
self.with_subscriber(move |(id, subscriber)| {
78-
if let Some(get_context) = subscriber.downcast_ref::<WithContext>() {
79-
get_context.with_context(subscriber, id, move |builder, _tracer| {
77+
self.with_collector(move |(id, collector)| {
78+
if let Some(get_context) = collector.downcast_ref::<WithContext>() {
79+
get_context.with_context(collector, id, move |builder, _tracer| {
8080
builder.parent_context = parent_context.remote_span_context().cloned()
8181
});
8282
}
@@ -85,9 +85,9 @@ impl OpenTelemetrySpanExt for tracing::Span {
8585

8686
fn context(&self) -> api::Context {
8787
let mut span_context = None;
88-
self.with_subscriber(|(id, subscriber)| {
89-
if let Some(get_context) = subscriber.downcast_ref::<WithContext>() {
90-
get_context.with_context(subscriber, id, |builder, tracer| {
88+
self.with_collector(|(id, collector)| {
89+
if let Some(get_context) = collector.downcast_ref::<WithContext>() {
90+
get_context.with_context(collector, id, |builder, tracer| {
9191
span_context = Some(tracer.sampled_span_context(builder));
9292
})
9393
}

0 commit comments

Comments
 (0)
Please sign in to comment.