You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
auto provider = opentelemetry::trace::Provider::GetTracerProvider();
59
66
auto tracer = provider->GetTracer("foo_library", "1.0.0");
60
67
```
68
+
61
69
The TracerProvider acquired in the first step is a singleton object that is usually provided by the OpenTelemetry C++ SDK. It is used to provide specific implementations for API interfaces. In case no SDK is used, the API provides a default no-op implementation of a TracerProvider.
62
70
63
71
The Tracer acquired in the second step is needed to create and start Spans.
64
72
65
73
#### Start a span
66
-
```
74
+
75
+
```bash
67
76
auto span = tracer->StartSpan("HandleRequest");
68
77
```
78
+
69
79
This creates a span, sets its name to "HandleRequest", and sets its start time to the current time. Refer to the API documentation for other operations that are available to enrich spans with additional data.
70
80
71
81
#### Mark a span as active
72
-
```
82
+
83
+
```bash
73
84
auto scope = tracer->WithActiveSpan(span);
74
85
```
86
+
75
87
This marks a span as active and returns a Scope object. The scope object controls how long a span is active. The span remains active for the lifetime of the scope object.
76
88
77
89
The concept of an active span is important, as any span that is created without explicitly specifying a parent is parented to the currently active span. A span without a parent is called root span.
78
90
79
91
## Exporters
80
92
81
-
#### Available exporters
93
+
### Available exporters
94
+
82
95
The registry contains a list of exporters for C++.
83
96
84
97
Among exporters, OpenTelemetry Protocol (OTLP) exporters are designed with the OpenTelemetry data model in mind, emitting OTel data without any loss of information. Furthermore, many tools that operate on telemetry data support OTLP (such as Prometheus, Jaeger, and most vendors), providing you with a high degree of flexibility when you need it. To learn more about OTLP, see OTLP Specification.
85
98
86
99
This page covers the main OpenTelemetry C++ exporters and how to set them up.
87
100
88
-
89
101
## OTLP Exporter
90
-
#### Collector Setup
102
+
103
+
### Collector Setup
91
104
92
105
In an empty directory, create a file called collector-config.yaml with the following content:
93
-
```
106
+
107
+
```yaml
94
108
receivers:
95
109
otlp:
96
110
protocols:
@@ -113,28 +127,33 @@ service:
113
127
receivers: [otlp]
114
128
exporters: [debug]
115
129
```
130
+
116
131
Now run the collector in a docker container:
117
-
```
132
+
133
+
```bash
118
134
docker run -p 4317:4317 -p 4318:4318 --rm -v $(pwd)/collector-config.yaml:/etc/otelcol/config.yaml otel/opentelemetry-collector
119
135
```
136
+
120
137
This collector is now able to accept telemetry via OTLP. Later you may want to configure the collector to send your telemetry to your observability backend.
121
138
122
139
#### Dependencies
140
+
123
141
If you want to send telemetry data to an OTLP endpoint (like the OpenTelemetry Collector, Jaeger or Prometheus), you can choose between two different protocols to transport your data:
124
142
125
143
HTTP/protobuf
126
144
gRPC
127
145
Make sure that you have set the right cmake build variables while building OpenTelemetry C++ from source:
128
-
```
129
146
147
+
```bash
130
148
-DWITH_OTLP_GRPC=ON: To enable building OTLP gRPC exporter.
131
149
-DWITH_OTLP_HTTP=ON: To enable building OTLP HTTP exporter.
0 commit comments