1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//! W3C `TraceContext` propagation for distributed tracing
//!
//! This module provides utilities for injecting and extracting trace context
//! across process boundaries, enabling distributed tracing when subgraphs execute
//! in independent services or remote execution contexts.
//!
//! # Feature Flags
//!
//! - `otel` (default: off) - Enable OpenTelemetry propagator support
//!
//! # Basic Usage
//!
//! Inject trace context before crossing process boundaries:
//!
//! ```ignore
//! use juncture_tracing::propagation::inject_trace_context;
//! use opentelemetry::propagation::Injector;
//!
//! let mut carrier = HashMap::new();
//! inject_trace_context(&mut carrier);
//! // Send carrier to remote service
//! ```
//!
//! Extract trace context on the receiving side:
//!
//! ```ignore
//! use juncture_tracing::propagation::extract_trace_context;
//! use opentelemetry::propagation::Extractor;
//!
//! let carrier = receive_trace_context_from_remote();
//! let context = extract_trace_context(&carrier)?;
//! // Use context to establish parent span relationship
//! ```
use ;
use TraceContextExt;
use ;
use TraceContextPropagator;
/// Inject current W3C `TraceContext` into a carrier.
///
/// Extracts the current trace context from the runtime and serializes it
/// into the provided carrier using the W3C `TraceContext` format.
///
/// This function should be called before crossing process boundaries (e.g.,
/// when invoking a remote subgraph service) to enable trace continuity.
///
/// # Arguments
///
/// * `carrier` - Mutable reference to an injector that receives trace headers
///
/// # Examples
///
/// ```ignore
/// use juncture_tracing::propagation::inject_trace_context;
/// use std::collections::HashMap;
///
/// fn send_request_with_tracing() {
/// let mut headers = HashMap::new();
/// inject_trace_context(&mut headers);
/// // Send headers via HTTP/gRPC to remote service
/// }
/// ```
///
/// # W3C `TraceContext` Headers
///
/// This function injects the following headers when trace context is active:
/// - `traceparent`: Trace ID, span ID, and trace flags
/// - `tracestate`: Vendor-specific trace state (if present)
/// Extract W3C `TraceContext` from a carrier.
///
/// Deserializes trace context from the provided carrier using the W3C
/// `TraceContext` format and returns an OpenTelemetry [`Context`] that can
/// be used to establish parent span relationships.
///
/// This function should be called when receiving a request from another
/// service to ensure trace continuity across process boundaries.
///
/// # Arguments
///
/// * `carrier` - Reference to an extractor containing trace headers
///
/// # Returns
///
/// Returns an OpenTelemetry [`Context`] containing the extracted trace context.
/// If no trace context is present in the carrier, returns the current context.
///
/// # Examples
///
/// ```ignore
/// use juncture_tracing::propagation::extract_trace_context;
/// use std::collections::HashMap;
///
/// fn handle_remote_request(headers: &HashMap<String, String>) {
/// let ctx = extract_trace_context(headers);
/// let _guard = ctx.attach();
/// // All spans created here will be part of the incoming trace
/// }
/// ```
/// Attach a context to the current execution scope.
///
/// Establishes the provided context as the active context for the duration
/// of the returned guard's lifetime. All spans created within this scope
/// will have the context's span as their parent.
///
/// This is typically used after extracting trace context from a remote
/// service to ensure trace continuity.
///
/// # Arguments
///
/// * `context` - The context to attach as current
///
/// # Returns
///
/// Returns a [`ContextGuard`] that detaches the context when dropped.
///
/// # Examples
///
/// ```ignore
/// use juncture_tracing::propagation::{extract_trace_context, attach_context};
/// use std::collections::HashMap;
///
/// fn handle_remote_request(headers: &HashMap<String, String>) {
/// let ctx = extract_trace_context(headers);
/// let _guard = attach_context(&ctx);
/// // All spans created here are part of the incoming trace
/// // Guard detaches when it goes out of scope
/// }
/// ```
// Rust guideline compliant 2026-05-24