1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
-------------------------------------------------------------
C wrapper for the C++ implementation of the OpenTracing API
-------------------------------------------------------------
Summary
------------------------------------------------------------------------
1. Introduction
2. Build instructions
3. Testing the operation of the library
4. Basic concepts in the OpenTracing
5. Tracing example
6. Known bugs and limitations
1. Introduction
------------------------------------------------------------------------
OpenTracing C Wrapper library was created due to the need to use distributed
tracing within C programs.
The OpenTracing project (https://opentracing.io/) has published a
C-language implementation on https://github.com/opentracing/opentracing-c
but that implementation is incomplete, with the last update on Jun
27th 2018
This library takes inspiration from the header files in that project but
implements the proposed functionality fully by wrapping the functional
C++ library.
2. Build instructions
------------------------------------------------------------------------
Prerequisites for configuring and compiling the OpenTracing C Wrapper:
----------------------------------------------------------------------
* GNU GCC Compiler and Development Environment
The main components of this system are C standard library, C and C++
compilers, make and cmake utilities and other development tools that are
not explicitly listed because they depend on the system on which we want
to compile the OpenTracing C Wrapper.
The program itself is very likely possible to compile with another C
compiler (non-GCC), but I'm not sure about the other required libraries.
On debian-like linux systems it is necessary to run the following, in
order to install development packages:
# apt-get install automake autoconf make cmake libc6-dev gcc g++ binutils libtool pkgconf gawk git
* GNU autoconf
https://www.gnu.org/software/autoconf/
* GNU automake
https://www.gnu.org/software/automake/
* POSIX threads library
* C++ implementation of the OpenTracing API http://opentracing.io
https://github.com/opentracing/opentracing-cpp
* the tracing plugins (one of the following may be used):
* Jaeger SDK with OpenTracing API for C++ binding
https://github.com/jaegertracing/jaeger-client-cpp
* the LightStep distributed tracing library for C++
https://github.com/lightstep/lightstep-tracer-cpp
* OpenTracing implementation for Zipkin in C++
https://github.com/rnburn/zipkin-cpp-opentracing
* Datadog OpenTracing C++ Client
https://github.com/DataDog/dd-opentracing-cpp
Note: prompt '%' indicates that the command is executed under a unprivileged
user, while prompt '#' indicates that the command is executed under the
root user.
Compiling and installing the opentracing-cpp library:
-----------------------------------------------------
The assumption is that we want to install the library in the /opt directory.
% wget https://github.com/opentracing/opentracing-cpp/archive/v1.5.0.tar.gz
% tar xf v1.5.0.tar.gz
% cd opentracing-cpp-1.5.0
% mkdir build
% cd build
% cmake -DCMAKE_INSTALL_PREFIX=/opt ..
% make
# make install
Of course, we can take another version of the library (or download the master
branch via git). For example, this version is used here due to compatibility
with the Jaeger plugin, which I mostly used when testing the operation of the
program.
Compiling and installing the opentracing-c-wrapper library:
-----------------------------------------------------------
We will also install this library in the /opt directory, and when configuring
the library we must specify where the opentracing-cpp library is located.
In this example we will install two builds of the library, first the
release version and then the debug version.
% git clone https://github.com/haproxytech/opentracing-c-wrapper.git
% cd opentracing-c-wrapper
% ./scripts/bootstrap
% ./configure --prefix=/opt --with-opentracing=/opt
% make
# make install
% ./scripts/distclean
% ./scripts/bootstrap
% ./configure --prefix=/opt --enable-debug --with-opentracing=/opt
% make
# make install
Compiling the Jaeger tracing plugin:
------------------------------------
We will use the 1.5.0 version of the plugin, a newer one can be taken (or
the git master branch) if you want to try it (as is the case with previous
libraries, you can try a newer version).
Important note: the GCC version must be at least 4.9 or later.
% wget https://github.com/jaegertracing/jaeger-client-cpp/archive/v0.5.0.tar.gz
% tar xf v0.5.0.tar.gz
% cd jaeger-client-cpp-0.5.0
% mkdir build
% cd build
% cmake -DCMAKE_INSTALL_PREFIX=/opt -DJAEGERTRACING_PLUGIN=ON -DHUNTER_CONFIGURATION_TYPES=Release -DHUNTER_BUILD_SHARED_LIBS=OFF ..
% make
After the plugin is compiled, it will be in the current directory.
The name of the plugin is libjaegertracing_plugin.so.
Of course, we can download the precompiled version of the Jaeger plugin
(unfortunately, the latest version that can be downloaded is 0.4.2).
% wget https://github.com/jaegertracing/jaeger-client-cpp/releases/download/v0.4.2/libjaegertracing_plugin.linux_amd64.so
3. Testing the operation of the library
------------------------------------------------------------------------
Testing of the library can be done through the test program, which is located
in the eponymous directory 'test'. In this directory there is also a script
with which we can download opentracing plugins from all supported tracers.
As a script argument we can specify the directory to which the plugins are
downloaded. If we do not specify this argument then the download is done to
the current directory. In our example we will place the downloaded plugins
in the 'test' directory:
% ./test/get-opentracing-plugins.sh test
The options supported by the test program can be found using the '-h' option:
% ./test/ot-c-wrapper-test_dbg -h
--- help output -------
Usage: ot-c-wrapper-test_dbg { -h --help }
ot-c-wrapper-test_dbg { -V --version }
ot-c-wrapper-test_dbg { [ -R --runcount=VALUE ] | [ -r --runtime=TIME ] } [OPTION]...
Options are:
-c, --config=FILE Specify the configuration for the used tracer.
-d, --debug=LEVEL Enable and specify the debug mode level (default: 0).
-h, --help Show this text.
-p, --plugin=FILE Specify the OpenTracing compatible plugin library.
-R, --runcount=VALUE Execute this program a certain number of passes (0 = unlimited).
-r, --runtime=TIME Run this program for a certain amount of time (ms, 0 = unlimited).
-t, --threads=VALUE Specify the number of threads (default: 1000).
-V, --version Show program version.
Copyright 2020 HAProxy Technologies
SPDX-License-Identifier: Apache-2.0
--- help output -------
In case we did not use the '--enable-debug' option when configuring the
library, the test program will be named ot-c-wrapper-test.
Example of using the test program:
% ./test/ot-c-wrapper-test -r 10000 -c test/cfg-jaeger.yml -p test/libjaeger_opentracing_plugin-0.4.2.so
'-r' is the option that must be specified when launching a program. It is
used to prevent the test program from starting unnecessarily when testing the
program options, or printing the test program help. In addition, with this
option, the test program runtime is set. If the time is set to 0, the test
program runtime is unlimited. In the example above, the runtime is set to
10 seconds.
With the '-c' option, we specify the configuration of the used tracer (in this
case it is Jeager); while the '-p' option selects the plugin library that the
selected tracer uses.
The test directory contains several configurations prepared for supported
tracers:
- cfg-dd.json - Datadog tracer
- cfg-jaeger.yml - Jaeger tracer
- cfg-zipkin.json - Zipkin tracer
Jaeger docker image installation:
---------------------------------
Installation instructions can be found on the website
https://www.jaegertracing.io/download/. For the impatient, here we will list
how the image to test the operation of the tracer system can be installed
without much reading of the documentation.
# docker pull jaegertracing/all-in-one:latest
# docker run -d --name jaeger -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 14268:14268 -p 9411:9411 jaegertracing/all-in-one:latest
The last command will also initialize and run the Jaeger container.
If we want to use that container later, it can be started and stopped
in the classic way, using the 'docker container start/stop' commands.
4. Basic concepts in the OpenTracing
------------------------------------------------------------------------
Basic concepts of the OpenTracing can be read on the OpenTracing documentation
website https://opentracing.io/docs/overview/.
Here we will list only the most important elements of distributed tracing and
these are 'trace', 'span' and 'span context'. Trace is a description of the
complete transaction we want to record in the tracing system. A span is an
operation that represents a unit of work that is recorded in a tracing system.
Span context is a group of information related to a particular span that is
passed on to the system (from service to service). Using this context, we can
add new spans to already open trace (or supplement data in already open spans).
An individual span may contain one or more tags, logs and baggage items.
The tag is a key-value element that is valid for the entire span. Log is a
key-value element that allows you to write some data at a certain time, it
can be used for debugging. A baggage item is a key-value data pair that can
be used for the duration of an entire trace, from the moment it is added to
the span.
5. Tracing example
------------------------------------------------------------------------
In the example, whose source is in the 'test' directory, the operation of the
OpenTracing C Wrapper is checked. 5 spans are created in which tags, logs and
baggage are placed; and data propagation via text map, http header and binary
data is checked.
root span |------------------------------------------------------------------|
span #1 |----------------------------------------------------------|
text map propagation |--------------------------------------------------|
http headers propagation |------------------------------------------|
binary data propagation |----------------------------------|
6. Known bugs and limitations
------------------------------------------------------------------------
The library does not know whether the data was sent to the tracer or not,
because sending is done in a separate thread that does not affect the
operation of the rest of the program.
One should not exaggerate with the number of competing threads that send data
to their tracers as this can slow down the sending of data to the tracer.
|