-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME
More file actions
1210 lines (889 loc) · 43.4 KB
/
README
File metadata and controls
1210 lines (889 loc) · 43.4 KB
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-----------------------------------------------------------------
C wrapper for the C++ OpenTelemetry API, enabling C integration
-----------------------------------------------------------------
Summary
------------------------------------------------------------------------------
1. Introduction
2. Build instructions
2.1. Prerequisites for building the OTel C wrapper library
2.2. Compiling and installing the OTel C++ client
2.3. Compiling and installing the OTel C wrapper library
3. Testing the operation of the library
4. Basic concepts of OpenTelemetry
5. Library API overview
6. YAML configuration
6.1. Document structure
6.2. Exporters
6.3. Samplers
6.4. Processors
6.5. Readers
6.6. Providers
6.7. Signals
6.8. Environment variables
7. Tracing example
8. Metrics example
9. Logging example
10. Thread safety
11. Known bugs and limitations
1. Introduction
------------------------------------------------------------------------------
This document will not cover the internal structure of OpenTelemetry (often
abbreviated as OTel) or the environment that led to the need for an
observability framework. Those interested can find detailed reasons for its use
and relevant documentation in many sources, especially on the official OTel
website https://opentelemetry.io/ .
The OTel C wrapper library was primarily developed for use in the HAProxy OTel
filter to enable effective observation - specifically, exporting telemetry data
to simplify the analysis of software performance and behavior.
This library is a C wrapper for the official OTel C++ client, with the source
repository available at https://github.com/open-telemetry/opentelemetry-cpp .
2. Build instructions
------------------------------------------------------------------------------
2.1. Prerequisites for building the OTel C wrapper library
------------------------------------------------------------------------------
To simplify the process of compiling all the libraries required by the OTel C
wrapper, several shell scripts have been created and are available in the
scripts/build directory. All scripts have been tested on the following Linux
distributions for the amd64 architecture:
* debian 11 / 12 / 13
* ubuntu 20.04.6 / 22.04.5 / 24.04.3 / 25.10
* tuxedo 24.04.3
* rhel 8.10 / 9.5 / 10.0
* rocky 9.5
* opensuse-leap 15.5 / 15.6
Linux distributions for other architectures, as well as other operating systems
supported by the OTel C++ client (such as BSD, macOS, and Windows), have not
been tested.
To install all the required packages for compiling and installing the OTel C
wrapper library, execute the linux-update.sh script located in the scripts/build
directory:
# cd scripts/build
# ./linux-update.sh
Note: the '%' prompt indicates that the command is being executed by a non-
privileged user, whereas the '#' prompt indicates that the command is
being executed by the root user.
The script linux-update.sh does not accept any arguments.
To summarize, the script installs the necessary packages for compiling and
setting up all required libraries, with the most important ones being:
* GNU GCC Compiler and Development Environment
* GNU autoconf / automake / libtool / make
* Kitware CMake
* various developer packages of the system libraries (libc, curl, ssl, zlib,
lzma, systemd)
* various utilities for downloading source code repositories (git, wget, curl)
2.2. Compiling and installing the OTel C++ client
------------------------------------------------------------------------------
Installing all the prerequisite libraries can be quite demanding, which is why
several installation scripts have been created to simplify the process. Each
prerequisite library has its own dedicated installation script, but it is not
recommended to run them separately. Instead, it's advised to use one of the
following two scripts:
* build.sh - each prerequisite library is compiled and installed individually,
following a predefined order
* build-bundle.sh - the OTel C++ client is compiled in such a way that it
automatically downloads and compiles all the necessary prerequisite
libraries
It is strongly recommended to use the provided build scripts rather than relying
on system-installed dependency packages, which are likely outdated or compiled
with options incompatible with the OTel C wrapper.
If none of the attached build-*.sh scripts is used, the patches in
scripts/build/ must be applied to the OpenTelemetry C++ source tree before
compilation and the same CMake configuration options found in
scripts/build/opentelemetry-cpp-1.26.0-install.sh must be used.
Whichever script is used, the result should be the same. However, it is
recommended to use the build-bundle.sh script for this task. In that script,
the AWS-LC and curl build steps are commented out by default, so the script uses
the OpenSSL and curl libraries present on the system. An SSL library (OpenSSL
or another supported implementation) must be installed on the system; if
curl is not available, the OTel C++ build process downloads and compiles it
automatically. Users can uncomment the AWS-LC and curl steps if they prefer to
build those from source as well.
Example of how to run an installation script:
# cd scripts/build
# ./build-bundle.sh
Both scripts accept multiple input arguments. The first argument specifies the
destination directory where packages will be installed, and the second argument
defines the location of the root directory for installation. However, it is not
recommended to set the 'install-dir' argument, as it is intended solely for
debugging purposes.
# ./build-bundle.sh [ prefix-dir [ install-dir ] ]
By default, libraries are installed in the /opt directory (prefix = '/opt').
Finally, the installation script will verify that all library dependencies for
programs in the <prefix>/bin directory and libraries in the <prefix>/lib
directory are met, which is done by running the ldd utility.
Note: it is possible that some prerequisite libraries are already installed on
the system (as part of the operating system). This can lead to errors
when compiling the OTel C++ client. For this reason, it is recommended to
use the provided script for installation and to install it in a non-system
directory, such as /opt, /usr/local, or any other non-system directory of
your choice.
If one prefers to use the AWS-LC cryptographic library instead of the
system-installed OpenSSL, the AWS-LC and curl build steps can be uncommented in
the installation scripts.
List of (almost) all dependencies for the OTel C++ client package:
* AWS libcrypto (AWS-LC)
https://github.com/aws/aws-lc
* curl - a command-line tool for transferring data from or to a server using
URLs
https://github.com/curl/curl
* Abseil - C++ Common Libraries
https://github.com/abseil/abseil-cpp
* c-ares - a modern DNS (stub) resolver library
https://github.com/c-ares/c-ares
* RE2, a regular expression library
https://github.com/google/re2
* Protocol Buffers - Google's data interchange format
https://github.com/protocolbuffers/protobuf
* JSON for Modern C++
https://github.com/nlohmann/json
* GoogleTest - Google's C++ test framework
https://github.com/google/googletest
* Benchmark - a library to benchmark code snippets, similar to unit tests
https://github.com/google/benchmark
* gRPC - an RPC library and framework
https://github.com/grpc/grpc
* Rapid YAML - a C++ library to parse and emit YAML
https://github.com/biojppm/rapidyaml
* OpenTelemetry C++ - the C++ OpenTelemetry client
https://github.com/open-telemetry/opentelemetry-cpp
This is not a complete list of dependencies; other libraries present on the
operating system, such as libidn, libpsl, libunistring, zlib, and libzstd, are
also required.
Additional information on this topic can be found at:
https://github.com/open-telemetry/opentelemetry-cpp/blob/main/docs/dependencies.md
2.3. Compiling and installing the OTel C wrapper library
------------------------------------------------------------------------------
Along with the OTel C++ client, the OTel C wrapper library depends on a YAML
parsing library. By default, rapidyaml (ryml) is used, and this is the
recommended configuration. Since rapidyaml is already built and installed as
part of the OTel C++ client dependencies, no additional steps are required.
Alternatively, libfyaml can be used instead by explicitly specifying the
--with-libfyaml option (autotools) or -DWITH_LIBFYAML=ON (CMake). Both
options cannot be used at the same time.
* Rapid YAML - a C++ library to parse and emit YAML
https://github.com/biojppm/rapidyaml
* libfyaml - a fully-featured YAML 1.2 and JSON parser/writer
https://github.com/pantoniou/libfyaml
Once the OTel C++ client is installed, the OTel C wrapper library can be
compiled and installed. It can also be built in debug mode, which enables
detailed logging of the library's operations, such as internal function
calls.
In this example, we will install two versions of the library: the release
version first, followed by the debug version. Both versions will be installed
in the /opt directory.
% git clone https://github.com/haproxytech/opentelemetry-c-wrapper.git
% cd opentelemetry-c-wrapper
% ./scripts/bootstrap
% ./configure --prefix=/opt --with-opentelemetry=/opt
% make
# make install
% ./scripts/distclean
% ./scripts/bootstrap
% ./configure --prefix=/opt --with-opentelemetry=/opt --enable-debug
% make
# make install
Alternatively, the library can be compiled using CMake:
% mkdir build && cd build
% cmake -DCMAKE_INSTALL_PREFIX=/opt -DOPENTELEMETRY_DIR=/opt ..
% make
# make install
To build the debug version, add the -DENABLE_DEBUG=ON option to the cmake
command above.
3. Testing the operation of the library
------------------------------------------------------------------------------
The library includes a test suite located in the test/ directory. Test
programs are not compiled during the regular build; use 'make test' to compile
them. The main test program simulates a worker process that generates traces,
metrics, and logs.
% make test
% cd test
% ./otel-c-wrapper-test --help
% ./otel-c-wrapper-test --runcount=10 --threads=8
The test program uses otel-cfg.yml as its library configuration file.
When built with the debug option, the test binary is named
otel-c-wrapper-test_dbg. If present at install time, the test binary is
installed into the <prefix>/bin directory by 'make install'.
For integration testing with an OpenTelemetry Collector and a backend (like
Elasticsearch/Kibana or ClickHouse), you can use the Docker Compose setup
provided in `test/elastic-apm/`.
A reference OpenTelemetry Collector configuration is provided in test/otelcol/.
The OpenTelemetry Collector source is available at
https://github.com/open-telemetry/opentelemetry-collector . The configuration
collects all three signals (traces, metrics, and logs) over OTLP/gRPC and
OTLP/HTTP, and exports traces to a Jaeger instance reachable at a local IP
address via OTLP/HTTP.
% cd test/elastic-apm
% docker compose up -d
Ensure that the `otel-cfg.yml` configuration file is correctly set up to point
to the collector's endpoint.
4. Basic concepts of OpenTelemetry
------------------------------------------------------------------------------
OpenTelemetry (OTel) is an observability framework for cloud-native software.
It provides a standardized, vendor-neutral way to create and collect telemetry
data (traces, metrics, and logs). Understanding its core concepts is key to
using this wrapper library effectively.
The main components of OTel are:
* Signals: OTel classifies telemetry data into several categories, known as
signals. The three primary signals are traces, metrics, and logs. This
library currently supports traces, metrics, and logs.
* API (Application Programming Interface): This is a set of interfaces that
you use to instrument your code. For example, you use the API to get a
tracer, start a span, or record a metric. The API is decoupled from the
implementation.
* SDK (Software Development Kit): This is the official implementation of the
API. The SDK provides the configuration and logic for processing telemetry
data. It allows you to configure exporters, processors, and samplers.
* Exporter: An exporter is a component that sends telemetry data to a specific
backend or collector. For example, you might use an OTLP (OpenTelemetry
Protocol) exporter to send data to an OTel Collector, or a Jaeger exporter
to send data directly to a Jaeger instance.
* Collector: The OTel Collector is a standalone service that can receive,
process, and export telemetry data. It acts as a flexible pipeline,
allowing you to transform and filter data before it reaches your
observability backend.
Key concepts related to tracing:
* Trace: A trace represents the entire journey of a request as it moves
through all the services in a distributed system. A single trace is
composed of one or more spans.
* Span: A span represents a single unit of work or operation within a trace,
such as an HTTP request, a database query, or a function call. Spans have
a start time, an end time, attributes (key-value pairs), events (timestamped
log messages), links (references to related spans in other traces), and a
status.
* Context Propagation: This is the mechanism that allows OTel to correlate
spans across different services. When a service makes a call to another
service, context (which includes the current trace ID and span ID) is
injected into the request (e.g., as HTTP headers). The receiving service
extracts this context to create a new child span, linking it to the parent
span in the calling service.
For a more in-depth understanding, it is highly recommended to review the
official OpenTelemetry documentation: https://opentelemetry.io/docs/concepts/
5. Library API overview
------------------------------------------------------------------------------
The library provides a pure C API on top of the OpenTelemetry C++ SDK. The API
is organized around instance structs that each carry a pointer to an
operations vtable (a struct of function pointers), one pair per telemetry
signal:
* struct otelc_tracer - creates trace spans and propagates context
* struct otelc_meter - creates and records metric instruments
* struct otelc_logger - emits structured log records
Every instance struct carries an 'err' member (a character pointer holding the
last error message), a 'scope_name' member (the instrumentation scope name read
from the YAML configuration), and an 'ops' pointer to the operations vtable.
Operations are invoked through the ops pointer:
tracer->ops->start_span(tracer, "name")
The header <opentelemetry-c-wrapper/define.h> provides the convenience macros
OTELC_OPS() and OTELC_OPSR() (the latter passes &ptr so the callee can set the
pointer to NULL on destroy/end):
OTELC_OPS(tracer, start_span, "name")
OTELC_OPSR(span, end)
The typical usage follows this lifecycle:
1. otelc_init(cfgfile, &err) - parse the YAML configuration file
2. otelc_*_create(&err) - allocate a signal instance
3. instance->ops->start(instance) - start the signal pipeline
4. (use the signal) - create spans, record metrics, logs
5. otelc_deinit(...) - shut down all signals, free memory
The otelc_deinit() function accepts pointers to all three signal types and
destroys whichever ones are non-NULL:
otelc_deinit(&tracer, &meter, &logger);
Functions that can fail return OTELC_RET_OK (0) on success or OTELC_RET_ERROR
(-1) on failure. Functions that create resources return a pointer on success or
NULL on failure.
The library also provides several utility types for passing structured data to
the API:
* struct otelc_value - a tagged union for bool, integer, double, and
string values
* struct otelc_kv - a key-value pair (key string + otelc_value)
* struct otelc_text_map - a dynamic array of key-value string pairs
Additional utility functions complete the public API:
* otelc_ext_init() - register custom malloc/free/thread-ID
* otelc_log_set_handler() - install an SDK diagnostic log callback
* otelc_log_set_level() - set the SDK internal log level
* otelc_processor_dropped_count() - query dropped span/log counts
* otelc_span_context_create() - construct a span context from raw IDs
All public headers reside under include/opentelemetry-c-wrapper/. Including
<opentelemetry-c-wrapper/include.h> pulls in all of them.
6. YAML configuration
------------------------------------------------------------------------------
The library reads its configuration from a YAML file whose path is passed to
the otelc_init() function. Named pipeline components are defined in top-level
sections and bound together per signal type in the 'signals' section. All
string values have a maximum length of 4095 characters. Boolean values accept
"true" / "1" for true and "false" / "0" for false (case-insensitive).
6.1. Document structure
------------------------------------------------------------------------------
The YAML file contains the following top-level sections:
* exporters - define where telemetry data is sent
* samplers - control trace sampling strategy (traces only)
* processors - define how telemetry is batched before export (traces and logs
only)
* readers - configure periodic metric collection intervals (metrics only)
* providers - set resource attributes attached to all telemetry
* signals - bind the above components together per signal type
Each section (except 'signals') contains named configuration blocks. The
'signals' section references these blocks by name, either as a single name or
as a YAML list of names.
Here is a minimal configuration that exports traces to stdout:
exporters:
my_exporter:
type: ostream
filename: /dev/stdout
processors:
my_processor:
type: single
samplers:
my_sampler:
type: always_on
providers:
my_provider:
resources:
- service.name: "my-service"
signals:
traces:
scope_name: "my-application"
exporters: my_exporter
samplers: my_sampler
processors: my_processor
providers: my_provider
A complete configuration covering all three signals and multiple exporter types
can be found in the file test/otel-cfg.yml.
6.2. Exporters
------------------------------------------------------------------------------
Exporters define where telemetry data is sent. Each named exporter block must
include a 'type' key that selects the exporter backend. The available exporter
types and their signal support are:
Type Traces Metrics Logs
---- ------ ------- ----
otlp_file yes yes yes
otlp_grpc yes yes yes
otlp_http yes yes yes
ostream yes yes yes
memory yes yes no
zipkin yes no no
elasticsearch no no yes
Exporter availability depends on the build configuration; unsupported types
produce an error at startup.
The configuration keys for each exporter type are listed below. All keys are
optional unless noted otherwise.
OTLP File exporter (otlp_file)
Writes telemetry data to rotating files in OTLP format.
type (string, mandatory)
Must be "otlp_file".
thread_name (string, default: "")
Name assigned to the exporter's background thread.
file_pattern (string, default: "otel-logfile-%F-%N.txt")
Output file naming pattern.
alias_pattern (string, default: "")
Symbolic link or alias pattern for the current output file.
flush_interval (integer, default: 30000000, range: 100000-60000000)
Flush interval in microseconds.
flush_count (integer, default: 256, range: 16-8192)
Number of records buffered before flushing to disk.
file_size (integer, default: 20971520, range: 65536-2147483648)
Maximum file size in bytes (64 KB to 2 GB).
rotate_size (integer, default: 3, range: 1-256)
Number of rotated files to retain.
OTLP gRPC exporter (otlp_grpc)
Sends telemetry data to a collector over gRPC.
type (string, mandatory)
Must be "otlp_grpc".
thread_name (string, default: "")
Read from YAML for configuration consistency but not used by the SDK, as
gRPC exporters do not support runtime thread naming.
endpoint (string)
Server endpoint URL. Signal-specific defaults:
traces: "http://localhost:4317/v1/traces"
metrics: "http://localhost:4317/v1/metrics"
logs: "http://localhost:4317/v1/logs"
use_ssl_credentials (boolean, default: false)
Enable TLS for the gRPC connection.
ssl_credentials_cacert_path (string, default: "")
Path to a CA certificate file for server verification.
ssl_credentials_cacert_as_string (string, default: "")
CA certificate content provided as an inline string.
ssl_client_key_path (string, default: "")
Path to the client private key. Requires the SDK MTLS build flag
(ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW).
ssl_client_key_string (string, default: "")
Client private key as an inline string. Requires the SDK MTLS build flag.
ssl_client_cert_path (string, default: "")
Path to the client certificate. Requires the SDK MTLS build flag.
ssl_client_cert_string (string, default: "")
Client certificate as an inline string. Requires the SDK MTLS build flag.
timeout (integer, default: 10, range: 1-60)
Request timeout in seconds.
user_agent (string, default: "")
Custom user-agent string sent with each request.
max_threads (integer, default: 0, range: 1-1024)
Maximum number of concurrent gRPC threads. A value of 0 uses the SDK
default.
compression (string, default: "")
Compression algorithm (e.g., "gzip").
max_concurrent_requests (integer, default: 0, range: 1-1024)
Maximum number of concurrent export requests. A value of 0 uses the SDK
default.
OTLP HTTP exporter (otlp_http)
Sends telemetry data to a collector over HTTP using the curl library.
type (string, mandatory)
Must be "otlp_http".
thread_name (string, default: "")
Name assigned to the exporter's background thread.
endpoint (string)
Server endpoint URL. Signal-specific defaults:
traces: "http://localhost:4318/v1/traces"
metrics: "http://localhost:4318/v1/metrics"
logs: "http://localhost:4318/v1/logs"
content_type (string, default: "json")
HTTP request body encoding. Accepted values: "json", "binary".
json_bytes_mapping (string, default: "hexid")
How binary data is encoded in JSON output. Accepted values: "hexid",
"hex", "base64".
use_json_name (boolean, default: false)
Use JSON field names instead of protobuf field names.
debug (boolean, default: false)
Enable debug logging for HTTP requests. When enabled, the SDK internal
log level is also raised to Debug.
timeout (integer, default: 10, range: 1-60)
Request timeout in seconds.
http_headers (map, default: none)
Custom HTTP headers sent with each request. Specified as a YAML sequence
of key-value pairs:
http_headers:
- X-Custom-Header: "value"
- Authorization: "Bearer token"
max_concurrent_requests (integer, default: 64, range: 1-1024)
Maximum number of concurrent HTTP requests.
max_requests_per_connection (integer, default: 8, range: 1-1024)
Maximum number of requests sent over a single HTTP connection before
reconnecting.
background_thread_wait_for (integer, default: 0, range: 0-3600000)
How long the curl background thread waits (in milliseconds) after its last
request before exiting. A value of 0 keeps the thread alive indefinitely,
which prevents crashes caused by thread respawn failures in the SDK's
noexcept MaybeSpawnBackgroundThread() call. Requires the corresponding
SDK patch (see scripts/build/).
ssl_insecure_skip_verify (boolean, default: false)
Skip TLS certificate verification.
ssl_ca_cert_path (string, default: "")
Path to a CA certificate file for server verification.
ssl_ca_cert_string (string, default: "")
CA certificate content provided as an inline string.
ssl_client_key_path (string, default: "")
Path to the client private key.
ssl_client_key_string (string, default: "")
Client private key as an inline string.
ssl_client_cert_path (string, default: "")
Path to the client certificate.
ssl_client_cert_string (string, default: "")
Client certificate as an inline string.
ssl_min_tls (string, default: "")
Minimum TLS protocol version (e.g., "1.2").
ssl_max_tls (string, default: "")
Maximum TLS protocol version (e.g., "1.3").
ssl_cipher (string, default: "")
TLS cipher list for TLS 1.2 and earlier.
ssl_cipher_suite (string, default: "")
TLS ciphersuites for TLS 1.3.
compression (string, default: "")
Compression algorithm (e.g., "gzip").
OStream exporter (ostream)
Writes human-readable telemetry data to a C++ output stream (stdout, stderr,
or a file).
type (string, mandatory)
Must be "ostream".
filename (string, default: "stdout")
Output destination. Accepted values: "stdout", "stderr", or a file path.
In-Memory exporter (memory)
Stores telemetry data in a circular memory buffer. Supported for traces and
metrics only.
type (string, mandatory)
Must be "memory".
buffer_size (integer, range: 16-65536)
Maximum number of records in the circular buffer. Defaults to the SDK's
MAX_BUFFER_SIZE value.
Zipkin exporter (zipkin)
Sends trace data to a Zipkin backend. Supported for traces only.
type (string, mandatory)
Must be "zipkin".
endpoint (string, default: "http://localhost:9411/api/v2/spans")
Zipkin collector endpoint URL.
format (string, default: "")
Transport format. Accepted values: "json", "protobuf". When empty, the
SDK default is used.
service_name (string, default: "default-service")
Service name reported to Zipkin.
ipv4 (string, default: "")
IPv4 address of the service endpoint.
ipv6 (string, default: "")
IPv6 address of the service endpoint.
Elasticsearch exporter (elasticsearch)
Sends log records to an Elasticsearch cluster. Supported for logs only.
type (string, mandatory)
Must be "elasticsearch".
host (string, default: "localhost")
Elasticsearch server hostname.
port (integer, default: 9200, range: 1-65535)
Elasticsearch server port.
index (string, default: "logs")
Index name where log records are stored.
response_timeout (integer, default: 30, range: 1-3600)
Response timeout in seconds.
debug (boolean, default: false)
Enable debug logging for Elasticsearch requests.
http_headers (map, default: none)
Custom HTTP headers. Uses the same YAML format as the OTLP HTTP
exporter's http_headers option.
6.3. Samplers
------------------------------------------------------------------------------
Samplers control which traces are recorded and exported. They are configured
in the top-level 'samplers' section and referenced from the traces signal. Only
one sampler is active per tracer.
type (string, default: "trace_id_ratio_based")
Sampler type. Accepted values: "always_on", "always_off",
"trace_id_ratio_based", "parent_based".
Type "always_on" samples every trace unconditionally. No additional
configuration keys.
Type "always_off" rejects every trace unconditionally. No additional
configuration keys.
Type "trace_id_ratio_based" samples traces based on a configurable
probability. Additional key:
ratio (double, default: 1.0, range: 0.0-1.0)
Probability that a trace is sampled. A value of 0.0 means no traces are
sampled; 1.0 means all traces are sampled.
Type "parent_based" delegates the sampling decision based on the parent span's
context. When no parent span exists, the delegate sampler is used. Additional
keys:
delegate (string, default: "always_on")
Root sampler used when there is no parent span. Accepted values:
"always_on", "always_off", "trace_id_ratio_based".
ratio (double, default: 1.0, range: 0.0-1.0)
Sampling ratio for the delegate, used only when delegate is set to
"trace_id_ratio_based".
remote_sampled (string, default: "always_on")
Sampler applied when the remote parent has the sampled flag set.
Accepted values: "always_on", "always_off".
remote_not_sampled (string, default: "always_off")
Sampler applied when the remote parent does not have the sampled flag.
Accepted values: "always_on", "always_off".
local_sampled (string, default: "always_on")
Sampler applied when the local parent has the sampled flag set.
Accepted values: "always_on", "always_off".
local_not_sampled (string, default: "always_off")
Sampler applied when the local parent does not have the sampled flag.
Accepted values: "always_on", "always_off".
6.4. Processors
------------------------------------------------------------------------------
Processors control how telemetry records are batched and delivered to exporters.
They are used by the traces and logs signals. Metrics use readers instead of
processors (see section 6.5).
type (string, mandatory)
Processor type. Accepted values: "batch", "single".
thread_name (string, default: "")
Name assigned to the processor's background thread (only meaningful in
batch mode).
Type "batch" buffers records in a bounded circular queue and exports them in
batches at regular intervals. Additional keys:
max_queue_size (integer, default: 2048, range: 64-65536)
Maximum number of records the queue can hold. Must be greater than or
equal to max_export_batch_size.
schedule_delay (integer, range: 1-60000)
Time in milliseconds between consecutive export cycles.
Default: 5000 for traces, 1000 for logs.
export_timeout (integer, default: 30000, range: 1-60000)
Maximum time in milliseconds allowed for a single export operation.
max_export_batch_size (integer, default: 512, range: 1-65536)
Maximum number of records per export batch.
When the queue fills up, new records are silently dropped. The library provides
otelc_processor_dropped_count() to monitor drop rates (see section 11 for
details).
Type "single" exports each record immediately without batching. No additional
configuration keys beyond 'type' and 'thread_name'.
6.5. Readers
------------------------------------------------------------------------------
Readers configure periodic metric collection and export. They are used
exclusively by the metrics signal and pair with exporters to form metric
pipelines.
thread_name (string, default: "")
Name assigned to the reader's background thread.
export_interval (integer, default: 60000, range: 100-3600000)
Time in milliseconds between consecutive metric exports.
Must be greater than or equal to export_timeout.
export_timeout (integer, default: 30000, range: 100-3600000)
Maximum time in milliseconds allowed for a single metric export operation.
6.6. Providers
------------------------------------------------------------------------------
Providers define resource attributes that are attached to all telemetry emitted
by a signal. These attributes identify the service producing the data and are
carried in every span, metric data point, and log record.
resources (map)
A YAML sequence of key-value pairs specifying resource attributes:
providers:
my_provider:
resources:
- service.name: "my-service"
- service.version: "1.0.0"
- service.namespace: "production"
- service.instance.id: "host-1"
Any string key-value pair is accepted. Common attributes follow
the OpenTelemetry semantic conventions and include service.name,
service.version, service.namespace, and service.instance.id.
Resource attributes from the YAML file are merged with attributes detected from
environment variables (see section 6.8). YAML attributes take precedence over
environment attributes for duplicate keys.
6.7. Signals
------------------------------------------------------------------------------
The 'signals' section is the central binding point that ties pipeline components
together. Each signal -- traces, metrics, or logs -- references the named
components it needs from the other top-level sections.
When exporters and processors (or readers) are specified as YAML lists, each
entry forms a separate pipeline within the same provider. The library pairs
list entries by position: for traces and logs, processor[i] is paired with
exporter[i]; for metrics, exporter[i] is paired with reader[i]. When one list
is shorter than the other, its last entry is reused for the remaining pairs.
A single scalar name (not a list) is also accepted.
Traces signal
scope_name (string, mandatory)
Instrumentation scope name for the tracer.
exporters (string or list of strings)
Exporter name(s) from the top-level 'exporters' section.
samplers (string)
Sampler name from the top-level 'samplers' section.
processors (string or list of strings)
Processor name(s) from the top-level 'processors' section.
providers (string)
Provider name from the top-level 'providers' section.
Metrics signal
scope_name (string, mandatory)
Instrumentation scope name for the meter.
exporters (string or list of strings)
Exporter name(s) from the top-level 'exporters' section.
readers (string or list of strings)
Reader name(s) from the top-level 'readers' section.
providers (string)
Provider name from the top-level 'providers' section.
Logs signal
scope_name (string, mandatory)
Instrumentation scope name for the logger.
exporters (string or list of strings)
Exporter name(s) from the top-level 'exporters' section.
processors (string or list of strings)
Processor name(s) from the top-level 'processors' section.
providers (string)
Provider name from the top-level 'providers' section.
min_severity (string, default: "TRACE")
Minimum log severity level. Log records below this severity are discarded
before reaching the processor. Accepted values (case-sensitive): TRACE,
TRACE2, TRACE3, TRACE4, DEBUG, DEBUG2, DEBUG3, DEBUG4, INFO, INFO2, INFO3,
INFO4, WARN, WARN2, WARN3, WARN4, ERROR, ERROR2, ERROR3, ERROR4, FATAL,
FATAL2, FATAL3, FATAL4.
6.8. Environment variables
------------------------------------------------------------------------------
Resource attributes can also be set through environment variables, independently
of the YAML file. Attributes from environment variables are detected at startup
and merged with those specified in the YAML providers section. YAML values take
precedence for duplicate keys.
OTEL_RESOURCE_ATTRIBUTES
Comma-separated list of key=value pairs to use as resource attributes.
Example:
export OTEL_RESOURCE_ATTRIBUTES="service.name=test,version=1.0"
OTEL_SERVICE_NAME
Sets the service.name resource attribute. Takes precedence over a
service.name value in OTEL_RESOURCE_ATTRIBUTES.
7. Tracing example
------------------------------------------------------------------------------
Here is a simple example demonstrating how to use the C wrapper library to
create a tracer, start a span, and export it.
```c
#include <stdio.h>
#include <stdlib.h>
#include <opentelemetry-c-wrapper/include.h>
int main(int argc, char **argv)
{
struct otelc_tracer *tracer;
struct otelc_span *span;
char *err = NULL;
/* Initialize the library */
if (otelc_init("otel-cfg.yml", &err) != OTELC_RET_OK) {
fprintf(stderr, "Failed to init: %s\n", err);
free(err);
return 1;
}
/* Create and start a tracer */
tracer = otelc_tracer_create(&err);
if (tracer == NULL) {
fprintf(stderr, "Failed to create tracer: %s\n", err);
free(err);
otelc_deinit(NULL, NULL, NULL);
return 1;
}
if (tracer->ops->start(tracer) != OTELC_RET_OK) {
fprintf(stderr, "Failed to start tracer\n");
otelc_deinit(&tracer, NULL, NULL);
return 1;