A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
provider.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
22#ifndef A11_OBS_PROVIDER_H_
23#define A11_OBS_PROVIDER_H_
24
25#include <string>
26#include <utility>
27#include <vector>
28
29#include <absl/status/status.h>
30
31#include "a11/obs/span.h"
32
33namespace a11::obs {
34
36enum class ExporterKind {
37 kNone,
38 kInMemory,
39 kOstream,
42};
43
46 std::string service_name = "a11";
48 std::vector<std::pair<std::string, std::string>> resource_attributes;
51 // Simple (synchronous) processing exports each span as it ends -- convenient
52 // and deterministic for tests. Batch processing is used otherwise.
53 bool use_simple_processor = false;
54
55 // OTLP/HTTP options (only used when exporter == kOtlpHttp).
56 std::string otlp_endpoint;
58 std::vector<std::pair<std::string, std::string>> otlp_headers;
59 int otlp_timeout_millis = 10000;
60
61 // Baggage keys promoted onto every span as attributes (of the same name).
63 std::vector<std::string> baggage_span_attributes;
64};
65
68absl::Status Configure(const ProviderOptions& options);
69
71void Shutdown();
72
74[[nodiscard]] bool IsConfigured();
75
76// --- Introspection (meaningful only with ExporterKind::kInMemory) ---------
77
80 std::string name;
81 std::vector<std::pair<std::string, std::string>>
83};
84
87 std::string name;
88 std::string trace_id;
89 std::string span_id;
90 std::string parent_span_id;
92 int status_code = 0;
93 std::string status_description;
94 std::vector<std::pair<std::string, std::string>>
96 std::vector<RecordedEvent> events;
97};
98
100std::vector<RecordedSpan> GetRecordedSpans();
101
103void ClearRecordedSpans();
104
105} // namespace a11::obs
106
107#endif // A11_OBS_PROVIDER_H_
Definition provider.cc:58
ExporterKind
Destination used for spans produced by actions, sessions, and transports.
Definition provider.h:36
@ 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:302
std::vector< RecordedSpan > GetRecordedSpans()
Return in-memory spans oldest first; meaningful for kInMemory only.
Definition provider.cc:307
void Shutdown()
Flush pending spans and restore the process to its unconfigured state.
Definition provider.cc:294
absl::Status Configure(const ProviderOptions &options)
Install or replace the process-wide tracer provider.
Definition provider.cc:214
SpanKind
OpenTelemetry span relationships, mirrored to keep OTel out of this API.
Definition span.h:35
void ClearRecordedSpans()
Clear spans retained by the in-memory exporter.
Definition provider.cc:314
Configure how an A11 process records and exports agent traces.
Definition provider.h:45
std::string otlp_endpoint
Full OTLP/HTTP traces URL.
Definition provider.h:56
std::vector< std::pair< std::string, std::string > > otlp_headers
Request headers such as backend authentication.
Definition provider.h:58
std::string service_name
OTel service.name resource value.
Definition provider.h:46
bool use_simple_processor
Export synchronously as spans end.
Definition provider.h:53
int otlp_timeout_millis
Export request timeout.
Definition provider.h:59
std::vector< std::pair< std::string, std::string > > resource_attributes
Additional attributes attached to the process-level OTel resource.
Definition provider.h:48
ExporterKind exporter
Span destination; must not remain kNone when passed to Configure().
Definition provider.h:50
std::vector< std::string > baggage_span_attributes
Baggage keys promoted to same-named span attributes.
Definition provider.h:63
Event captured on a span by the in-memory exporter.
Definition provider.h:79
std::vector< std::pair< std::string, std::string > > attributes
Snapshot attributes.
Definition provider.h:82
std::string name
Event name.
Definition provider.h:80
Finished span snapshot returned by the in-memory exporter.
Definition provider.h:86
int status_code
OTel status: 0 unset, 1 OK, 2 error.
Definition provider.h:92
std::string span_id
16 lowercase hex characters.
Definition provider.h:89
std::vector< std::pair< std::string, std::string > > attributes
Final attributes.
Definition provider.h:95
std::string parent_span_id
Parent id, or empty for a root span.
Definition provider.h:90
SpanKind kind
OTel relationship kind.
Definition provider.h:91
std::string status_description
Optional error explanation.
Definition provider.h:93
std::string trace_id
32 lowercase hex characters.
Definition provider.h:88
std::vector< RecordedEvent > events
Events in recording order.
Definition provider.h:96
std::string name
Final span name.
Definition provider.h:87