Skip to content

Commit 13b3088

Browse files
Update README.md
Signed-off-by: Mohamed Asif <142201466+mohamedasifs123@users.noreply.github.com>
1 parent 486bcbf commit 13b3088

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

doca-demo/README.md

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# OpenTelemetry C++ Starter for DOCA
1+
# OpenTelemetry C++ Starter for DOCA
22

33
## Prerequisites
44

@@ -7,39 +7,44 @@ Ensure you have the following installed:
77
- **Git**
88
- **C++ Compiler**
99
- **Make**
10-
- **CMake**
10+
- **CMake**
1111
- **Docker** (for running the OTLP collector and Jeager)
1212

1313
### Create Project Directory
14+
1415
Create a folder named otel-cpp-starter.
1516

1617
move into the newly created folder. This will serve as your working directory.
1718

18-
19+
```bash
1920
mkdir otel-cpp-starter
2021
cd otel-cpp-starter
21-
22+
```
2223

2324
Next, install and build OpenTelemetry C++ locally using CMake, following these steps:
2425

2526
In your terminal, navigate back to the otel-cpp-starter directory. Then, clone the OpenTelemetry C++ GitHub repository to your local machine.
2627

28+
```bash
2729
git clone https://github.com/open-telemetry/opentelemetry-cpp.git
30+
```
2831

2932
Change your working directory to the OpenTelemetry C++ SDK directory.
3033

31-
```
34+
```bash
3235
cd opentelemetry-cpp
3336
```
3437

3538
Create a build directory and navigate into it.
36-
```
39+
40+
```bash
3741
mkdir build
3842
cd build
3943
```
4044

4145
In the build directory run CMake, to configure and generate the build system without enabling tests:
42-
```
46+
47+
```bash
4348
cmake -DBUILD_TESTING=OFF ..
4449
Or, if the cmake --build fails, you can also try:
4550

@@ -53,44 +58,53 @@ cmake --install . --prefix ../../otel-cpp
5358
```
5459
5560
## Traces
56-
#### Initialize tracing
57-
```
61+
62+
### Initialize tracing
63+
64+
```bash
5865
auto provider = opentelemetry::trace::Provider::GetTracerProvider();
5966
auto tracer = provider->GetTracer("foo_library", "1.0.0");
6067
```
68+
6169
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.
6270
6371
The Tracer acquired in the second step is needed to create and start Spans.
6472
6573
#### Start a span
66-
```
74+
75+
```bash
6776
auto span = tracer->StartSpan("HandleRequest");
6877
```
78+
6979
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.
7080
7181
#### Mark a span as active
72-
```
82+
83+
```bash
7384
auto scope = tracer->WithActiveSpan(span);
7485
```
86+
7587
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.
7688
7789
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.
7890
7991
## Exporters
8092
81-
#### Available exporters
93+
### Available exporters
94+
8295
The registry contains a list of exporters for C++.
8396
8497
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.
8598
8699
This page covers the main OpenTelemetry C++ exporters and how to set them up.
87100
88-
89101
## OTLP Exporter
90-
#### Collector Setup
102+
103+
### Collector Setup
91104
92105
In an empty directory, create a file called collector-config.yaml with the following content:
93-
```
106+
107+
```yaml
94108
receivers:
95109
otlp:
96110
protocols:
@@ -113,28 +127,33 @@ service:
113127
receivers: [otlp]
114128
exporters: [debug]
115129
```
130+
116131
Now run the collector in a docker container:
117-
```
132+
133+
```bash
118134
docker run -p 4317:4317 -p 4318:4318 --rm -v $(pwd)/collector-config.yaml:/etc/otelcol/config.yaml otel/opentelemetry-collector
119135
```
136+
120137
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.
121138
122139
#### Dependencies
140+
123141
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:
124142
125143
HTTP/protobuf
126144
gRPC
127145
Make sure that you have set the right cmake build variables while building OpenTelemetry C++ from source:
128-
```
129146
147+
```bash
130148
-DWITH_OTLP_GRPC=ON: To enable building OTLP gRPC exporter.
131149
-DWITH_OTLP_HTTP=ON: To enable building OTLP HTTP exporter.
132150
```
133151
134152
In this tutorial, we use HTTP endpoint.
135153
136154
## Usage
137-
```
155+
156+
```bash
138157
#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
139158
#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h"
140159
#include "opentelemetry/sdk/trace/processor.h"
@@ -201,7 +220,7 @@ void CleanupTracer()
201220
202221
and then we define our function traces and we pass the service name and operation name on to it.
203222
204-
```
223+
```bash
205224
void traces(std::string serviceName, std::string operationName)
206225
{
207226
auto span = getTracer(serviceName)->StartSpan(operationName);
@@ -211,8 +230,10 @@ void traces(std::string serviceName, std::string operationName)
211230
span->End();
212231
}
213232
```
233+
214234
we call it by using the traces and can pass the service and operation names respectively
215-
```
235+
236+
```bash
216237
traces("doca", "doca prepare");
217238
```
218239
@@ -221,13 +242,15 @@ The traces are called and it send the traces to otlp endpoint.
221242
After that, by using otlp the traces is sent to the jeager and it can be accessed on http...
222243
223244
The Build steps are as follows,
224-
```
245+
246+
```bash
225247
meson build
226248
cd build
227249
./doca_telemetry_export
228250
```
251+
229252
make sure to run the docker containers for otel and jeager before executing above commands.
230253
231-
the will display on browser on https://localhost:16686
254+
the will display on browser on [Jeager](https://localhost:16686)
232255
233256
![demo](images/demo.png)

0 commit comments

Comments
 (0)