From fe310797faff234132bc9f052a08de31d76bd029 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 9 Aug 2021 18:04:39 +0530 Subject: [PATCH 1/7] add sdk docs --- docs/public/sdk/GettingStarted.rst | 96 +++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/docs/public/sdk/GettingStarted.rst b/docs/public/sdk/GettingStarted.rst index dba2627b0e..b3718b8112 100644 --- a/docs/public/sdk/GettingStarted.rst +++ b/docs/public/sdk/GettingStarted.rst @@ -1,4 +1,96 @@ Getting started ---------------- +^^^^^^^^^^^^^^^ -TBD +Opentelemetry C++ SDK provides the reference implementation of Opentelemetry C++ API, +and also provides implementation for Processor, Sampler, and core Exporters as per the +specification. + + +Tracing SDK Configuration +^^^^^^^^^^^^^^^^^^^^^^^^^ + +A basic configuration below instantiates the SDK tracer provider and sets to export the traces +to console stream. + +Exporter: +^^^^^^^^ + +An exporter is responsible for sending the telemetry data to a particular backend. +OpenTelemetry offers six tracing exporters out of the box: +- In-Memory Exporter: keeps the data in memory, useful for debugging. +- Jaeger Exporter: prepares and sends the collected telemetry data to a Jaeger backend via UDP and HTTP. +- Zipkin Exporter: prepares and sends the collected telemetry data to a Zipkin backend via the Zipkin APIs. +- Logging Exporter: saves the telemetry data into log streams +- Opentelemetry(otlp) Exporter: sends the data to the Opentelemetry Collector using protobuf/gRPC or protobuf/HTTP. +- ETW Exporter: sends the telemetry data to Event Tracing for Windows (ETW) + +.. code:: cpp + + // logging exporter + auto ostream_exporter = std::unique_ptr(new opentelemetry::exporter::trace::OStreamSpanExporter); + + // memory exporter + auto memory_exporter = std::unique_ptr(new opentelemetry::exporter::memory::InMemorySpanExporter); + + // zipkin exporter + opentelemetry::exporter::zipkin::ZipkinExporterOptions opts; + opts.endpoint = "http://localhost:9411/api/v2/spans" ; // or export OTEL_EXPORTER_ZIPKIN_ENDPOINT="..." + opts.service_name = "default_service" ; + auto zipkin_exporter = std::unique_ptr(new opentelemetry::exporter::zipkin::ZipkinExporter(opts)); + + // Jaeger UDP exporter + opentelemetry::exporter::jaeger::JaegerExporterOptions opts; + opts.server_addr = "localhost"; + opts.server_port = 6831; + auto jaeger_udp_exporter = std::unique_ptr(new opentelemetry::exporter::jaeger::JaegerExporter(opts)); + + // otlp grpc exporter + opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; + opts.endpoint = "localhost::4317"; + opts.use_ssl_credentials = true; + opts.ssl_credentials_cacert_as_string = "ssl-certificate"; + auto otlp_grpc_exporter = std::unique_ptr(new opentelemetry::exporter::otlp::OtlpGrpcExporter(opts)); + + // otlp http exporter + opentelemetry::exporter::otlp::OtlpHttpExporterOptions opts; + opts.url = "http://localhost:4317/v1/traces"; + auto otlp_http_exporter = std::unique_ptr(new opentelemetry::exporter::otlp::OtlpHttpExporter(opts)); + + +Span Processor: +^^^^^^^^^^^^^^ + +Span Processor is initialised with an Exporter. Different Span Processors are offered by Opentelemetry C++ SDK: + +- SimpleSpanProcessor: immediately forwards ended spans to the exporter. +- BatchSpanProcessor: batches the ended spans and send them to exporter in bulk. +- MultiSpanProcessor: Allows multiple span processors to be active and configured at the same time. + +.. code:: cpp + + // simple processor + auto simple_processor = std::unique_ptr( + new sdktrace::SimpleSpanProcessor(std::move(ostream_exporter))); + + // batch processor + sdktrace::BatchSpanProcessorOptions options{}; + auto batch_processor = std::unique_ptr( + new sdktrace::BatchSpanProcessor(std::move(memory_exporter), options)); + + // multi-processor + std::vector> processors{std::move(simple_processor), std::move(batch_processor)}; + auto multi_processor = std::unique_ptr( + new sdktrace::MultiSpanProcessor(std::move(processors)); + +TracerContext +^^^^^^^^^^^^^ + +SDK configuration shared between `TracerProvider` and all the `Tracer` instances created through it. + +.. code:: cpp + auto exporter = std::unique_ptr + (new opentelemetry::exporter::trace::OStreamSpanExporter); + auto processor = std::unique_ptr + (new sdktrace::SimpleSpanProcessor(std::move(exporter))); + auto + auto tracer_context = \ No newline at end of file From 478f6f176483dbbe6859268007444888dd68b61f Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 9 Aug 2021 18:57:26 +0530 Subject: [PATCH 2/7] more docs --- docs/public/sdk/GettingStarted.rst | 94 +++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 22 deletions(-) diff --git a/docs/public/sdk/GettingStarted.rst b/docs/public/sdk/GettingStarted.rst index b3718b8112..4bfccd6e92 100644 --- a/docs/public/sdk/GettingStarted.rst +++ b/docs/public/sdk/GettingStarted.rst @@ -6,17 +6,12 @@ and also provides implementation for Processor, Sampler, and core Exporters as p specification. -Tracing SDK Configuration -^^^^^^^^^^^^^^^^^^^^^^^^^ - -A basic configuration below instantiates the SDK tracer provider and sets to export the traces -to console stream. - -Exporter: +Exporter ^^^^^^^^ An exporter is responsible for sending the telemetry data to a particular backend. OpenTelemetry offers six tracing exporters out of the box: + - In-Memory Exporter: keeps the data in memory, useful for debugging. - Jaeger Exporter: prepares and sends the collected telemetry data to a Jaeger backend via UDP and HTTP. - Zipkin Exporter: prepares and sends the collected telemetry data to a Zipkin backend via the Zipkin APIs. @@ -27,37 +22,43 @@ OpenTelemetry offers six tracing exporters out of the box: .. code:: cpp // logging exporter - auto ostream_exporter = std::unique_ptr(new opentelemetry::exporter::trace::OStreamSpanExporter); + auto ostream_exporter = + std::unique_ptr(new opentelemetry::exporter::trace::OStreamSpanExporter); // memory exporter - auto memory_exporter = std::unique_ptr(new opentelemetry::exporter::memory::InMemorySpanExporter); + auto memory_exporter = + std::unique_ptr(new opentelemetry::exporter::memory::InMemorySpanExporter); // zipkin exporter opentelemetry::exporter::zipkin::ZipkinExporterOptions opts; opts.endpoint = "http://localhost:9411/api/v2/spans" ; // or export OTEL_EXPORTER_ZIPKIN_ENDPOINT="..." opts.service_name = "default_service" ; - auto zipkin_exporter = std::unique_ptr(new opentelemetry::exporter::zipkin::ZipkinExporter(opts)); + auto zipkin_exporter = + std::unique_ptr(new opentelemetry::exporter::zipkin::ZipkinExporter(opts)); // Jaeger UDP exporter opentelemetry::exporter::jaeger::JaegerExporterOptions opts; opts.server_addr = "localhost"; opts.server_port = 6831; - auto jaeger_udp_exporter = std::unique_ptr(new opentelemetry::exporter::jaeger::JaegerExporter(opts)); + auto jaeger_udp_exporter = + std::unique_ptr(new opentelemetry::exporter::jaeger::JaegerExporter(opts)); // otlp grpc exporter opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; opts.endpoint = "localhost::4317"; opts.use_ssl_credentials = true; opts.ssl_credentials_cacert_as_string = "ssl-certificate"; - auto otlp_grpc_exporter = std::unique_ptr(new opentelemetry::exporter::otlp::OtlpGrpcExporter(opts)); + auto otlp_grpc_exporter = + std::unique_ptr(new opentelemetry::exporter::otlp::OtlpGrpcExporter(opts)); // otlp http exporter opentelemetry::exporter::otlp::OtlpHttpExporterOptions opts; opts.url = "http://localhost:4317/v1/traces"; - auto otlp_http_exporter = std::unique_ptr(new opentelemetry::exporter::otlp::OtlpHttpExporter(opts)); + auto otlp_http_exporter = + std::unique_ptr(new opentelemetry::exporter::otlp::OtlpHttpExporter(opts)); -Span Processor: +Span Processor ^^^^^^^^^^^^^^ Span Processor is initialised with an Exporter. Different Span Processors are offered by Opentelemetry C++ SDK: @@ -78,19 +79,68 @@ Span Processor is initialised with an Exporter. Different Span Processors are of new sdktrace::BatchSpanProcessor(std::move(memory_exporter), options)); // multi-processor - std::vector> processors{std::move(simple_processor), std::move(batch_processor)}; + std::vector> + processors{std::move(simple_processor), std::move(batch_processor)}; auto multi_processor = std::unique_ptr( new sdktrace::MultiSpanProcessor(std::move(processors)); +Resource +^^^^^^^^ + +A Resource is an immutable representation of the entity producing telemetry as key-value pair. +The Opentelemetry C++ SDK allow for creation of Resources and for associating them with telemetry. + +.. code:: cpp + + auto resource_attributes = opentelemetry::sdk::resource::ResourceAttributes + { + {"service.name": "shoppingcart"}, + {"service.instance.id": "instance-12"} + }; + auto resource = opentelemetry::sdk::resource::Resource::Create(resource_attributes); + auto received_attributes = resource.GetAttributes(); + // received_attributes contains + // - service.name = shoppingcart + // - service.instance.id = instance-12 + // - telemetry.sdk.name = opentelemetry + // - telemetry.sdk.language = cpp + // - telemetry.sdk.version = + +It is possible to define the custom resource detectors by inhering from +`opentelemetry::sdk::Resource::ResourceDetector` class. + +Sampler +^^^^^^^ + +Sampling is mechanism to control/reducing the number of samples of traces collected and sent to the backend. +Opentelemetry C++ SDK offers four samplers out of the box: + +- AlwaysOnSampler which samples every trace regardless of upstream sampling decisions. +- AlwaysOffSampler which doesn’t sample any trace, regardless of upstream sampling decisions. +- ParentBased which uses the parent span to make sampling decisions, if present. +- TraceIdRatioBased which samples a configurable percentage of traces + +.. code:: cpp + + //AlwaysOnSampler + opentelemetry::sdk::trace::AlwaysOnSampler always_on_sampler; + + //AlwaysOffSampler + opentelemetry::sdk::trace::AlwaysOffSampler always_off_sampler; + + //ParentBasedSampler + opentelemetry::sdk::trace::ParentBasedSampler sampler_off(std::make_shared()); + + //TraceIdRatioBasedSampler - Sample 50% generated spans + double ratio = 0.5; + opentelemetry::sdk::trace::TraceIdRatioBasedSampler s(ratio); + + TracerContext ^^^^^^^^^^^^^ -SDK configuration shared between `TracerProvider` and all the `Tracer` instances created through it. +SDK configuration are shared between `TracerProvider` and all the `Tracer` instances created through `TracerContext`. .. code:: cpp - auto exporter = std::unique_ptr - (new opentelemetry::exporter::trace::OStreamSpanExporter); - auto processor = std::unique_ptr - (new sdktrace::SimpleSpanProcessor(std::move(exporter))); - auto - auto tracer_context = \ No newline at end of file + + auto tracer_context = From 74f587ea3a0c7b0d96c9abd2a6d2f55965ef9dfd Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 9 Aug 2021 19:58:59 +0530 Subject: [PATCH 3/7] more docs --- docs/public/sdk/GettingStarted.rst | 61 +++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/docs/public/sdk/GettingStarted.rst b/docs/public/sdk/GettingStarted.rst index 4bfccd6e92..73301d60cb 100644 --- a/docs/public/sdk/GettingStarted.rst +++ b/docs/public/sdk/GettingStarted.rst @@ -139,8 +139,65 @@ Opentelemetry C++ SDK offers four samplers out of the box: TracerContext ^^^^^^^^^^^^^ -SDK configuration are shared between `TracerProvider` and all the `Tracer` instances created through `TracerContext`. +SDK configuration are shared between `TracerProvider` and all it's `Tracer` instances through `TracerContext`. .. code:: cpp - auto tracer_context = + auto tracer_context = std::make_shared + (std::move(multi_processor), resource, std::move(always_on_sampler)); + +TracerProvider +^^^^^^^^^^^^^^ + +`TracerProvider` instance holds the SDK configurations ( Span Processors, Samplers, Resource). There is single +global TracerProvider instance for an application, and it is created at the start of application. +There are two different mechanisms to create TraceProvider instance +- Using constructor which takes already created TracerContext shared object as parameter +- Using consructor which takes SDK configurations as parameter. + +.. code:: cpp + // Created using `TracerContext` instance + auto tracer_provider = sdktrace::TracerProvider(tracer_context); + + // Create using SDK configurations as parameter + auto tracer_provider = + sdktrace::TracerProvider(std::move(simple_processor), resource, std::move(always_on_sampler)); + + // set the global tracer TraceProvider + opentelemetry::trace::Provider::SetTracerProvider(provider); + + +Logging and Error Handling +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Opentelemetry C++ SDK provides mechanism for application owner to add customer log and error handler. +The default log handler is redirected to standard output ( using std::cout ). + +The logging macro supports logging using C++ stream format, and key-value pair. +The log handler is meant to capture errors and warnings arising from SDK, not supposed to be used for the application errors. +The different log levels are supported - Error, Warn, Info and Debug. The default log level is Warn ( to dump both Error and Warn) +and it can be changed at compile time. +.. code:: cpp + OTEL_INTERNAL_LOG_ERROR + (" Connection failed. Error string " << error_str << " Error Num: " << errorno); + OTEL_INTERNAL_LOG_ERROR + (" Connection failed." , {{"error message: " : error_str},{"error number": errorno}}); + OTEL_INTERNAL_LOG_DEBUG + (" Connection Established Successfully. Headers:", {{"url", url},{"content-length", len}, {"content-type", type}}); + +The custom log handler can be defined by inheriting from `sdk::common::internal_log::LogHandler` class. + +.. code:: cpp + class CustomLogHandler : public sdk::common::internal_log::LogHandler + { + void Handle(Loglevel level, + const char \*file, + int line, + const char \*msg, + const sdk::common::AttributeMap &attributes) + + { + // add implementation here + } + }; + sdk::common::internal_log::GlobalLogHandler::SetLogHandler(CustomLogHandler()); \ No newline at end of file From a6dc8b3d9a942e536d9a05992c3104b7aa1b88b5 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 9 Aug 2021 20:16:42 +0530 Subject: [PATCH 4/7] format --- docs/public/sdk/GettingStarted.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/public/sdk/GettingStarted.rst b/docs/public/sdk/GettingStarted.rst index 73301d60cb..648bc67e03 100644 --- a/docs/public/sdk/GettingStarted.rst +++ b/docs/public/sdk/GettingStarted.rst @@ -152,10 +152,12 @@ TracerProvider `TracerProvider` instance holds the SDK configurations ( Span Processors, Samplers, Resource). There is single global TracerProvider instance for an application, and it is created at the start of application. There are two different mechanisms to create TraceProvider instance + - Using constructor which takes already created TracerContext shared object as parameter - Using consructor which takes SDK configurations as parameter. .. code:: cpp + // Created using `TracerContext` instance auto tracer_provider = sdktrace::TracerProvider(tracer_context); @@ -177,7 +179,9 @@ The logging macro supports logging using C++ stream format, and key-value pair. The log handler is meant to capture errors and warnings arising from SDK, not supposed to be used for the application errors. The different log levels are supported - Error, Warn, Info and Debug. The default log level is Warn ( to dump both Error and Warn) and it can be changed at compile time. + .. code:: cpp + OTEL_INTERNAL_LOG_ERROR (" Connection failed. Error string " << error_str << " Error Num: " << errorno); OTEL_INTERNAL_LOG_ERROR @@ -188,6 +192,7 @@ and it can be changed at compile time. The custom log handler can be defined by inheriting from `sdk::common::internal_log::LogHandler` class. .. code:: cpp + class CustomLogHandler : public sdk::common::internal_log::LogHandler { void Handle(Loglevel level, From 0923223bfa2373630f57ebd381141b020c5ec37b Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Mon, 9 Aug 2021 21:01:37 +0530 Subject: [PATCH 5/7] review comment --- docs/public/sdk/GettingStarted.rst | 68 +++++++++++++++--------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/docs/public/sdk/GettingStarted.rst b/docs/public/sdk/GettingStarted.rst index 648bc67e03..9dc557488a 100644 --- a/docs/public/sdk/GettingStarted.rst +++ b/docs/public/sdk/GettingStarted.rst @@ -1,46 +1,46 @@ Getting started ^^^^^^^^^^^^^^^ -Opentelemetry C++ SDK provides the reference implementation of Opentelemetry C++ API, -and also provides implementation for Processor, Sampler, and core Exporters as per the +OpenTelemetry C++ SDK provides the reference implementation of OpenTelemetry C++ API, +and also provides implementation for Processor, Sampler, and core Exporters as per the specification. Exporter ^^^^^^^^ -An exporter is responsible for sending the telemetry data to a particular backend. +An exporter is responsible for sending the telemetry data to a particular backend. OpenTelemetry offers six tracing exporters out of the box: - In-Memory Exporter: keeps the data in memory, useful for debugging. - Jaeger Exporter: prepares and sends the collected telemetry data to a Jaeger backend via UDP and HTTP. - Zipkin Exporter: prepares and sends the collected telemetry data to a Zipkin backend via the Zipkin APIs. -- Logging Exporter: saves the telemetry data into log streams -- Opentelemetry(otlp) Exporter: sends the data to the Opentelemetry Collector using protobuf/gRPC or protobuf/HTTP. -- ETW Exporter: sends the telemetry data to Event Tracing for Windows (ETW) +- Logging Exporter: saves the telemetry data into log streams. +- OpenTelemetry(otlp) Exporter: sends the data to the OpenTelemetry Collector using protobuf/gRPC or protobuf/HTTP. +- ETW Exporter: sends the telemetry data to Event Tracing for Windows (ETW). .. code:: cpp // logging exporter - auto ostream_exporter = + auto ostream_exporter = std::unique_ptr(new opentelemetry::exporter::trace::OStreamSpanExporter); // memory exporter - auto memory_exporter = + auto memory_exporter = std::unique_ptr(new opentelemetry::exporter::memory::InMemorySpanExporter); // zipkin exporter opentelemetry::exporter::zipkin::ZipkinExporterOptions opts; opts.endpoint = "http://localhost:9411/api/v2/spans" ; // or export OTEL_EXPORTER_ZIPKIN_ENDPOINT="..." - opts.service_name = "default_service" ; - auto zipkin_exporter = + opts.service_name = "default_service" ; + auto zipkin_exporter = std::unique_ptr(new opentelemetry::exporter::zipkin::ZipkinExporter(opts)); // Jaeger UDP exporter opentelemetry::exporter::jaeger::JaegerExporterOptions opts; opts.server_addr = "localhost"; opts.server_port = 6831; - auto jaeger_udp_exporter = + auto jaeger_udp_exporter = std::unique_ptr(new opentelemetry::exporter::jaeger::JaegerExporter(opts)); // otlp grpc exporter @@ -48,20 +48,20 @@ OpenTelemetry offers six tracing exporters out of the box: opts.endpoint = "localhost::4317"; opts.use_ssl_credentials = true; opts.ssl_credentials_cacert_as_string = "ssl-certificate"; - auto otlp_grpc_exporter = + auto otlp_grpc_exporter = std::unique_ptr(new opentelemetry::exporter::otlp::OtlpGrpcExporter(opts)); // otlp http exporter opentelemetry::exporter::otlp::OtlpHttpExporterOptions opts; opts.url = "http://localhost:4317/v1/traces"; - auto otlp_http_exporter = + auto otlp_http_exporter = std::unique_ptr(new opentelemetry::exporter::otlp::OtlpHttpExporter(opts)); Span Processor ^^^^^^^^^^^^^^ -Span Processor is initialised with an Exporter. Different Span Processors are offered by Opentelemetry C++ SDK: +Span Processor is initialised with an Exporter. Different Span Processors are offered by OpenTelemetry C++ SDK: - SimpleSpanProcessor: immediately forwards ended spans to the exporter. - BatchSpanProcessor: batches the ended spans and send them to exporter in bulk. @@ -77,9 +77,9 @@ Span Processor is initialised with an Exporter. Different Span Processors are of sdktrace::BatchSpanProcessorOptions options{}; auto batch_processor = std::unique_ptr( new sdktrace::BatchSpanProcessor(std::move(memory_exporter), options)); - + // multi-processor - std::vector> + std::vector> processors{std::move(simple_processor), std::move(batch_processor)}; auto multi_processor = std::unique_ptr( new sdktrace::MultiSpanProcessor(std::move(processors)); @@ -87,13 +87,13 @@ Span Processor is initialised with an Exporter. Different Span Processors are of Resource ^^^^^^^^ -A Resource is an immutable representation of the entity producing telemetry as key-value pair. -The Opentelemetry C++ SDK allow for creation of Resources and for associating them with telemetry. +A Resource is an immutable representation of the entity producing telemetry as key-value pair. +The OpenTelemetry C++ SDK allow for creation of Resources and for associating them with telemetry. .. code:: cpp auto resource_attributes = opentelemetry::sdk::resource::ResourceAttributes - { + { {"service.name": "shoppingcart"}, {"service.instance.id": "instance-12"} }; @@ -113,12 +113,12 @@ Sampler ^^^^^^^ Sampling is mechanism to control/reducing the number of samples of traces collected and sent to the backend. -Opentelemetry C++ SDK offers four samplers out of the box: +OpenTelemetry C++ SDK offers four samplers out of the box: - AlwaysOnSampler which samples every trace regardless of upstream sampling decisions. - AlwaysOffSampler which doesn’t sample any trace, regardless of upstream sampling decisions. - ParentBased which uses the parent span to make sampling decisions, if present. -- TraceIdRatioBased which samples a configurable percentage of traces +- TraceIdRatioBased which samples a configurable percentage of traces. .. code:: cpp @@ -128,7 +128,7 @@ Opentelemetry C++ SDK offers four samplers out of the box: //AlwaysOffSampler opentelemetry::sdk::trace::AlwaysOffSampler always_off_sampler; - //ParentBasedSampler + //ParentBasedSampler opentelemetry::sdk::trace::ParentBasedSampler sampler_off(std::make_shared()); //TraceIdRatioBasedSampler - Sample 50% generated spans @@ -149,11 +149,11 @@ SDK configuration are shared between `TracerProvider` and all it's `Tracer` inst TracerProvider ^^^^^^^^^^^^^^ -`TracerProvider` instance holds the SDK configurations ( Span Processors, Samplers, Resource). There is single +`TracerProvider` instance holds the SDK configurations ( Span Processors, Samplers, Resource). There is single global TracerProvider instance for an application, and it is created at the start of application. There are two different mechanisms to create TraceProvider instance -- Using constructor which takes already created TracerContext shared object as parameter +- Using constructor which takes already created TracerContext shared object as parameter. - Using consructor which takes SDK configurations as parameter. .. code:: cpp @@ -162,22 +162,22 @@ There are two different mechanisms to create TraceProvider instance auto tracer_provider = sdktrace::TracerProvider(tracer_context); // Create using SDK configurations as parameter - auto tracer_provider = + auto tracer_provider = sdktrace::TracerProvider(std::move(simple_processor), resource, std::move(always_on_sampler)); // set the global tracer TraceProvider opentelemetry::trace::Provider::SetTracerProvider(provider); -Logging and Error Handling +Logging and Error Handling ^^^^^^^^^^^^^^^^^^^^^^^^^^ -Opentelemetry C++ SDK provides mechanism for application owner to add customer log and error handler. +OpenTelemetry C++ SDK provides mechanism for application owner to add customer log and error handler. The default log handler is redirected to standard output ( using std::cout ). -The logging macro supports logging using C++ stream format, and key-value pair. +The logging macro supports logging using C++ stream format, and key-value pair. The log handler is meant to capture errors and warnings arising from SDK, not supposed to be used for the application errors. -The different log levels are supported - Error, Warn, Info and Debug. The default log level is Warn ( to dump both Error and Warn) +The different log levels are supported - Error, Warn, Info and Debug. The default log level is Warn ( to dump both Error and Warn) and it can be changed at compile time. .. code:: cpp @@ -195,14 +195,14 @@ The custom log handler can be defined by inheriting from `sdk::common::internal_ class CustomLogHandler : public sdk::common::internal_log::LogHandler { - void Handle(Loglevel level, - const char \*file, - int line, + void Handle(Loglevel level, + const char \*file, + int line, const char \*msg, const sdk::common::AttributeMap &attributes) - + { // add implementation here - } + } }; sdk::common::internal_log::GlobalLogHandler::SetLogHandler(CustomLogHandler()); \ No newline at end of file From 86fb4d6bdd7a572da667b8f8653997a57b4b0d28 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 10 Aug 2021 09:23:11 +0530 Subject: [PATCH 6/7] jaeger http --- docs/public/sdk/GettingStarted.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/public/sdk/GettingStarted.rst b/docs/public/sdk/GettingStarted.rst index 9dc557488a..bb21b9bd8a 100644 --- a/docs/public/sdk/GettingStarted.rst +++ b/docs/public/sdk/GettingStarted.rst @@ -38,11 +38,21 @@ OpenTelemetry offers six tracing exporters out of the box: // Jaeger UDP exporter opentelemetry::exporter::jaeger::JaegerExporterOptions opts; - opts.server_addr = "localhost"; + opts.endpoint = "localhost"; opts.server_port = 6831; auto jaeger_udp_exporter = std::unique_ptr(new opentelemetry::exporter::jaeger::JaegerExporter(opts)); + // Jaeger HTTP exporter + opentelemetry::exporter::jaeger::JaegerExporterOptions opts; + opts.transport_format = opentelemetry::exporter::jaeger::TransportFormat::kThriftHttp; + opts.endpoint = "localhost"; + opts.server_port = 6831; + opts.headers = {{}}; // optional headers + auto jaeger_udp_exporter = + std::unique_ptr(new opentelemetry::exporter::jaeger::JaegerExporter(opts)); + + // otlp grpc exporter opentelemetry::exporter::otlp::OtlpGrpcExporterOptions opts; opts.endpoint = "localhost::4317"; From de60f5b5dd4234ecd0719e30d6fad94a84828f6b Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Tue, 10 Aug 2021 09:31:45 +0530 Subject: [PATCH 7/7] jaeger http and namespace alias --- docs/public/sdk/GettingStarted.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/public/sdk/GettingStarted.rst b/docs/public/sdk/GettingStarted.rst index bb21b9bd8a..fcdce5b846 100644 --- a/docs/public/sdk/GettingStarted.rst +++ b/docs/public/sdk/GettingStarted.rst @@ -21,6 +21,9 @@ OpenTelemetry offers six tracing exporters out of the box: .. code:: cpp + //namespace alias used in sample code here. + namespace sdktrace = opentelemetry::sdk::trace; + // logging exporter auto ostream_exporter = std::unique_ptr(new opentelemetry::exporter::trace::OStreamSpanExporter);