A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
trace_context.h
Go to the documentation of this file.
1// Copyright 2026 The A11 Authors.
2
3#ifndef A11_OBS_TRACE_CONTEXT_H_
4#define A11_OBS_TRACE_CONTEXT_H_
5
6#include <cstdint>
7#include <optional>
8#include <string>
9#include <string_view>
10#include <vector>
11
12#include <absl/status/status.h>
13#include <absl/status/statusor.h>
14
15#include "a11/data/types.h"
16
17namespace a11::obs {
18
20inline constexpr std::string_view kTraceparentHeader = "x-otel-traceparent";
22inline constexpr std::string_view kTracestateHeader = "x-otel-tracestate";
24inline constexpr std::string_view kBaggageHeader = "x-otel-baggage";
25
28 std::string key;
29 std::string value;
30 std::string properties;
31
32 friend bool operator==(const BaggageEntry&, const BaggageEntry&) = default;
33};
34
37 std::string trace_id;
38 std::string span_id;
39 std::uint8_t trace_flags = 0;
40 std::string tracestate;
41 std::vector<BaggageEntry> baggage;
42
44 [[nodiscard]] bool sampled() const { return (trace_flags & 0x01U) != 0; }
45
46 friend bool operator==(const TraceContext&, const TraceContext&) = default;
47};
48
52absl::StatusOr<std::optional<TraceContext>> ExtractTraceContext(
53 const data::ByteMap& headers);
54
56absl::Status InjectTraceContext(const TraceContext& context,
57 data::ByteMap& headers);
58
59} // namespace a11::obs
60
61#endif // A11_OBS_TRACE_CONTEXT_H_
absl::flat_hash_map< std::string, Bytes > ByteMap
String-keyed map of byte values (headers, attributes, etc.).
Definition types.h:42
Definition provider.cc:47
constexpr std::string_view kTracestateHeader
Reserved action header carrying the W3C tracestate value.
Definition trace_context.h:22
constexpr std::string_view kBaggageHeader
Reserved action header carrying request-scoped W3C baggage.
Definition trace_context.h:24
absl::Status InjectTraceContext(const TraceContext &context, data::ByteMap &headers)
Serialize context into reserved headers, replacing existing values.
Definition trace_context.cc:221
constexpr std::string_view kTraceparentHeader
Reserved action header carrying the W3C traceparent value.
Definition trace_context.h:20
absl::StatusOr< std::optional< TraceContext > > ExtractTraceContext(const data::ByteMap &headers)
Extract a remote parent; nullopt means no tracing headers were supplied.
Definition trace_context.cc:184
Future< T > SubmitWithCancellationHook(absl::AnyInvocable< absl::StatusOr< T >() && > work, std::function< void()> cancellation_hook, thread::TreeOptions tree_options)
Run work on A11's fiber pool with application-specific cancellation.
Definition executor.h:30
One decoded W3C baggage member propagated through nested and remote actions.
Definition trace_context.h:27
std::string properties
Trailing semicolon-separated properties.
Definition trace_context.h:30
std::string value
Percent-decoded member value.
Definition trace_context.h:29
std::string key
Trimmed member key; percent escapes stay encoded.
Definition trace_context.h:28
friend bool operator==(const BaggageEntry &, const BaggageEntry &)=default
SDK-independent W3C parent context recovered from reserved action headers.
Definition trace_context.h:36
std::string span_id
16 lowercase hex characters.
Definition trace_context.h:38
std::vector< BaggageEntry > baggage
Request-scoped propagated values.
Definition trace_context.h:41
bool sampled() const
Whether the W3C sampled flag is set.
Definition trace_context.h:44
std::string trace_id
32 lowercase hex characters.
Definition trace_context.h:37
std::uint8_t trace_flags
W3C trace flags byte.
Definition trace_context.h:39
friend bool operator==(const TraceContext &, const TraceContext &)=default
std::string tracestate
Raw tracestate header; may be empty.
Definition trace_context.h:40
A11's core wire value types: chunks, node fragments and messages.