Expand description
Copyright © 2025-2026 Wenze Wei. All Rights Reserved.
This file is part of DMSC. The DMSC project belongs to the Dunimd Team.
Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
§Distributed Tracing Context Propagation
This module provides implementations for distributed tracing context propagation, following the W3C Trace Context specification. It allows for propagating trace information across service boundaries using HTTP headers.
§Key Components
- DMSCTraceContext: Represents W3C Trace Context with trace ID, parent ID, and flags
- DMSCBaggage: Represents baggage for carrying additional cross-cutting concerns
- DMSCContextCarrier: Carries both trace context and baggage for propagation
§Design Principles
- W3C Compliance: Implements the W3C Trace Context specification
- Baggage Support: Provides baggage propagation for additional context
- HTTP Header Integration: Supports extraction and injection from/to HTTP headers
- Serialization Support: Implements Serialize and Deserialize for easy persistence
- Thread Safety: All structs are cloneable for safe sharing across threads
- Sampling Support: Includes trace sampling flag support
- Trace State: Optional support for vendor-specific trace state
- Easy to Use: Simple API for creating and manipulating trace contexts
§Usage
use dmsc::prelude::*;
use std::collections::HashMap;
fn example() {
// Create trace and span IDs
let trace_id = DMSCTraceId::generate();
let span_id = DMSCSpanId::generate();
// Create a trace context
let mut trace_context = DMSCTraceContext::new(trace_id, span_id);
trace_context.set_sampled(true);
// Create baggage
let mut baggage = DMSCBaggage::new();
baggage.insert("user_id".to_string(), "12345".to_string());
baggage.insert("request_id".to_string(), "abc123".to_string());
// Create a context carrier
let carrier = DMSCContextCarrier::new()
.with_trace_context(trace_context)
.with_baggage(baggage);
// Inject into HTTP headers
let mut headers = HashMap::new();
carrier.inject_into_headers(&mut headers);
println!("Headers: {:?}", headers);
// Extract from HTTP headers
let extracted_carrier = DMSCContextCarrier::from_headers(&headers);
println!("Extracted trace context: {:?}", extracted_carrier.trace_context);
}Structs§
- DMSC
Baggage - Baggage propagation for cross-cutting concerns.
- DMSC
Context Carrier - Context carrier for distributed tracing.
- DMSC
Trace Context - W3C Trace Context propagation format
- W3CTrace
Propagator - W3C Trace Context Propagator for distributed tracing.