Repository navigation
feat(telemetry): request-scoped spans on ingest, query, mcp, sweep (RFC 0038 slice 2) #615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b3d1ff3
feat(telemetry): open request-scoped spans on ingest, query, mcp, swe…
jensholdgaard febb436
fix(telemetry): strip tracing's synthetic span attributes for semconv…
jensholdgaard aa46359
fix(mcp): move tool spans to private delegates so descriptions survive
jensholdgaard 327332a
test(telemetry): assert the otel.kind span-kind contract on the inges…
jensholdgaard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
crates/ourios-ingester/tests/it/rfc0038_2_ingest_batch_span.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| //! RFC0038.2 — request-scope spans are O(1) in record count. | ||
| //! | ||
| //! The ingest hot path must never mint a span per record: that would both | ||
| //! strangle throughput and flood the trace backend, defeating the whole | ||
| //! sampling discipline of RFC 0038 §3. One OTLP Export batch yields exactly | ||
| //! one `ourios.ingest.batch` span with a single `ourios.wal.commit` child, | ||
| //! whether the batch carries one record or many. See `docs/rfcs/0038-self-tracing.md`. | ||
| //! | ||
| //! The subscriber is installed *scoped* to the driven future | ||
| //! (`WithSubscriber`) over an in-memory span exporter — no process-global | ||
| //! tracer provider, so this stays inside the consolidated harness (see | ||
| //! `tests/README.md` on the global-installer exclusions). | ||
|
|
||
| use crate::ingest_support::{open_pipeline, request, resource_logs}; | ||
| use opentelemetry::trace::{SpanId, TracerProvider as _}; | ||
| use opentelemetry_sdk::trace::{InMemorySpanExporter, SdkTracerProvider, SpanData}; | ||
| use tracing::instrument::WithSubscriber as _; | ||
| use tracing_subscriber::prelude::*; | ||
|
|
||
| /// Structurally distinct bodies so the miner mints a fresh `template_id` | ||
| /// per record — the per-record loop that RFC0038.2 forbids from spawning | ||
| /// spans is fully exercised. | ||
| fn distinct_bodies(n: usize) -> Vec<String> { | ||
| (0..n) | ||
| .map(|i| format!("event kind {i} completed status=ok")) | ||
| .collect() | ||
| } | ||
|
|
||
| /// Drive one `ingest_bound` of `record_count` records under a scoped | ||
| /// tracer and return every finished span. | ||
| async fn ingest_and_collect_spans(record_count: usize) -> Vec<SpanData> { | ||
| let tmp = tempfile::TempDir::new().expect("temp"); | ||
| let pipeline = open_pipeline(tmp.path()); | ||
|
|
||
| let exporter = InMemorySpanExporter::default(); | ||
| let provider = SdkTracerProvider::builder() | ||
| .with_simple_exporter(exporter.clone()) | ||
| .build(); | ||
| let subscriber = tracing_subscriber::registry() | ||
| .with(tracing_opentelemetry::layer().with_tracer(provider.tracer("ourios-test"))); | ||
|
|
||
| let bodies = distinct_bodies(record_count); | ||
| let body_refs: Vec<&str> = bodies.iter().map(String::as_str).collect(); | ||
| let export = request(vec![resource_logs("checkout", &body_refs)]); | ||
|
|
||
| let acked = pipeline | ||
| .ingest_bound(export, None, false) | ||
| .with_subscriber(subscriber) | ||
| .await | ||
| .expect("ingest acks"); | ||
| assert_eq!(acked, record_count, "every record acked"); | ||
|
|
||
| provider.force_flush().expect("spans flush"); | ||
| exporter.get_finished_spans().expect("spans exported") | ||
| } | ||
|
|
||
| fn spans_named<'a>(spans: &'a [SpanData], name: &str) -> Vec<&'a SpanData> { | ||
| spans.iter().filter(|s| s.name.as_ref() == name).collect() | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
| async fn rfc0038_2_ingest_batch_emits_one_span_with_a_wal_commit_child() { | ||
| let spans = ingest_and_collect_spans(1).await; | ||
|
|
||
| let batch = spans_named(&spans, "ourios.ingest.batch"); | ||
| let commit = spans_named(&spans, "ourios.wal.commit"); | ||
| assert_eq!( | ||
| batch.len(), | ||
| 1, | ||
| "exactly one ingest.batch span, got {spans:?}" | ||
| ); | ||
| assert_eq!( | ||
| commit.len(), | ||
| 1, | ||
| "exactly one wal.commit span, got {spans:?}" | ||
| ); | ||
|
|
||
| assert_ne!( | ||
| batch[0].span_context.span_id(), | ||
| SpanId::INVALID, | ||
| "the batch span has a real span id", | ||
| ); | ||
| assert_eq!( | ||
| commit[0].parent_span_id, | ||
| batch[0].span_context.span_id(), | ||
| "wal.commit nests under ingest.batch", | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
| async fn rfc0038_2_span_count_is_constant_in_record_count() { | ||
| let one = ingest_and_collect_spans(1).await; | ||
| let many = ingest_and_collect_spans(64).await; | ||
|
|
||
| assert_eq!( | ||
| one.len(), | ||
| many.len(), | ||
| "span count must not grow with record count (no per-record spans): \ | ||
| 1 record -> {} spans, 64 records -> {} spans", | ||
| one.len(), | ||
| many.len(), | ||
| ); | ||
| // The two request-scope spans, and nothing per-record. | ||
| assert_eq!( | ||
| many.len(), | ||
| 2, | ||
| "batch + wal.commit only, got {:?}", | ||
| many.iter().map(|s| s.name.clone()).collect::<Vec<_>>(), | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.