A11 emits action, session, and wire-stream spans from the native runtime. Configure one process-wide provider before creating those objects, then attach trace context at the boundary where an application request begins.
Configure OTLP/HTTP
The native exporter accepts a complete traces URL. Authentication headers and resource attributes remain application configuration, so the same binary can target a local collector or a hosted backend.
.resource_attributes = {
{"deployment.environment", "production"},
{"service.version", "1.4.0"},
},
.otlp_endpoint = "https://otel.example.com/v1/traces",
.otlp_headers = {{"authorization", "Bearer token"}},
.otlp_timeout_millis = 10000,
.baggage_span_attributes = {"tenant.id"},
};
@ kOtlpHttp
Native OTLP/HTTP export; requires the A11_WITH_OTLP_HTTP build option.
absl::Status Configure(const ProviderOptions &options)
Install or replace the process-wide tracer provider.
Definition provider.cc:214
Configure how an A11 process records and exports agent traces.
Definition provider.h:45
std::string service_name
OTel service.name resource value.
Definition provider.h:46
Build A11 with OTLP/HTTP support when selecting kOtlpHttp. Use kOstream for local inspection and kInMemory for deterministic tests.
Trace a root action
Configuring the provider records session and stream lifecycles automatically. Actions require W3C context. Start a span for the surrounding request, inject its context into the action headers, and run the action normally.
ABSL_RETURN_IF_ERROR(action->SetHeader(
name, std::move(
value)));
}
ABSL_RETURN_IF_ERROR(action->Run().status());
const absl::Status completed = action->Wait().Await().status();
ABSL_RETURN_IF_ERROR(completed);
Move-only RAII handle to one action, session, or transport span.
Definition span.h:51
void SetStatus(const absl::Status &status)
Map an A11 operation status onto the span's OTel outcome.
Definition tracer.cc:276
absl::Status InjectContext(data::ByteMap &headers) const
Inject trace context and inherited baggage into reserved A11 headers.
Definition tracer.cc:335
void SetAttribute(std::string_view key, std::string_view value)
Set or replace a string attribute on the live span.
Definition tracer.cc:216
static Span StartRootSpan(std::string_view name, SpanKind kind, std::string_view preassigned_trace_id={})
Start a root span, optionally using a preassigned 32-character trace id.
Definition tracer.cc:393
std::string value
Definition discover.cc:114
absl::flat_hash_map< std::string, Bytes > ByteMap
String-keyed map of byte values (headers, attributes, etc.).
Definition types.h:58
The action becomes a child of request. Nested actions inherit that context, and remote calls carry it in A11's reserved trace headers. A service receiving the call continues the same trace without OpenTelemetry thread-local state.
Continue incoming context
An HTTP or messaging boundary can provide a decoded TraceContext. Pass it to Tracer::StartSpan and inject the resulting context into downstream work:
ABSL_ASSIGN_OR_RETURN(
std::optional<a11::obs::TraceContext>
parent,
static Span StartSpan(std::string_view name, SpanKind kind, const TraceContext *parent)
Continue parent, or begin a root when it is null or empty.
Definition tracer.cc:354
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:148
const Scope * parent
Definition resolve.cc:730
Malformed trace headers return an error rather than detaching work from the requested trace.
Session and stream spans
Once configured, the runtime emits these infrastructure spans without action headers:
| Span | Lifetime | Data |
a11.session | Creation through completion | ID and terminal status |
a11.wire_stream | Startup through bilateral completion | ID, role, status, send events |
Each a11.wire.send event records action-message count, node-fragment count, and approximate bytes. Payload values are omitted. Session and stream spans use independent infrastructure traces; correlate them with a11.session.id and a11.stream.id.
Flush during shutdown
Stop accepting work, drain services, and finish traced actions before shutting down the provider:
ABSL_RETURN_IF_ERROR(service->StopAccepting());
ABSL_RETURN_IF_ERROR(service->Drain(absl::Seconds(30)).Await().status());
void Shutdown()
Flush pending spans and restore the process to its unconfigured state.
Definition provider.cc:294
Shutdown() flushes buffered spans and returns tracing to its unconfigured state. A later Configure() call can install a new provider.