Skip to content

Commit fcd65b2

Browse files
theletterfcartermp
andauthored
Add note on OTel C++ and automatic instrumentation (#4542)
Co-authored-by: Phillip Carter <[email protected]>
1 parent 82feec4 commit fcd65b2

File tree

2 files changed

+37
-30
lines changed

2 files changed

+37
-30
lines changed

content/en/docs/languages/cpp/getting-started.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Ensure that you have the following installed locally:
1919
- Make
2020
- CMake version >= 3.25
2121

22-
## Example Application
22+
## Example application
2323

2424
The following example uses a basic [Oat++](https://oatpp.io/) application. If
2525
you are not using Oat++, that's OK - you can use OpenTelemetry C++ with any
@@ -396,7 +396,7 @@ will see a span being emitted to the terminal.
396396
}
397397
```
398398

399-
## Next Steps
399+
## Next steps
400400

401401
For more information about instrumenting your code, refer the
402402
[instrumentation](/docs/languages/cpp/instrumentation) documentation.

content/en/docs/languages/cpp/instrumentation.md

+35-28
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ cSpell:ignore: decltype labelkv nostd nullptr
1111

1212
{{% docs/languages/instrumentation-intro %}}
1313

14+
{{% alert title="Note" color="primary" %}}
15+
16+
OpenTelemetry C++ doesn't support automatic instrumentation when the source code
17+
of the library you want to instrument isn't available.
18+
19+
{{% /alert %}}
20+
1421
## Setup
1522

1623
Follow the instructions in the
@@ -19,7 +26,7 @@ OpenTelemetry C++.
1926

2027
## Traces
2128

22-
### Initializing tracing
29+
### Initialize tracing
2330

2431
```cpp
2532
auto provider = opentelemetry::trace::Provider::GetTracerProvider();
@@ -57,7 +64,7 @@ The concept of an active span is important, as any span that is created without
5764
explicitly specifying a parent is parented to the currently active span. A span
5865
without a parent is called root span.
5966
60-
### Create nested Spans
67+
### Create nested spans
6168
6269
```cpp
6370
auto outer_span = tracer->StartSpan("Outer operation");
@@ -76,7 +83,7 @@ Spans can be nested, and have a parent-child relationship with other spans. When
7683
a given span is active, the newly created span inherits the active span’s trace
7784
ID, and other context attributes.
7885

79-
### Context Propagation
86+
### Context propagation
8087

8188
```cpp
8289
// set global propagator
@@ -105,18 +112,18 @@ distributed tracing to transfer this Context across service boundary often
105112
through HTTP headers. OpenTelemetry provides a text-based approach to propagate
106113
context to remote services using the W3C Trace Context HTTP headers.
107114
108-
### Further Reading
115+
### Further reading
109116
110117
- [Traces API](https://opentelemetry-cpp.readthedocs.io/en/latest/otel_docs/namespace_opentelemetry__trace.html)
111118
- [Traces SDK](https://opentelemetry-cpp.readthedocs.io/en/latest/otel_docs/namespace_opentelemetry__sdk__trace.html)
112119
- [Simple Metrics Example](https://github.com/open-telemetry/opentelemetry-cpp/tree/main/examples/metrics_simple)
113120
114121
## Metrics
115122
116-
### Initialize Exporter and Reader
123+
### Initialize exporter and reader
117124
118-
Initialize an exporter and a reader. In this case, we initialize an OStream
119-
Exporter which will print to stdout by default. The reader periodically collects
125+
Initialize an exporter and a reader. In this case, you initialize an OStream
126+
Exporter which prints to stdout by default. The reader periodically collects
120127
metrics from the Aggregation Store and exports them.
121128
122129
```cpp
@@ -125,23 +132,23 @@ std::unique_ptr<opentelemetry::sdk::metrics::MetricReader> reader{
125132
new opentelemetry::sdk::metrics::PeriodicExportingMetricReader(std::move(exporter), options)};
126133
```
127134

128-
### Initialize Meter Provider
135+
### Initialize a meter provider
129136

130-
Initialize a MeterProvider and add the reader. We will use this to obtain Meter
131-
objects in the future.
137+
Initialize a MeterProvider and add the reader. Use this to obtain Meter objects
138+
in the future.
132139

133140
```cpp
134141
auto provider = std::shared_ptr<opentelemetry::metrics::MeterProvider>(new opentelemetry::sdk::metrics::MeterProvider());
135142
auto p = std::static_pointer_cast<opentelemetry::sdk::metrics::MeterProvider>(provider);
136143
p->AddMetricReader(std::move(reader));
137144
```
138145
139-
### Create a Counter
146+
### Create a counter
140147
141148
Create a Counter instrument from the Meter, and record the measurement. Every
142149
Meter pointer returned by the MeterProvider points to the same Meter. This means
143-
that the Meter will be able to combine metrics captured from different functions
144-
without having to constantly pass the Meter around the library.
150+
that the Meter can combine metrics captured from different functions without
151+
having to constantly pass the Meter around the library.
145152
146153
```cpp
147154
auto meter = provider->GetMeter(name, "1.2.0");
@@ -152,36 +159,36 @@ auto labelkv = common::KeyValueIterableView<decltype(labels)>{labels};
152159
double_counter->Add(val, labelkv);
153160
```
154161

155-
### Create a Histogram
162+
### Create a histogram
156163

157-
Create a Histogram instrument from the Meter, and record the measurement.
164+
Create a histogram instrument from the meter, and record the measurement.
158165

159166
```cpp
160167
auto meter = provider->GetMeter(name, "1.2.0");
161168
auto histogram_counter = meter->CreateDoubleHistogram("histogram_name");
162169
histogram_counter->Record(val, labelkv);
163170
```
164171
165-
### Create Observable Counter
172+
### Create an observable counter
166173
167-
Create a Observable Counter Instrument from the Meter, and add a callback. The
168-
callback would be used to record the measurement during metrics collection.
169-
Ensure to keep the Instrument object active for the lifetime of collection.
174+
Create an observable counter instrument from the meter, and add a callback. The
175+
callback is used to record the measurement during metrics collection. Ensure to
176+
keep the Instrument object active for the lifetime of collection.
170177
171178
```cpp
172179
auto meter = provider->GetMeter(name, "1.2.0");
173180
auto counter = meter->CreateDoubleObservableCounter(counter_name);
174181
counter->AddCallback(MeasurementFetcher::Fetcher, nullptr);
175182
```
176183

177-
### Create Views
184+
### Create views
178185

179-
#### Map the Counter Instrument to Sum Aggregation
186+
#### Map the counter instrument to sum aggregation
180187

181188
Create a view to map the Counter Instrument to Sum Aggregation. Add this view to
182-
provider. View creation is optional unless we want to add custom aggregation
183-
config, and attribute processor. Metrics SDK will implicitly create a missing
184-
view with default mapping between Instrument and Aggregation.
189+
provider. View creation is optional unless you want to add custom aggregation
190+
config, and attribute processor. Metrics SDK creates a missing view with default
191+
mapping between Instrument and Aggregation.
185192

186193
```cpp
187194
std::unique_ptr<opentelemetry::sdk::metrics::InstrumentSelector> instrument_selector{
@@ -193,7 +200,7 @@ std::unique_ptr<opentelemetry::sdk::metrics::View> sum_view{
193200
p->AddView(std::move(instrument_selector), std::move(meter_selector), std::move(sum_view));
194201
```
195202
196-
#### Map the Histogram Instrument to Histogram Aggregation
203+
#### Map the histogram instrument to histogram aggregation
197204
198205
```cpp
199206
std::unique_ptr<opentelemetry::sdk::metrics::InstrumentSelector> histogram_instrument_selector{
@@ -206,7 +213,7 @@ p->AddView(std::move(histogram_instrument_selector), std::move(histogram_meter_s
206213
std::move(histogram_view));
207214
```
208215

209-
#### Map the Observable Counter Instrument to Sum Aggregation
216+
#### Map the observable counter instrument to sum aggregation
210217

211218
```cpp
212219
std::unique_ptr<opentelemetry::sdk::metrics::InstrumentSelector> observable_instrument_selector{
@@ -220,7 +227,7 @@ p->AddView(std::move(observable_instrument_selector), std::move(observable_meter
220227
std::move(observable_sum_view));
221228
```
222229
223-
### Further Reading
230+
### Further reading
224231
225232
- [Metrics API](https://opentelemetry-cpp.readthedocs.io/en/latest/otel_docs/namespace_opentelemetry__metrics.html#)
226233
- [Metrics SDK](https://opentelemetry-cpp.readthedocs.io/en/latest/otel_docs/namespace_opentelemetry__sdk__metrics.html)
@@ -232,7 +239,7 @@ The documentation for the logs API & SDK is missing, you can help make it
232239
available by
233240
[editing this page](https://github.com/open-telemetry/opentelemetry.io/edit/main/content/en/docs/languages/cpp/instrumentation.md).
234241
235-
## Next Steps
242+
## Next steps
236243
237244
You’ll also want to configure an appropriate exporter to
238245
[export your telemetry data](/docs/languages/cpp/exporters) to one or more

0 commit comments

Comments
 (0)