Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@

- Add `Event` type to represent single points in time during the span's lifetime.
- Add `fastrace-opentelementry` reporter that reports spans to OpenTelemetry collector.
- Removed `Collector` and raplaced it with `Reporter`.
- Removed `Collector` and replaced it with `Reporter`.
- The macro arguments must be named if any, e.g. `#[trace(name="name")]`.
- Allow to statically opt-out of tracing by not setting `enable` feature.

Expand Down
50 changes: 31 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ fastrace-opentelemetry = { path = "fastrace-opentelemetry" }

# crates.io dependencies
log = { version = "0.4.27" }
opentelemetry = { version = "0.30.0", default-features = false, features = [
opentelemetry = { version = "0.31.0", default-features = false, features = [
"trace",
] }
opentelemetry-otlp = { version = "0.30.0", default-features = false, features = [
opentelemetry-otlp = { version = "0.31.0", default-features = false, features = [
"trace",
"grpc-tonic",
] }
opentelemetry_sdk = { version = "0.30.0", default-features = false, features = [
opentelemetry_sdk = { version = "0.31.0", default-features = false, features = [
"trace",
] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
2 changes: 2 additions & 0 deletions fastrace-opentelemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl OpenTelemetryReporter {
trace_id,
span_id,
parent_id,
parent_is_remote,
begin_time_unix_ns,
duration_ns,
name,
Expand All @@ -157,6 +158,7 @@ impl OpenTelemetryReporter {
SpanData {
span_context,
parent_span_id,
parent_span_is_remote: parent_is_remote,
span_kind,
name,
start_time,
Expand Down
2 changes: 1 addition & 1 deletion fastrace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ rand = "0.9"
serial_test = "3.1"
tokio = { workspace = true }
tracing = { version = "0.1" }
tracing-opentelemetry = { version = "0.31.0" }
tracing-opentelemetry = "0.32.0"
tracing-subscriber = { version = "0.3.19" }

[[bench]]
Expand Down
26 changes: 26 additions & 0 deletions fastrace/src/collector/global_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,13 @@ enum SpanCollection {
spans: SpanSet,
trace_id: TraceId,
parent_id: SpanId,
parent_is_remote: bool,
},
Shared {
spans: Arc<SpanSet>,
trace_id: TraceId,
parent_id: SpanId,
parent_is_remote: bool,
},
}

Expand Down Expand Up @@ -347,12 +349,14 @@ impl GlobalCollector {
spans,
trace_id: item.trace_id,
parent_id: item.parent_id,
parent_is_remote: item.parent_is_remote,
});
} else if !self.config.tail_sampled {
stale_spans.push(SpanCollection::Owned {
spans,
trace_id: item.trace_id,
parent_id: item.parent_id,
parent_is_remote: item.parent_is_remote,
});
}
} else {
Expand All @@ -366,12 +370,14 @@ impl GlobalCollector {
spans: spans.clone(),
trace_id: item.trace_id,
parent_id: item.parent_id,
parent_is_remote: item.parent_is_remote,
});
} else if !self.config.tail_sampled {
stale_spans.push(SpanCollection::Shared {
spans: spans.clone(),
trace_id: item.trace_id,
parent_id: item.parent_id,
parent_is_remote: item.parent_is_remote,
});
}
}
Expand Down Expand Up @@ -430,6 +436,7 @@ impl LocalSpansInner {
self,
parent.trace_id,
parent.span_id,
parent.is_remote,
&mut records,
&mut danglings,
&anchor,
Expand Down Expand Up @@ -458,11 +465,13 @@ fn postprocess_span_collection<'a>(
spans,
trace_id,
parent_id,
parent_is_remote,
} => match spans {
SpanSet::Span(raw_span) => amend_span(
raw_span,
*trace_id,
*parent_id,
*parent_is_remote,
committed_records,
danglings,
anchor,
Expand All @@ -471,6 +480,7 @@ fn postprocess_span_collection<'a>(
local_spans,
*trace_id,
*parent_id,
*parent_is_remote,
committed_records,
danglings,
anchor,
Expand All @@ -479,6 +489,7 @@ fn postprocess_span_collection<'a>(
local_spans,
*trace_id,
*parent_id,
*parent_is_remote,
committed_records,
danglings,
anchor,
Expand All @@ -488,11 +499,13 @@ fn postprocess_span_collection<'a>(
spans,
trace_id,
parent_id,
parent_is_remote,
} => match &**spans {
SpanSet::Span(raw_span) => amend_span(
raw_span,
*trace_id,
*parent_id,
*parent_is_remote,
committed_records,
danglings,
anchor,
Expand All @@ -501,6 +514,7 @@ fn postprocess_span_collection<'a>(
local_spans,
*trace_id,
*parent_id,
*parent_is_remote,
committed_records,
danglings,
anchor,
Expand All @@ -509,6 +523,7 @@ fn postprocess_span_collection<'a>(
local_spans,
*trace_id,
*parent_id,
*parent_is_remote,
committed_records,
danglings,
anchor,
Expand All @@ -524,12 +539,20 @@ fn amend_local_span(
local_spans: &LocalSpansInner,
trace_id: TraceId,
parent_id: SpanId,
parent_is_remote: bool,
spans: &mut Vec<SpanRecord>,
dangling: &mut HashMap<SpanId, Vec<DanglingItem>>,
anchor: &Anchor,
) {
for span in local_spans.spans.iter() {
let parent_id = span.parent_id.unwrap_or(parent_id);

let span_parent_is_remote = if span.parent_id.is_none() {
parent_is_remote
} else {
false // Child spans always have local parents
};

match span.raw_kind {
RawKind::Span => {
let begin_time_unix_ns = span.begin_instant.as_unix_nanos(anchor);
Expand All @@ -542,6 +565,7 @@ fn amend_local_span(
trace_id,
span_id: span.id,
parent_id,
parent_is_remote: span_parent_is_remote,
begin_time_unix_ns,
duration_ns: end_time_unix_ns.saturating_sub(begin_time_unix_ns),
name: span.name.clone(),
Expand Down Expand Up @@ -588,6 +612,7 @@ fn amend_span(
span: &RawSpan,
trace_id: TraceId,
parent_id: SpanId,
parent_is_remote: bool,
spans: &mut Vec<SpanRecord>,
dangling: &mut HashMap<SpanId, Vec<DanglingItem>>,
anchor: &Anchor,
Expand All @@ -600,6 +625,7 @@ fn amend_span(
trace_id,
span_id: span.id,
parent_id,
parent_is_remote,
begin_time_unix_ns,
duration_ns: end_time_unix_ns.saturating_sub(begin_time_unix_ns),
name: span.name.clone(),
Expand Down
Loading
Loading