Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tracing-opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ default = ["tracing-log"]

[dependencies]
opentelemetry = { version = "0.17", default-features = false, features = ["trace"] }
tracing = { path = "../tracing", version = "0.1", default-features = false, features = ["std"] }
tracing-core = { path = "../tracing-core", version = "0.1" }
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3", default-features = false, features = ["registry", "std"] }
tracing-log = { path = "../tracing-log", version = "0.1", default-features = false, optional = true }
tracing = { version = "0.1.36", default-features = false, features = ["std"] }
tracing-core = { version = "0.1.28" }
tracing-subscriber = { version = "0.3.14", default-features = false, features = ["registry", "std"] }
tracing-log = { version = "0.1.3", default-features = false, optional = true }
once_cell = "1"

[dev-dependencies]
Expand Down
10 changes: 6 additions & 4 deletions tracing-opentelemetry/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,10 +916,12 @@ where
}
}

// Assign end time, build and start span, drop span to export
builder
.with_end_time(SystemTime::now())
.start_with_context(&self.tracer, &parent_cx);
if builder.end_time.is_none() {
// Assign end time
builder = builder.with_end_time(SystemTime::now());
}
// Build and start span, drop span to export
builder.start_with_context(&self.tracer, &parent_cx);
}
}

Expand Down
23 changes: 23 additions & 0 deletions tracing-opentelemetry/src/span_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ pub trait OpenTelemetrySpanExt {
/// make_request(Span::current().context())
/// ```
fn context(&self) -> Context;

fn set_start_time(&self, start_time: std::time::SystemTime);
fn set_end_time(&self, end_time: std::time::SystemTime);
}

impl OpenTelemetrySpanExt for tracing::Span {
Expand Down Expand Up @@ -167,4 +170,24 @@ impl OpenTelemetrySpanExt for tracing::Span {

cx.unwrap_or_default()
}

fn set_start_time(&self, start_time: std::time::SystemTime) {
self.with_subscriber(|(id, subscriber)| {
if let Some(get_context) = subscriber.downcast_ref::<WithContext>() {
get_context.with_context(subscriber, id, |otel_data, _tracer| {
otel_data.builder.start_time = Some(start_time);
})
}
});
}

fn set_end_time(&self, end_time: std::time::SystemTime) {
self.with_subscriber(|(id, subscriber)| {
if let Some(get_context) = subscriber.downcast_ref::<WithContext>() {
get_context.with_context(subscriber, id, |otel_data, _tracer| {
otel_data.builder.end_time = Some(end_time);
})
}
});
}
}