An open API service indexing awesome lists of open source software.

https://github.com/datadog/dd-trace-cpp

Datadog APM client for C++
https://github.com/datadog/dd-trace-cpp

cpp datadog tracing

Last synced: 4 days ago
JSON representation

Datadog APM client for C++

Awesome Lists containing this project

README

          

Datadog C++ Tracing Library
===========================

```c++
#include
#include
#include

#include
#include
#include

int main() {
namespace dd = datadog::tracing;

dd::TracerConfig config;
config.service = "my-service";

const auto validated_config = dd::finalize_config(config);
if (!validated_config) {
std::cerr << validated_config.error() << '\n';
return 1;
}

dd::Tracer tracer{*validated_config};
dd::SpanConfig options;

options.name = "parent";
dd::Span parent = tracer.create_span(options);

std::this_thread::sleep_for(std::chrono::seconds(1));

options.name = "child";
dd::Span child = parent.create_child(options);
child.set_tag("foo", "bar");

std::this_thread::sleep_for(std::chrono::seconds(2));
}
```
See the [examples](examples) directory for more extensive usage examples.

## Platform Support
The library has been tested and is compatible on the following CPU architecture, OS and compiler combinations:
- x86_64 and arm64 Linux with GCC 11.4.
- x86_64 and arm64 Linux with Clang 14.
- x86_64 Windows with MSVC 2022.
- arm64 macOS with Apple Clang 15.

## Building and Installation

### Requirements
`dd-trace-cpp` requires a [supported](#platform-support) C++17 compiler.

A recent version of CMake is required (`3.28`), which might not be in your
system's package manager. [bin/install-cmake](bin/install-cmake) is an installer
for a recent CMake, on Linux.

### Building
Build this library from source using [CMake](https://cmake.org).

```shell
git clone 'https://github.com/datadog/dd-trace-cpp'
cd dd-trace-cpp
cmake -B build .
cmake --build build -j
```

By default CMake will generate both static and shared libraries. To build only one of them use
either `BUILD_SHARED_LIBS` or `BUILD_STATIC_LIBS`. Example:

```shell
cmake -B build -DBUILD_SHARED_LIBS=1 .
```

### Installation
Installation places a shared library and public headers into the appropriate system directories
(`/usr/local/[…]`), or to a specified installation prefix. Example:

```shell
# Install dd-trace-cpp into `.install/` within the source repository.
cmake --install build --prefix=.install
```

### Optional: Linking to the shared library
In case you decided to build the shared library:

When building an executable that uses `dd-trace-cpp`, specify the path to
the installed headers using an appropriate `-I` option. If the library was
installed into the default system directories, then the `-I` option is not
needed.
```shell
c++ -I/path/to/dd-trace-cpp/.install/include -c -o my_app.o my_app.cpp
```

When linking an executable that uses `dd-trace-cpp`, specify linkage to the
built library using the `-ldd_trace_cpp` option and an appropriate `-L` option.
If the library was installed into the default system directories, then the `-L`
options is not needed. The `-ldd_trace_cpp` option is always needed.
```shell
c++ -o my_app my_app.o -L/path/to/dd-trace-cpp/.install/lib -ldd_trace_cpp
```

Test
----
Pass `-DDD_TRACE_BUILD_TESTING=1` to `cmake` to include the unit tests in the build.

The resulting unit test executable is `test/tests` within the build directory.
```shell
cmake -B build -DDD_TRACE_BUILD_TESTING=1 .
cmake --build build -j
./build/test/tests
```

Alternatively, [bin/test](bin/test) is provided for convenience.

Contributing
------------
See the [contributing guidelines](CONTRIBUTING.md) and the [maintainer docs](doc/maintainers.md)
for information on the overall structure of the repository.