A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
provider.h
Go to the documentation of this file.
1// Copyright 2026 The A11 Authors.
2
8#ifndef A11_OBS_PROVIDER_H_
9#define A11_OBS_PROVIDER_H_
10
11#include <string>
12#include <utility>
13#include <vector>
14
15#include <absl/status/status.h>
16
17#include "a11/obs/span.h"
18
19namespace a11::obs {
20
22enum class ExporterKind {
23 kNone,
24 kInMemory,
25 kOstream,
28};
29
32 std::string service_name = "a11";
34 std::vector<std::pair<std::string, std::string>> resource_attributes;
37 // Simple (synchronous) processing exports each span as it ends -- convenient
38 // and deterministic for tests. Batch processing is used otherwise.
39 bool use_simple_processor = false;
40
41 // OTLP/HTTP options (only used when exporter == kOtlpHttp).
42 std::string otlp_endpoint;
44 std::vector<std::pair<std::string, std::string>> otlp_headers;
45 int otlp_timeout_millis = 10000;
46
47 // Baggage keys promoted onto every span as attributes (of the same name).
48 // This is how request-scoped values set upstream via the x-otel-baggage
49 // header -- e.g. langfuse.session.id -- become span attributes that a
50 // backend can read, while still propagating across nested/remote actions.
52 std::vector<std::string> baggage_span_attributes;
53};
54
57absl::Status Configure(const ProviderOptions& options);
58
60void Shutdown();
61
63[[nodiscard]] bool IsConfigured();
64
65// --- Introspection (meaningful only with ExporterKind::kInMemory) ---------
66
69 std::string name;
70 std::vector<std::pair<std::string, std::string>>
72};
73
76 std::string name;
77 std::string trace_id;
78 std::string span_id;
79 std::string parent_span_id;
81 int status_code = 0;
82 std::string status_description;
83 std::vector<std::pair<std::string, std::string>>
85 std::vector<RecordedEvent> events;
86};
87
89std::vector<RecordedSpan> GetRecordedSpans();
90
93
94} // namespace a11::obs
95
96#endif // A11_OBS_PROVIDER_H_
Definition provider.cc:47
ExporterKind
Destination used for spans produced by actions, sessions, and transports.
Definition provider.h:22
@ kNone
Unconfigured sentinel; Configure() rejects this value.
@ kOtlpHttp
Native OTLP/HTTP export; requires the A11_WITH_OTLP_HTTP build option.
@ kInMemory
Retain finished spans for GetRecordedSpans(); useful in tests.
@ kOstream
Human-readable output for local debugging.
bool IsConfigured()
Whether a tracer provider is currently installed.
Definition provider.cc:293
std::vector< RecordedSpan > GetRecordedSpans()
Return in-memory spans oldest first; meaningful for kInMemory only.
Definition provider.cc:298
void Shutdown()
Flush pending spans and restore the process to its unconfigured state.
Definition provider.cc:285
absl::Status Configure(const ProviderOptions &options)
Install or replace the process-wide tracer provider.
Definition provider.cc:205
SpanKind
OpenTelemetry span relationships, mirrored to keep OTel out of this API.
Definition span.h:21
void ClearRecordedSpans()
Clear spans retained by the in-memory exporter.
Definition provider.cc:305
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
Configure how an A11 process records and exports agent traces.
Definition provider.h:31
std::string otlp_endpoint
Full OTLP/HTTP traces URL.
Definition provider.h:42
std::vector< std::pair< std::string, std::string > > otlp_headers
Request headers such as backend authentication.
Definition provider.h:44
std::string service_name
OTel service.name resource value.
Definition provider.h:32
bool use_simple_processor
Export synchronously as spans end.
Definition provider.h:39
int otlp_timeout_millis
Export request timeout.
Definition provider.h:45
std::vector< std::pair< std::string, std::string > > resource_attributes
Additional attributes attached to the process-level OTel resource.
Definition provider.h:34
ExporterKind exporter
Span destination; must not remain kNone when passed to Configure().
Definition provider.h:36
std::vector< std::string > baggage_span_attributes
Baggage keys promoted to same-named span attributes.
Definition provider.h:52
Event captured on a span by the in-memory exporter.
Definition provider.h:68
std::vector< std::pair< std::string, std::string > > attributes
Snapshot attributes.
Definition provider.h:71
std::string name
Event name.
Definition provider.h:69
Finished span snapshot returned by the in-memory exporter.
Definition provider.h:75
int status_code
OTel status: 0 unset, 1 OK, 2 error.
Definition provider.h:81
std::string span_id
16 lowercase hex characters.
Definition provider.h:78
std::vector< std::pair< std::string, std::string > > attributes
Final attributes.
Definition provider.h:84
std::string parent_span_id
Parent id, or empty for a root span.
Definition provider.h:79
SpanKind kind
OTel relationship kind.
Definition provider.h:80
std::string status_description
Optional error explanation.
Definition provider.h:82
std::string trace_id
32 lowercase hex characters.
Definition provider.h:77
std::vector< RecordedEvent > events
Events in recording order.
Definition provider.h:85
std::string name
Final span name.
Definition provider.h:76