Skip to content

Commit 4f4c0e5

Browse files
committed
fix(telemetry): carry request completion timing into revisions correlation
Signed-off-by: Alex Fournier <afournier@nvidia.com>
2 parents a79c87e + 0f9452c commit 4f4c0e5

4 files changed

Lines changed: 27 additions & 5 deletions

File tree

‎crates/openshell-supervisor-network/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ and children around stages that actually run, with valid workload W3C context
7777
only as an untrusted link. Their records never create an extra denial-only span,
7878
even if the request span is disabled or unsampled. Other egress paths retain the
7979
legacy bounded deny-span behavior. End HTTP tracing before an upgraded session.
80+
The request span ends after its owned stages, not when response headers are logged.
8081

8182
Inspected request records retain the policy generation/hash, selected endpoint
8283
identity and pinned provider installation/revision under OCSF `unmapped`.

‎crates/openshell-supervisor-network/src/l7/request_trace.rs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,13 @@ impl RequestTrace {
181181

182182
impl Drop for RequestTrace {
183183
fn drop(&mut self) {
184-
self.span.record("openshell.request.outcome", self.outcome);
185-
if matches!(self.outcome, "failed" | "incomplete") {
186-
self.span.record("otel.status_code", "ERROR");
187-
}
184+
// Finalize exported timing after the request's child stages.
185+
self.span.in_scope(|| {
186+
self.span.record("openshell.request.outcome", self.outcome);
187+
if matches!(self.outcome, "failed" | "incomplete") {
188+
self.span.record("otel.status_code", "ERROR");
189+
}
190+
});
188191
}
189192
}
190193

‎crates/openshell-supervisor-network/src/l7/request_trace/tests.rs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,24 @@ fn explicit_request_root_does_not_adopt_ambient_otel_context() {
100100
assert_eq!(root.links.links.len(), 1);
101101
}
102102

103+
#[test]
104+
fn request_completion_encloses_stages_after_an_early_root_exit() {
105+
let spans = capture(Sampler::AlwaysOn, || {
106+
let mut trace = RequestTrace::new("local", "GET", "example.test", 443, &request("01"));
107+
trace.span().in_scope(|| trace.record_status(200));
108+
trace.stage(RequestStage::Response).in_scope(|| {});
109+
trace.record_outcome(HttpOutcome::Allowed);
110+
});
111+
let root = root(&spans);
112+
let response = spans
113+
.iter()
114+
.find(|span| span.name == RequestStage::Response.name())
115+
.unwrap();
116+
assert_eq!(response.parent_span_id, root.span_context.span_id());
117+
assert!(response.start_time >= root.start_time);
118+
assert!(response.end_time <= root.end_time);
119+
}
120+
103121
#[test]
104122
fn remote_sampled_flag_cannot_override_local_always_off() {
105123
for flags in ["00", "01"] {

‎docs/observability/ocsf-json-export.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ OTLP log export links every OCSF record, whatever its class, to the active sampl
313313

314314
With OTLP trace export enabled on a dedicated supervisor, each inspected HTTP request has an INFO `openshell.http.request` span for its allowed, denied or failed outcome. Children measure the policy, middleware, credential, upstream and response stages that actually run. HTTP upgrade tracing ends before the upgraded WebSocket session.
315315

316-
`openshell.upstream.send` measures request writes and flush, not the full upstream round trip. Response handling has a separate span.
316+
The request span ends after its owned stages, not when response headers are logged. `openshell.upstream.send` measures request writes and flush, not the full upstream round trip. Response handling has a separate span.
317317

318318
The supervisor owns the request trace. A valid workload `traceparent`, sampled or unsampled, becomes an explicitly untrusted link, never its parent. Invalid or duplicate context is ignored; workload `tracestate` is not adopted. Your backend may show the agent and supervisor as separate linked traces rather than one nested tree.
319319

0 commit comments

Comments
 (0)