Quick Overview
OpenTelemetry C++ is an open-source observability framework for cloud-native software. It provides a collection of tools, APIs, and SDKs to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior.
Pros
- Vendor-agnostic and compatible with various backends and analysis tools
- Supports multiple data types (traces, metrics, logs) for comprehensive observability
- Highly extensible and customizable to fit various use cases
- Part of the larger OpenTelemetry ecosystem, benefiting from community support and standardization
Cons
- Steeper learning curve compared to some simpler logging or metrics libraries
- Documentation can be complex for newcomers to distributed tracing and observability
- Still evolving, which may lead to occasional breaking changes or API adjustments
- Performance overhead, though minimal, needs to be considered for high-throughput systems
Code Examples
- Creating a tracer and recording a span:
#include "opentelemetry/sdk/trace/simple_processor.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/trace/provider.h"
namespace trace = opentelemetry::trace;
namespace trace_sdk = opentelemetry::sdk::trace;
int main() {
auto provider = trace_sdk::TracerProvider::Create();
auto tracer = provider->GetTracer("example_tracer");
auto span = tracer->StartSpan("MyOperation");
// Perform your operation here
span->End();
return 0;
}
- Adding attributes to a span:
auto span = tracer->StartSpan("MyOperation");
span->SetAttribute("http.method", "GET");
span->SetAttribute("http.url", "https://example.com");
span->End();
- Creating a metric and recording measurements:
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/sdk/metrics/meter_provider.h"
namespace metrics = opentelemetry::metrics;
namespace metrics_sdk = opentelemetry::sdk::metrics;
int main() {
auto provider = metrics_sdk::MeterProvider::Create();
auto meter = provider->GetMeter("example_meter");
auto counter = meter->CreateUInt64Counter("my_counter");
counter->Add(1);
return 0;
}
Getting Started
- Install OpenTelemetry C++ using your preferred package manager or build from source.
- Include the necessary headers in your project.
- Initialize the OpenTelemetry SDK:
#include "opentelemetry/sdk/trace/simple_processor.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/trace/provider.h"
int main() {
auto exporter = std::unique_ptr<sdktrace::SpanExporter>(new otlp::OtlpHttpExporter());
auto processor = std::unique_ptr<sdktrace::SpanProcessor>(new sdktrace::SimpleSpanProcessor(std::move(exporter)));
auto provider = nostd::shared_ptr<opentelemetry::trace::TracerProvider>(new sdktrace::TracerProvider(std::move(processor)));
// Set the global trace provider
opentelemetry::trace::Provider::SetTracerProvider(provider);
// Use the tracer in your application
auto tracer = opentelemetry::trace::Provider::GetTracerProvider()->GetTracer("my_library_name", "1.0.0");
// Your application code here
return 0;
}
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
OpenTelemetry C++
The C++ OpenTelemetry client.
Project Status
Stable across all 3 signals i.e. Logs
, Metrics
, and Traces
.
See Spec Compliance Matrix to understand which portions of the specification has been implemented in this repo.
Supported C++ Versions
Code shipped from this repository generally supports the following versions of C++ standards:
- ISO/IEC 14882:2014 (C++14)
- ISO/IEC 14882:2017 (C++17)
- ISO/IEC 14882:2020 (C++20)
Any exceptions to this are noted in the individual README.md
files.
Please note that supporting the C Programming Language is not a goal of the current project.
Supported Development Platforms
Our CI pipeline builds and tests on following x86-64
platforms:
Platform | Build type |
---|---|
ubuntu-22.04 (GCC 10, GCC 12, Clang 14) | CMake, Bazel |
ubuntu-20.04 (GCC 9.4.0 - default compiler) | CMake, Bazel |
ubuntu-20.04 (GCC 9.4.0 with -std=c++14/17/20 flags) | CMake, Bazel |
macOS 12.7 (Xcode 14.2) | Bazel |
Windows Server 2019 (Visual Studio Enterprise 2019) | CMake, Bazel |
Windows Server 2022 (Visual Studio Enterprise 2022) | CMake |
In general, the code shipped from this repository should build on all platforms having C++ compiler with supported C++ standards.
Dependencies
Please refer to Dependencies.md for OSS Dependencies and license requirements.
Installation
Please refer to INSTALL.md.
Getting Started
As an application owner or the library author, you can find the getting started guide and reference documentation on opentelemetry-cpp.readthedocs.io
The examples/simple
directory contains a minimal program demonstrating how to
instrument a small library using a simple processor
and console exporter
,
along with build files for CMake and Bazel.
Contributing
See CONTRIBUTING.md
We meet weekly, and the time of the meeting alternates between Monday at 13:00 PT and Wednesday at 9:00 PT. The meeting is subject to change depending on contributors' availability. Check the OpenTelemetry community calendar for specific dates and Zoom meeting links.
Meeting notes are available as a public Google doc. For edit access, get in touch on Slack.
Maintainers (@open-telemetry/cpp-maintainers):
- Ehsan Saei
- Lalit Kumar Bhasin, Microsoft
- Marc Alff, Oracle
- Tom Tan, Microsoft
Approvers (@open-telemetry/cpp-approvers):
- Josh Suereth, Google
- Pranav Sharma, Google
- WenTao Ou, Tencent
Emeritus Maintainer/Approver/Triager:
Thanks to all the people who have contributed
Release Schedule
See the release notes for existing releases.
See the project milestones for details on upcoming releases. The dates and features described in issues and milestones are estimates, and subject to change.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot