[SDK] Better control of threads executed by opentelemetry-cpp (#3175)

This commit is contained in:
Marc Alff 2025-01-13 10:12:30 +01:00 committed by GitHub
parent 0b712dd2f7
commit d693e95cdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
67 changed files with 1720 additions and 112 deletions

View File

@ -27,6 +27,66 @@ Increment the:
* [EXPORTER] Fix throw in OtlpGrpcMetricExporter with shared grpc client
[#3243](https://github.com/open-telemetry/opentelemetry-cpp/pull/3243)
* [SDK] Better control of threads executed by opentelemetry-cpp
[#3175](https://github.com/open-telemetry/opentelemetry-cpp/pull/3175)
New features:
* [SDK] Better control of threads executed by opentelemetry-cpp
[#3175](https://github.com/open-telemetry/opentelemetry-cpp/pull/3175)
* This feature provides a way for applications,
when configuring the SDK and exporters,
to participate in the execution path
of internal opentelemetry-cpp threads.
* The opentelemetry-cpp library provides the following:
* a new ThreadInstrumentation interface,
* new runtime options structures, to optionally configure the SDK:
* BatchSpanProcessorRuntimeOptions
* PeriodicExportingMetricReaderRuntimeOptions
* BatchLogRecordProcessorRuntimeOptions
* new runtime options structures,
to optionally configure the OTLP HTTP exporters:
* OtlpHttpExporterRuntimeOptions
* OtlpHttpMetricExporterRuntimeOptions
* OtlpHttpLogRecordExporterRuntimeOptions
* new ThreadInstrumentation parameters,
to optionally configure the CURL HttpClient
* new runtime options structures,
to optionally configure the OTLP FILE exporters:
* OtlpFileExporterRuntimeOptions
* OtlpFileMetricExporterRuntimeOptions
* OtlpFileLogRecordExporterRuntimeOptions
* new runtime options structure,
to optionally configure the OTLP FILE client:
* OtlpFileClientRuntimeOptions
* Using the optional runtime options structures,
an application can subclass the ThreadInstrumentation interface,
and be notified of specific events of interest during the execution
of an internal opentelemetry-cpp thread.
* This allows an application to call, for example:
* pthread_setaffinity_np(), for better performances,
* setns(), to control the network namespace used by HTTP CURL connections
* pthread_setname_np(), for better observability from the operating system
* many more specific apis, as needed
* See the documentation for ThreadInstrumentation for details.
* A new example program, example_otlp_instrumented_http,
shows how to use the feature,
and add application logic in the thread execution code path.
* Note that this feature is experimental,
protected by a WITH_THREAD_INSTRUMENTATION_PREVIEW
flag in CMake. Various runtime options structures,
as well as the thread instrumentation interface,
may change without notice before this feature is declared stable.
## [1.18 2024-11-25]
* [EXPORTER] Fix crash in ElasticsearchLogRecordExporter

View File

@ -300,6 +300,10 @@ option(WITH_ASYNC_EXPORT_PREVIEW "Whether to enable async export" OFF)
option(WITH_METRICS_EXEMPLAR_PREVIEW
"Whether to enable exemplar within metrics" OFF)
# Experimental, so behind feature flag by default
option(WITH_THREAD_INSTRUMENTATION_PREVIEW
"Whether to enable thread instrumentation" OFF)
option(OPENTELEMETRY_SKIP_DYNAMIC_LOADING_TESTS
"Whether to build test libraries that are always linked as shared libs"
OFF)

View File

@ -126,6 +126,11 @@ if(WITH_METRICS_EXEMPLAR_PREVIEW)
INTERFACE ENABLE_METRICS_EXEMPLAR_PREVIEW)
endif()
if(WITH_THREAD_INSTRUMENTATION_PREVIEW)
target_compile_definitions(opentelemetry_api
INTERFACE ENABLE_THREAD_INSTRUMENTATION_PREVIEW)
endif()
if(WITH_OTLP_HTTP_COMPRESSION)
target_compile_definitions(opentelemetry_api
INTERFACE ENABLE_OTLP_COMPRESSION_PREVIEW)

View File

@ -131,6 +131,7 @@ elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then
-DOTELCPP_MAINTAINER_MODE=ON \
-DWITH_NO_DEPRECATED_CODE=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
@ -153,6 +154,7 @@ elif [[ "$1" == "cmake.maintainer.async.test" ]]; then
-DOTELCPP_MAINTAINER_MODE=ON \
-DWITH_NO_DEPRECATED_CODE=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
@ -176,6 +178,7 @@ elif [[ "$1" == "cmake.maintainer.cpp11.async.test" ]]; then
-DOTELCPP_MAINTAINER_MODE=ON \
-DWITH_NO_DEPRECATED_CODE=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
"${SRC_DIR}"
make -k -j $(nproc)
make test
@ -199,6 +202,7 @@ elif [[ "$1" == "cmake.maintainer.abiv2.test" ]]; then
-DWITH_ABI_VERSION_1=OFF \
-DWITH_ABI_VERSION_2=ON \
-DWITH_OTLP_HTTP_COMPRESSION=ON \
-DWITH_THREAD_INSTRUMENTATION_PREVIEW=ON \
${IWYU} \
"${SRC_DIR}"
eval "$MAKE_COMMAND"

View File

@ -168,3 +168,25 @@ cc_binary(
"//sdk/src/metrics",
],
)
cc_binary(
name = "example_otlp_instrumented_http",
srcs = [
"http_instrumented_main.cc",
],
tags = [
"examples",
"otlp",
"otlp_http",
],
deps = [
"//api",
"//examples/common/logs_foo_library:common_logs_foo_library",
"//examples/common/metrics_foo_library:common_metrics_foo_library",
"//exporters/otlp:otlp_http_exporter",
"//exporters/otlp:otlp_http_log_record_exporter",
"//exporters/otlp:otlp_http_metric_exporter",
"//sdk/src/metrics",
"//sdk/src/trace",
],
)

View File

@ -99,6 +99,29 @@ if(WITH_OTLP_HTTP)
opentelemetry_exporter_otlp_http_log)
endif()
# ALL, instrumented
add_executable(example_otlp_instrumented_http http_instrumented_main.cc)
# Note: common_logs_foo_library provide traces and logs
target_link_libraries(
example_otlp_instrumented_http ${CMAKE_THREAD_LIBS_INIT}
common_metrics_foo_library common_logs_foo_library)
if(DEFINED OPENTELEMETRY_BUILD_DLL)
target_link_libraries(example_otlp_instrumented_http opentelemetry_cpp
opentelemetry_common)
else()
target_link_libraries(
example_otlp_instrumented_http
opentelemetry_trace
opentelemetry_metrics
opentelemetry_logs
opentelemetry_exporter_otlp_http
opentelemetry_exporter_otlp_http_metric
opentelemetry_exporter_otlp_http_log)
endif()
endif()
if(WITH_OTLP_FILE)

View File

@ -0,0 +1,358 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#include <iostream>
#include <memory>
#include <string>
#include <utility>
#include "opentelemetry/exporters/otlp/otlp_environment.h"
#include "opentelemetry/exporters/otlp/otlp_http.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h"
#include "opentelemetry/logs/log_record.h"
#include "opentelemetry/logs/logger_provider.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/metrics/meter_provider.h"
#include "opentelemetry/metrics/provider.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h"
#include "opentelemetry/sdk/logs/logger_provider.h"
#include "opentelemetry/sdk/logs/logger_provider_factory.h"
#include "opentelemetry/sdk/logs/recordable.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_runtime_options.h"
#include "opentelemetry/sdk/metrics/meter_context.h"
#include "opentelemetry/sdk/metrics/meter_context_factory.h"
#include "opentelemetry/sdk/metrics/meter_provider_factory.h"
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/sdk/trace/batch_span_processor_factory.h"
#include "opentelemetry/sdk/trace/batch_span_processor_options.h"
#include "opentelemetry/sdk/trace/batch_span_processor_runtime_options.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/recordable.h"
#include "opentelemetry/sdk/trace/tracer_provider.h"
#include "opentelemetry/sdk/trace/tracer_provider_factory.h"
#include "opentelemetry/trace/provider.h"
#include "opentelemetry/trace/span_id.h"
#include "opentelemetry/trace/tracer_provider.h"
#ifdef BAZEL_BUILD
# include "examples/common/logs_foo_library/foo_library.h"
# include "examples/common/metrics_foo_library/foo_library.h"
#else
# include "logs_foo_library/foo_library.h"
# include "metrics_foo_library/foo_library.h"
#endif
namespace
{
std::mutex serialize;
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
/**
The purpose of MyThreadInstrumentation is to demonstrate
how notifications are delivered to the application.
Printing to std::cout is useful for debugging,
to understand the overall thread execution in the library.
In production, a real application would instead:
- set thread priorities / CPU affinity
- set thread local storage keys
- set a thread name to the operating system
- set network namespaces
in the OnXXX() code here.
*/
class MyThreadInstrumentation : public opentelemetry::sdk::common::ThreadInstrumentation
{
public:
MyThreadInstrumentation(const std::string &thread_name,
const std::string &network_name,
const std::string &priority)
: thread_name_(thread_name), network_name_(network_name), priority_(priority)
{}
~MyThreadInstrumentation() override = default;
void OnStart() override
{
std::lock_guard<std::mutex> lock_guard(serialize);
std::cout << "OnStart() thread " << thread_name_ << ", id " << std::this_thread::get_id();
if (!network_name_.empty())
{
std::cout << ", network_name " << network_name_;
}
if (!priority_.empty())
{
std::cout << ", priority " << priority_;
}
std::cout << std::endl << std::flush;
}
void OnEnd() override
{
std::lock_guard<std::mutex> lock_guard(serialize);
std::cout << "OnEnd() thread " << thread_name_ << ", id " << std::this_thread::get_id()
<< std::endl
<< std::flush;
}
void BeforeWait() override
{
std::lock_guard<std::mutex> lock_guard(serialize);
std::cout << "BeforeWait() thread " << thread_name_ << ", id " << std::this_thread::get_id()
<< ", waiting" << std::endl
<< std::flush;
}
void AfterWait() override
{
std::lock_guard<std::mutex> lock_guard(serialize);
std::cout << "AfterWait() thread " << thread_name_ << ", id " << std::this_thread::get_id()
<< ", done waiting" << std::endl
<< std::flush;
}
void BeforeLoad() override
{
std::lock_guard<std::mutex> lock_guard(serialize);
std::cout << "BeforeLoad() thread " << thread_name_ << ", id " << std::this_thread::get_id()
<< ", about to work" << std::endl
<< std::flush;
}
void AfterLoad() override
{
std::lock_guard<std::mutex> lock_guard(serialize);
std::cout << "AfterLoad() thread " << thread_name_ << ", id " << std::this_thread::get_id()
<< ", done working" << std::endl
<< std::flush;
}
private:
std::string thread_name_;
std::string network_name_;
std::string priority_;
};
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
opentelemetry::exporter::otlp::OtlpHttpExporterOptions tracer_opts;
opentelemetry::exporter::otlp::OtlpHttpMetricExporterOptions meter_opts;
opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterOptions logger_opts;
std::shared_ptr<opentelemetry::sdk::trace::TracerProvider> tracer_provider;
std::shared_ptr<opentelemetry::sdk::metrics::MeterProvider> meter_provider;
std::shared_ptr<opentelemetry::sdk::logs::LoggerProvider> logger_provider;
void InitTracer()
{
// Create OTLP exporter instance
opentelemetry::exporter::otlp::OtlpHttpExporterRuntimeOptions exp_rt_opts;
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
auto exp_instr = std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation>(
new MyThreadInstrumentation("OtlpHttpExporter", "trace-net", "high"));
exp_rt_opts.thread_instrumentation = exp_instr;
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
auto exporter =
opentelemetry::exporter::otlp::OtlpHttpExporterFactory::Create(tracer_opts, exp_rt_opts);
// Create Processor instance
opentelemetry::sdk::trace::BatchSpanProcessorOptions pro_opts;
opentelemetry::sdk::trace::BatchSpanProcessorRuntimeOptions pro_rt_opts;
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
auto pro_instr = std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation>(
new MyThreadInstrumentation("BatchSpanProcessor", "", "high"));
pro_rt_opts.thread_instrumentation = pro_instr;
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
auto processor = opentelemetry::sdk::trace::BatchSpanProcessorFactory::Create(
std::move(exporter), pro_opts, pro_rt_opts);
// Create Provider instance
tracer_provider = opentelemetry::sdk::trace::TracerProviderFactory::Create(std::move(processor));
// Set the global trace provider
std::shared_ptr<opentelemetry::trace::TracerProvider> api_provider = tracer_provider;
opentelemetry::trace::Provider::SetTracerProvider(api_provider);
}
void CleanupTracer()
{
// We call ForceFlush to prevent to cancel running exportings, It's optional.
if (tracer_provider)
{
tracer_provider->ForceFlush();
tracer_provider->Shutdown();
}
tracer_provider.reset();
std::shared_ptr<opentelemetry::trace::TracerProvider> none;
opentelemetry::trace::Provider::SetTracerProvider(none);
}
void InitMetrics()
{
// Create OTLP exporter instance
opentelemetry::exporter::otlp::OtlpHttpMetricExporterRuntimeOptions exp_rt_opts;
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
auto exp_instr = std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation>(
new MyThreadInstrumentation("OtlpHttpMetricExporter", "metric-net", "medium"));
exp_rt_opts.thread_instrumentation = exp_instr;
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
auto exporter =
opentelemetry::exporter::otlp::OtlpHttpMetricExporterFactory::Create(meter_opts, exp_rt_opts);
std::string version{"1.2.0"};
std::string schema{"https://opentelemetry.io/schemas/1.2.0"};
// Initialize and set the global MeterProvider
opentelemetry::sdk::metrics::PeriodicExportingMetricReaderOptions reader_options;
reader_options.export_interval_millis = std::chrono::milliseconds(1000);
reader_options.export_timeout_millis = std::chrono::milliseconds(500);
opentelemetry::sdk::metrics::PeriodicExportingMetricReaderRuntimeOptions reader_rt_opts;
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
auto reader_periodic_instr = std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation>(
new MyThreadInstrumentation("PeriodicExportingMetricReader(periodic)", "", "medium"));
auto reader_collect_instr = std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation>(
new MyThreadInstrumentation("PeriodicExportingMetricReader(collect)", "", "medium"));
reader_rt_opts.periodic_thread_instrumentation = reader_periodic_instr;
reader_rt_opts.collect_thread_instrumentation = reader_collect_instr;
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
auto reader = opentelemetry::sdk::metrics::PeriodicExportingMetricReaderFactory::Create(
std::move(exporter), reader_options, reader_rt_opts);
auto context = opentelemetry::sdk::metrics::MeterContextFactory::Create();
context->AddMetricReader(std::move(reader));
meter_provider = opentelemetry::sdk::metrics::MeterProviderFactory::Create(std::move(context));
std::shared_ptr<opentelemetry::metrics::MeterProvider> api_provider = meter_provider;
opentelemetry::metrics::Provider::SetMeterProvider(api_provider);
}
void CleanupMetrics()
{
// We call ForceFlush to prevent to cancel running exportings, It's optional.
if (meter_provider)
{
meter_provider->ForceFlush();
meter_provider->Shutdown();
}
meter_provider.reset();
std::shared_ptr<opentelemetry::metrics::MeterProvider> none;
opentelemetry::metrics::Provider::SetMeterProvider(none);
}
void InitLogger()
{
// Create OTLP exporter instance
opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterRuntimeOptions exp_rt_opts;
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
auto exp_instr = std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation>(
new MyThreadInstrumentation("OtlpHttpLogRecordExporter", "log-net", "low"));
exp_rt_opts.thread_instrumentation = exp_instr;
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
auto exporter = opentelemetry::exporter::otlp::OtlpHttpLogRecordExporterFactory::Create(
logger_opts, exp_rt_opts);
// Create Processor instance
opentelemetry::sdk::logs::BatchLogRecordProcessorOptions pro_opts;
opentelemetry::sdk::logs::BatchLogRecordProcessorRuntimeOptions pro_rt_opts;
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
auto pro_instr = std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation>(
new MyThreadInstrumentation("BatchLogRecordProcessor", "", "low"));
pro_rt_opts.thread_instrumentation = pro_instr;
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
auto processor = opentelemetry::sdk::logs::BatchLogRecordProcessorFactory::Create(
std::move(exporter), pro_opts, pro_rt_opts);
logger_provider = opentelemetry::sdk::logs::LoggerProviderFactory::Create(std::move(processor));
std::shared_ptr<opentelemetry::logs::LoggerProvider> api_provider = logger_provider;
opentelemetry::logs::Provider::SetLoggerProvider(api_provider);
}
void CleanupLogger()
{
// We call ForceFlush to prevent to cancel running exportings, It's optional.
if (logger_provider)
{
logger_provider->ForceFlush();
logger_provider->Shutdown();
}
logger_provider.reset();
std::shared_ptr<opentelemetry::logs::LoggerProvider> none;
opentelemetry::logs::Provider::SetLoggerProvider(none);
}
} // namespace
/*
Usage:
- example_otlp_instrumented_http
- example_otlp_instrumented_http <TRACE_URL> <METRIC_URL> <LOG_URL>
*/
int main(int argc, char *argv[])
{
if (argc > 1)
{
tracer_opts.url = argv[1];
}
else
{
tracer_opts.url = "http://localhost:4318/v1/traces";
}
if (argc > 2)
{
meter_opts.url = argv[2];
}
else
{
meter_opts.url = "http://localhost:4318/v1/metrics";
}
if (argc > 3)
{
logger_opts.url = argv[3];
}
else
{
logger_opts.url = "http://localhost:4318/v1/logs";
}
std::cout << "Initializing opentelemetry-cpp" << std::endl << std::flush;
InitTracer();
InitMetrics();
InitLogger();
std::cout << "Application payload" << std::endl << std::flush;
foo_library();
std::string name{"otlp_http_metric_example"};
foo_library::observable_counter_example(name);
std::cout << "Shutting down opentelemetry-cpp" << std::endl << std::flush;
CleanupLogger();
CleanupMetrics();
CleanupTracer();
std::cout << "Done" << std::endl << std::flush;
return 0;
}

View File

@ -155,6 +155,7 @@ cc_library(
"include/opentelemetry/exporters/otlp/otlp_http_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_http_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],
@ -180,6 +181,7 @@ cc_library(
"include/opentelemetry/exporters/otlp/otlp_environment.h",
"include/opentelemetry/exporters/otlp/otlp_file_client.h",
"include/opentelemetry/exporters/otlp/otlp_file_client_options.h",
"include/opentelemetry/exporters/otlp/otlp_file_client_runtime_options.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],
@ -210,6 +212,7 @@ cc_library(
"include/opentelemetry/exporters/otlp/otlp_file_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_file_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_file_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_file_exporter_runtime_options.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],
@ -270,6 +273,7 @@ cc_library(
"include/opentelemetry/exporters/otlp/otlp_http_metric_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],
@ -298,6 +302,7 @@ cc_library(
"include/opentelemetry/exporters/otlp/otlp_file_metric_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_file_metric_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_file_metric_exporter_runtime_options.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],
@ -326,6 +331,7 @@ cc_library(
"include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],
@ -354,6 +360,7 @@ cc_library(
"include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter.h",
"include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter_factory.h",
"include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h",
"include/opentelemetry/exporters/otlp/otlp_file_log_record_exporter_runtime_options.h",
"include/opentelemetry/exporters/otlp/protobuf_include_prefix.h",
"include/opentelemetry/exporters/otlp/protobuf_include_suffix.h",
],

View File

@ -7,6 +7,7 @@
#include <cstddef>
#include "opentelemetry/exporters/otlp/otlp_file_client_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_client_runtime_options.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/version.h"
@ -35,7 +36,8 @@ public:
/**
* Create an OtlpFileClient using the given options.
*/
explicit OtlpFileClient(OtlpFileClientOptions &&options);
explicit OtlpFileClient(OtlpFileClientOptions &&options,
OtlpFileClientRuntimeOptions &&runtime_options);
~OtlpFileClient();
@ -80,6 +82,8 @@ private:
// The configuration options associated with this file client.
const OtlpFileClientOptions options_;
// The runtime options associated with this file client.
const OtlpFileClientRuntimeOptions runtime_options_;
opentelemetry::nostd::shared_ptr<OtlpFileAppender> backend_;
};

View File

@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <memory>
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
/**
* Struct to hold OTLP FILE client runtime options.
*/
struct OtlpFileClientRuntimeOptions
{
OtlpFileClientRuntimeOptions() = default;
~OtlpFileClientRuntimeOptions() = default;
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation =
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
};
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE

View File

@ -8,6 +8,7 @@
#include "opentelemetry/exporters/otlp/otlp_file_client.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_runtime_options.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/trace/exporter.h"
@ -36,6 +37,12 @@ public:
*/
explicit OtlpFileExporter(const OtlpFileExporterOptions &options);
/**
* Create an OtlpFileExporter using the given options.
*/
explicit OtlpFileExporter(const OtlpFileExporterOptions &options,
const OtlpFileExporterRuntimeOptions &runtime_options);
/**
* Create a span recordable.
* @return a newly initialized Recordable object
@ -70,6 +77,8 @@ public:
private:
// The configuration options associated with this exporter.
const OtlpFileExporterOptions options_;
// The runtime options associated with this exporter.
const OtlpFileExporterRuntimeOptions runtime_options_;
// Object that stores the file context.
std::unique_ptr<OtlpFileClient> file_client_;

View File

@ -6,6 +6,7 @@
#include <memory>
#include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_runtime_options.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/version.h"
@ -31,6 +32,13 @@ public:
*/
static std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> Create(
const OtlpFileExporterOptions &options);
/**
* Create an OtlpFileExporter using the given options.
*/
static std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> Create(
const OtlpFileExporterOptions &options,
const OtlpFileExporterRuntimeOptions &runtime_options);
};
} // namespace otlp

View File

@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "opentelemetry/version.h"
#include "opentelemetry/exporters/otlp/otlp_file_client_runtime_options.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
/**
* Struct to hold OTLP File traces exporter runtime options.
*/
struct OPENTELEMETRY_EXPORT OtlpFileExporterRuntimeOptions : public OtlpFileClientRuntimeOptions
{
OtlpFileExporterRuntimeOptions() = default;
~OtlpFileExporterRuntimeOptions() = default;
};
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE

View File

@ -8,6 +8,7 @@
#include "opentelemetry/exporters/otlp/otlp_file_client.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_runtime_options.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/logs/exporter.h"
@ -37,6 +38,14 @@ public:
*/
OtlpFileLogRecordExporter(const OtlpFileLogRecordExporterOptions &options);
/**
* Create an OtlpFileLogRecordExporter with user specified options.
* @param options An object containing the user's configuration options.
* @param runtime_options An object containing the user's runtime options.
*/
OtlpFileLogRecordExporter(const OtlpFileLogRecordExporterOptions &options,
const OtlpFileLogRecordExporterRuntimeOptions &runtime_options);
/**
* Creates a recordable that stores the data in a JSON object
*/
@ -69,6 +78,8 @@ public:
private:
// Configuration options for the exporter
const OtlpFileLogRecordExporterOptions options_;
// Runtime options for the exporter
const OtlpFileLogRecordExporterRuntimeOptions runtime_options_;
// Object that stores the file context.
std::unique_ptr<OtlpFileClient> file_client_;

View File

@ -6,6 +6,7 @@
#include <memory>
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_runtime_options.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/version.h"
@ -31,6 +32,13 @@ public:
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
const OtlpFileLogRecordExporterOptions &options);
/**
* Create an OtlpFileExporter using the given options.
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
const OtlpFileLogRecordExporterOptions &options,
const OtlpFileLogRecordExporterRuntimeOptions &runtime_options);
};
} // namespace otlp

View File

@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "opentelemetry/exporters/otlp/otlp_file_client_runtime_options.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
/**
* Struct to hold OTLP File log record exporter runtime options.
*/
struct OPENTELEMETRY_EXPORT OtlpFileLogRecordExporterRuntimeOptions
: public OtlpFileClientRuntimeOptions
{
OtlpFileLogRecordExporterRuntimeOptions() = default;
~OtlpFileLogRecordExporterRuntimeOptions() = default;
};
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE

View File

@ -8,6 +8,7 @@
#include "opentelemetry/exporters/otlp/otlp_file_client.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_runtime_options.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
#include "opentelemetry/sdk/metrics/instruments.h"
@ -36,6 +37,14 @@ public:
*/
OtlpFileMetricExporter(const OtlpFileMetricExporterOptions &options);
/**
* Create an OtlpFileMetricExporter with user specified options.
* @param options An object containing the user's configuration options.
* @param runtime_options An object containing the user's runtime options.
*/
OtlpFileMetricExporter(const OtlpFileMetricExporterOptions &options,
const OtlpFileMetricExporterRuntimeOptions &runtime_options);
/**
* Get the AggregationTemporality for exporter
*
@ -61,6 +70,8 @@ private:
// Configuration options for the exporter
const OtlpFileMetricExporterOptions options_;
// Runtime options for the exporter
const OtlpFileMetricExporterRuntimeOptions runtime_options_;
// Aggregation Temporality Selector
const sdk::metrics::AggregationTemporalitySelector aggregation_temporality_selector_;

View File

@ -6,6 +6,7 @@
#include <memory>
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_runtime_options.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/version.h"
@ -31,6 +32,13 @@ public:
*/
static std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> Create(
const OtlpFileMetricExporterOptions &options);
/**
* Create an OtlpFileExporter using the given options.
*/
static std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> Create(
const OtlpFileMetricExporterOptions &options,
const OtlpFileMetricExporterRuntimeOptions &runtime_options);
};
} // namespace otlp

View File

@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "opentelemetry/exporters/otlp/otlp_file_client_runtime_options.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
/**
* Struct to hold OTLP File metrics exporter runtime options.
*/
struct OPENTELEMETRY_EXPORT OtlpFileMetricExporterRuntimeOptions
: public OtlpFileClientRuntimeOptions
{
OtlpFileMetricExporterRuntimeOptions() = default;
~OtlpFileMetricExporterRuntimeOptions() = default;
};
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE

View File

@ -20,6 +20,7 @@
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/variant.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
// forward declare google::protobuf::Message
@ -83,28 +84,33 @@ struct OtlpHttpClientOptions
// User agent
std::string user_agent;
inline OtlpHttpClientOptions(nostd::string_view input_url,
bool input_ssl_insecure_skip_verify,
nostd::string_view input_ssl_ca_cert_path,
nostd::string_view input_ssl_ca_cert_string,
nostd::string_view input_ssl_client_key_path,
nostd::string_view input_ssl_client_key_string,
nostd::string_view input_ssl_client_cert_path,
nostd::string_view input_ssl_client_cert_string,
nostd::string_view input_ssl_min_tls,
nostd::string_view input_ssl_max_tls,
nostd::string_view input_ssl_cipher,
nostd::string_view input_ssl_cipher_suite,
HttpRequestContentType input_content_type,
JsonBytesMappingKind input_json_bytes_mapping,
nostd::string_view input_compression,
bool input_use_json_name,
bool input_console_debug,
std::chrono::system_clock::duration input_timeout,
const OtlpHeaders &input_http_headers,
std::size_t input_concurrent_sessions = 64,
std::size_t input_max_requests_per_connection = 8,
nostd::string_view input_user_agent = GetOtlpDefaultUserAgent())
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation =
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
inline OtlpHttpClientOptions(
nostd::string_view input_url,
bool input_ssl_insecure_skip_verify,
nostd::string_view input_ssl_ca_cert_path,
nostd::string_view input_ssl_ca_cert_string,
nostd::string_view input_ssl_client_key_path,
nostd::string_view input_ssl_client_key_string,
nostd::string_view input_ssl_client_cert_path,
nostd::string_view input_ssl_client_cert_string,
nostd::string_view input_ssl_min_tls,
nostd::string_view input_ssl_max_tls,
nostd::string_view input_ssl_cipher,
nostd::string_view input_ssl_cipher_suite,
HttpRequestContentType input_content_type,
JsonBytesMappingKind input_json_bytes_mapping,
nostd::string_view input_compression,
bool input_use_json_name,
bool input_console_debug,
std::chrono::system_clock::duration input_timeout,
const OtlpHeaders &input_http_headers,
const std::shared_ptr<sdk::common::ThreadInstrumentation> &input_thread_instrumentation,
std::size_t input_concurrent_sessions = 64,
std::size_t input_max_requests_per_connection = 8,
nostd::string_view input_user_agent = GetOtlpDefaultUserAgent())
: url(input_url),
ssl_options(input_url,
input_ssl_insecure_skip_verify,
@ -127,7 +133,8 @@ struct OtlpHttpClientOptions
http_headers(input_http_headers),
max_concurrent_requests(input_concurrent_sessions),
max_requests_per_connection(input_max_requests_per_connection),
user_agent(input_user_agent)
user_agent(input_user_agent),
thread_instrumentation(input_thread_instrumentation)
{}
};

View File

@ -8,6 +8,7 @@
#include "opentelemetry/exporters/otlp/otlp_http_client.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/trace/exporter.h"
@ -36,6 +37,12 @@ public:
*/
explicit OtlpHttpExporter(const OtlpHttpExporterOptions &options);
/**
* Create an OtlpHttpExporter using the given options.
*/
OtlpHttpExporter(const OtlpHttpExporterOptions &options,
const OtlpHttpExporterRuntimeOptions &runtime_options);
/**
* Create a span recordable.
* @return a newly initialized Recordable object
@ -69,7 +76,9 @@ public:
private:
// The configuration options associated with this exporter.
const OtlpHttpExporterOptions options_;
OtlpHttpExporterOptions options_;
// The runtime options associated with this exporter.
OtlpHttpExporterRuntimeOptions runtime_options_;
// Object that stores the HTTP sessions that have been created
std::unique_ptr<OtlpHttpClient> http_client_;

View File

@ -6,6 +6,7 @@
#include <memory>
#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/version.h"
@ -31,6 +32,13 @@ public:
*/
static std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> Create(
const OtlpHttpExporterOptions &options);
/**
* Create an OtlpHttpExporter using the given options.
*/
static std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> Create(
const OtlpHttpExporterOptions &options,
const OtlpHttpExporterRuntimeOptions &runtime_options);
};
} // namespace otlp

View File

@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <memory>
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
/**
* Struct to hold OTLP HTTP traces exporter runtime options.
*/
struct OPENTELEMETRY_EXPORT OtlpHttpExporterRuntimeOptions
{
OtlpHttpExporterRuntimeOptions() = default;
~OtlpHttpExporterRuntimeOptions() = default;
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation =
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
};
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE

View File

@ -8,6 +8,7 @@
#include "opentelemetry/exporters/otlp/otlp_http_client.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/logs/exporter.h"
@ -37,6 +38,14 @@ public:
*/
OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options);
/**
* Create an OtlpHttpLogRecordExporter with user specified options.
* @param options An object containing the user's configuration options.
* @param runtime_options An object containing the user's runtime options.
*/
OtlpHttpLogRecordExporter(const OtlpHttpLogRecordExporterOptions &options,
const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options);
/**
* Creates a recordable that stores the data in a JSON object
*/
@ -68,7 +77,9 @@ public:
private:
// Configuration options for the exporter
const OtlpHttpLogRecordExporterOptions options_;
OtlpHttpLogRecordExporterOptions options_;
// Runtime options for the exporter
OtlpHttpLogRecordExporterRuntimeOptions runtime_options_;
// Object that stores the HTTP sessions that have been created
std::unique_ptr<OtlpHttpClient> http_client_;

View File

@ -6,6 +6,7 @@
#include <memory>
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/version.h"
@ -31,6 +32,13 @@ public:
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
const OtlpHttpLogRecordExporterOptions &options);
/**
* Create a OtlpHttpLogRecordExporter.
*/
static std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> Create(
const OtlpHttpLogRecordExporterOptions &options,
const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options);
};
} // namespace otlp

View File

@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <memory>
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
/**
* Struct to hold OTLP HTTP log record exporter runtime options.
*/
struct OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterRuntimeOptions
{
OtlpHttpLogRecordExporterRuntimeOptions() = default;
~OtlpHttpLogRecordExporterRuntimeOptions() = default;
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation =
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
};
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE

View File

@ -8,6 +8,7 @@
#include "opentelemetry/exporters/otlp/otlp_http_client.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
#include "opentelemetry/sdk/metrics/instruments.h"
@ -36,6 +37,14 @@ public:
*/
OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options);
/**
* Create an OtlpHttpMetricExporter with user specified options.
* @param options An object containing the user's configuration options.
* @param runtime_options An object containing the user's runtime options.
*/
OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options,
const OtlpHttpMetricExporterRuntimeOptions &runtime_options);
/**
* Get the AggregationTemporality for exporter
*
@ -58,7 +67,9 @@ public:
private:
// Configuration options for the exporter
const OtlpHttpMetricExporterOptions options_;
OtlpHttpMetricExporterOptions options_;
// Runtime options for the exporter
OtlpHttpMetricExporterRuntimeOptions runtime_options_;
// Aggregation Temporality Selector
const sdk::metrics::AggregationTemporalitySelector aggregation_temporality_selector_;

View File

@ -6,6 +6,7 @@
#include <memory>
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/version.h"
@ -31,6 +32,13 @@ public:
*/
static std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> Create(
const OtlpHttpMetricExporterOptions &options);
/**
* Create a OtlpHttpMetricExporter.
*/
static std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> Create(
const OtlpHttpMetricExporterOptions &options,
const OtlpHttpMetricExporterRuntimeOptions &runtime_options);
};
} // namespace otlp

View File

@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <memory>
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
namespace otlp
{
/**
* Struct to hold OTLP HTTP metrics exporter runtime options.
*/
struct OPENTELEMETRY_EXPORT OtlpHttpMetricExporterRuntimeOptions
{
OtlpHttpMetricExporterRuntimeOptions() = default;
~OtlpHttpMetricExporterRuntimeOptions() = default;
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation =
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
};
} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE

View File

@ -104,6 +104,7 @@
#include "opentelemetry/exporters/otlp/otlp_file_client.h"
#include "opentelemetry/exporters/otlp/otlp_file_client_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_client_runtime_options.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/variant.h"
@ -970,8 +971,9 @@ void ConvertListFieldToJson(nlohmann::json &value,
class OPENTELEMETRY_LOCAL_SYMBOL OtlpFileSystemBackend : public OtlpFileAppender
{
public:
explicit OtlpFileSystemBackend(const OtlpFileClientFileSystemOptions &options)
: options_(options), is_initialized_{false}
explicit OtlpFileSystemBackend(const OtlpFileClientFileSystemOptions &options,
const OtlpFileClientRuntimeOptions &runtime_options)
: options_(options), runtime_options_(runtime_options), is_initialized_{false}
{
file_->is_shutdown.store(false);
file_->rotate_index = 0;
@ -1444,11 +1446,20 @@ private:
std::shared_ptr<FileStats> concurrency_file = file_;
std::chrono::microseconds flush_interval = options_.flush_interval;
file_->background_flush_thread.reset(new std::thread([concurrency_file, flush_interval]() {
auto thread_instrumentation = runtime_options_.thread_instrumentation;
file_->background_flush_thread.reset(new std::thread([concurrency_file, flush_interval,
thread_instrumentation]() {
std::chrono::system_clock::time_point last_free_job_timepoint =
std::chrono::system_clock::now();
std::size_t last_record_count = 0;
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (thread_instrumentation != nullptr)
{
thread_instrumentation->OnStart();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
while (true)
{
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
@ -1463,11 +1474,25 @@ private:
break;
}
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (thread_instrumentation != nullptr)
{
thread_instrumentation->BeforeWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
{
std::unique_lock<std::mutex> lk(concurrency_file->background_thread_waker_lock);
concurrency_file->background_thread_waker_cv.wait_for(lk, flush_interval);
}
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (thread_instrumentation != nullptr)
{
thread_instrumentation->AfterWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
{
std::size_t current_record_count =
concurrency_file->record_count.load(std::memory_order_acquire);
@ -1496,6 +1521,14 @@ private:
std::lock_guard<std::mutex> lock_guard_inner{concurrency_file->background_thread_lock};
background_flush_thread.swap(concurrency_file->background_flush_thread);
}
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (thread_instrumentation != nullptr)
{
thread_instrumentation->OnEnd();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
if (background_flush_thread && background_flush_thread->joinable())
{
background_flush_thread->detach();
@ -1519,6 +1552,7 @@ private:
private:
OtlpFileClientFileSystemOptions options_;
OtlpFileClientRuntimeOptions runtime_options_;
struct FileStats
{
@ -1571,13 +1605,16 @@ private:
std::reference_wrapper<std::ostream> os_;
};
OtlpFileClient::OtlpFileClient(OtlpFileClientOptions &&options)
: is_shutdown_(false), options_(std::move(options))
OtlpFileClient::OtlpFileClient(OtlpFileClientOptions &&options,
OtlpFileClientRuntimeOptions &&runtime_options)
: is_shutdown_(false),
options_(std::move(options)),
runtime_options_(std::move(runtime_options))
{
if (nostd::holds_alternative<OtlpFileClientFileSystemOptions>(options_.backend_options))
{
backend_ = opentelemetry::nostd::shared_ptr<OtlpFileAppender>(new OtlpFileSystemBackend(
nostd::get<OtlpFileClientFileSystemOptions>(options_.backend_options)));
nostd::get<OtlpFileClientFileSystemOptions>(options_.backend_options), runtime_options_));
}
else if (nostd::holds_alternative<std::reference_wrapper<std::ostream>>(options_.backend_options))
{

View File

@ -11,6 +11,7 @@
#include "opentelemetry/exporters/otlp/otlp_file_client_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_recordable.h"
#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h"
#include "opentelemetry/nostd/span.h"
@ -35,7 +36,15 @@ namespace otlp
OtlpFileExporter::OtlpFileExporter() : OtlpFileExporter(OtlpFileExporterOptions()) {}
OtlpFileExporter::OtlpFileExporter(const OtlpFileExporterOptions &options)
: options_(options), file_client_(new OtlpFileClient(OtlpFileClientOptions(options)))
: OtlpFileExporter(options, OtlpFileExporterRuntimeOptions())
{}
OtlpFileExporter::OtlpFileExporter(const OtlpFileExporterOptions &options,
const OtlpFileExporterRuntimeOptions &runtime_options)
: options_(options),
runtime_options_(runtime_options),
file_client_(new OtlpFileClient(OtlpFileClientOptions(options),
OtlpFileExporterRuntimeOptions(runtime_options)))
{}
// ----------------------------- Exporter methods ------------------------------

View File

@ -2,9 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
#include "opentelemetry/exporters/otlp/otlp_file_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_exporter_runtime_options.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
@ -21,7 +22,16 @@ std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> OtlpFileExporterFactory
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> OtlpFileExporterFactory::Create(
const OtlpFileExporterOptions &options)
{
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> exporter(new OtlpFileExporter(options));
OtlpFileExporterRuntimeOptions runtime_options;
return Create(options, runtime_options);
}
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> OtlpFileExporterFactory::Create(
const OtlpFileExporterOptions &options,
const OtlpFileExporterRuntimeOptions &runtime_options)
{
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> exporter(
new OtlpFileExporter(options, runtime_options));
return exporter;
}

View File

@ -11,6 +11,7 @@
#include "opentelemetry/exporters/otlp/otlp_file_client_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_log_recordable.h"
#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h"
#include "opentelemetry/nostd/span.h"
@ -38,7 +39,16 @@ OtlpFileLogRecordExporter::OtlpFileLogRecordExporter()
OtlpFileLogRecordExporter::OtlpFileLogRecordExporter(
const OtlpFileLogRecordExporterOptions &options)
: options_(options), file_client_(new OtlpFileClient(OtlpFileClientOptions(options)))
: OtlpFileLogRecordExporter(options, OtlpFileLogRecordExporterRuntimeOptions())
{}
OtlpFileLogRecordExporter::OtlpFileLogRecordExporter(
const OtlpFileLogRecordExporterOptions &options,
const OtlpFileLogRecordExporterRuntimeOptions &runtime_options)
: options_(options),
runtime_options_(runtime_options),
file_client_(new OtlpFileClient(OtlpFileClientOptions(options),
OtlpFileLogRecordExporterRuntimeOptions(runtime_options)))
{}
// ----------------------------- Exporter methods ------------------------------

View File

@ -4,6 +4,8 @@
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_log_record_exporter_runtime_options.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
@ -20,9 +22,18 @@ OtlpFileLogRecordExporterFactory::Create()
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
OtlpFileLogRecordExporterFactory::Create(const OtlpFileLogRecordExporterOptions &options)
{
OtlpFileLogRecordExporterRuntimeOptions runtime_options;
return Create(options, runtime_options);
}
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
OtlpFileLogRecordExporterFactory::Create(
const OtlpFileLogRecordExporterOptions &options,
const OtlpFileLogRecordExporterRuntimeOptions &runtime_options)
{
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> exporter(
new OtlpFileLogRecordExporter(options));
new OtlpFileLogRecordExporter(options, runtime_options));
return exporter;
}

View File

@ -10,8 +10,10 @@
#include "opentelemetry/exporters/otlp/otlp_file_client.h"
#include "opentelemetry/exporters/otlp/otlp_file_client_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_client_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_metric_utils.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/common/global_log_handler.h"
@ -37,10 +39,18 @@ OtlpFileMetricExporter::OtlpFileMetricExporter()
{}
OtlpFileMetricExporter::OtlpFileMetricExporter(const OtlpFileMetricExporterOptions &options)
: OtlpFileMetricExporter(options, OtlpFileMetricExporterRuntimeOptions())
{}
OtlpFileMetricExporter::OtlpFileMetricExporter(
const OtlpFileMetricExporterOptions &options,
const OtlpFileMetricExporterRuntimeOptions &runtime_options)
: options_(options),
runtime_options_(runtime_options),
aggregation_temporality_selector_{
OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)},
file_client_(new OtlpFileClient(OtlpFileClientOptions(options)))
file_client_(new OtlpFileClient(OtlpFileClientOptions(options),
OtlpFileClientRuntimeOptions(runtime_options)))
{}
// ----------------------------- Exporter methods ------------------------------

View File

@ -4,6 +4,8 @@
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_metric_exporter_runtime_options.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
@ -20,9 +22,17 @@ OtlpFileMetricExporterFactory::Create()
std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter>
OtlpFileMetricExporterFactory::Create(const OtlpFileMetricExporterOptions &options)
{
OtlpFileMetricExporterRuntimeOptions runtime_options;
return Create(options, runtime_options);
}
std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter>
OtlpFileMetricExporterFactory::Create(const OtlpFileMetricExporterOptions &options,
const OtlpFileMetricExporterRuntimeOptions &runtime_options)
{
std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> exporter(
new OtlpFileMetricExporter(options));
new OtlpFileMetricExporter(options, runtime_options));
return exporter;
}

View File

@ -666,7 +666,7 @@ void ConvertListFieldToJson(nlohmann::json &value,
OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options)
: is_shutdown_(false),
options_(options),
http_client_(http_client::HttpClientFactory::Create()),
http_client_(http_client::HttpClientFactory::Create(options.thread_instrumentation)),
start_session_counter_(0),
finished_session_counter_(0)
{

View File

@ -12,6 +12,7 @@
#include "opentelemetry/exporters/otlp/otlp_http_client.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_recordable.h"
#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h"
#include "opentelemetry/nostd/span.h"
@ -38,6 +39,40 @@ OtlpHttpExporter::OtlpHttpExporter() : OtlpHttpExporter(OtlpHttpExporterOptions(
OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options)
: options_(options),
runtime_options_(),
http_client_(new OtlpHttpClient(OtlpHttpClientOptions(
options.url,
options.ssl_insecure_skip_verify,
options.ssl_ca_cert_path,
options.ssl_ca_cert_string,
options.ssl_client_key_path,
options.ssl_client_key_string,
options.ssl_client_cert_path,
options.ssl_client_cert_string,
options.ssl_min_tls,
options.ssl_max_tls,
options.ssl_cipher,
options.ssl_cipher_suite,
options.content_type,
options.json_bytes_mapping,
options.compression,
options.use_json_name,
options.console_debug,
options.timeout,
options.http_headers,
std::shared_ptr<sdk::common::ThreadInstrumentation>{nullptr}
#ifdef ENABLE_ASYNC_EXPORT
,
options.max_concurrent_requests,
options.max_requests_per_connection
#endif
)))
{}
OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options,
const OtlpHttpExporterRuntimeOptions &runtime_options)
: options_(options),
runtime_options_(runtime_options),
http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url,
options.ssl_insecure_skip_verify,
options.ssl_ca_cert_path,
@ -56,7 +91,8 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options)
options.use_json_name,
options.console_debug,
options.timeout,
options.http_headers
options.http_headers,
runtime_options.thread_instrumentation
#ifdef ENABLE_ASYNC_EXPORT
,
options.max_concurrent_requests,
@ -68,18 +104,18 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options)
OtlpHttpExporter::OtlpHttpExporter(std::unique_ptr<OtlpHttpClient> http_client)
: options_(OtlpHttpExporterOptions()), http_client_(std::move(http_client))
{
OtlpHttpExporterOptions &options = const_cast<OtlpHttpExporterOptions &>(options_);
options.url = http_client_->GetOptions().url;
options.content_type = http_client_->GetOptions().content_type;
options.json_bytes_mapping = http_client_->GetOptions().json_bytes_mapping;
options.use_json_name = http_client_->GetOptions().use_json_name;
options.console_debug = http_client_->GetOptions().console_debug;
options.timeout = http_client_->GetOptions().timeout;
options.http_headers = http_client_->GetOptions().http_headers;
options_.url = http_client_->GetOptions().url;
options_.content_type = http_client_->GetOptions().content_type;
options_.json_bytes_mapping = http_client_->GetOptions().json_bytes_mapping;
options_.use_json_name = http_client_->GetOptions().use_json_name;
options_.console_debug = http_client_->GetOptions().console_debug;
options_.timeout = http_client_->GetOptions().timeout;
options_.http_headers = http_client_->GetOptions().http_headers;
#ifdef ENABLE_ASYNC_EXPORT
options.max_concurrent_requests = http_client_->GetOptions().max_concurrent_requests;
options.max_requests_per_connection = http_client_->GetOptions().max_requests_per_connection;
options_.max_concurrent_requests = http_client_->GetOptions().max_concurrent_requests;
options_.max_requests_per_connection = http_client_->GetOptions().max_requests_per_connection;
#endif
runtime_options_.thread_instrumentation = http_client_->GetOptions().thread_instrumentation;
}
// ----------------------------- Exporter methods ------------------------------

View File

@ -4,6 +4,7 @@
#include "opentelemetry/exporters/otlp/otlp_http_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_exporter_runtime_options.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
@ -20,7 +21,16 @@ std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> OtlpHttpExporterFactory
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> OtlpHttpExporterFactory::Create(
const OtlpHttpExporterOptions &options)
{
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> exporter(new OtlpHttpExporter(options));
OtlpHttpExporterRuntimeOptions runtime_options;
return Create(options, runtime_options);
}
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> OtlpHttpExporterFactory::Create(
const OtlpHttpExporterOptions &options,
const OtlpHttpExporterRuntimeOptions &runtime_options)
{
std::unique_ptr<opentelemetry::sdk::trace::SpanExporter> exporter(
new OtlpHttpExporter(options, runtime_options));
return exporter;
}

View File

@ -12,12 +12,14 @@
#include "opentelemetry/exporters/otlp/otlp_http_client.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_log_recordable.h"
#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/common/global_log_handler.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/sdk/logs/recordable.h"
#include "opentelemetry/version.h"
@ -41,6 +43,41 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter()
OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(
const OtlpHttpLogRecordExporterOptions &options)
: options_(options),
runtime_options_(),
http_client_(new OtlpHttpClient(OtlpHttpClientOptions(
options.url,
options.ssl_insecure_skip_verify,
options.ssl_ca_cert_path,
options.ssl_ca_cert_string,
options.ssl_client_key_path,
options.ssl_client_key_string,
options.ssl_client_cert_path,
options.ssl_client_cert_string,
options.ssl_min_tls,
options.ssl_max_tls,
options.ssl_cipher,
options.ssl_cipher_suite,
options.content_type,
options.json_bytes_mapping,
options.compression,
options.use_json_name,
options.console_debug,
options.timeout,
options.http_headers,
std::shared_ptr<sdk::common::ThreadInstrumentation>{nullptr}
#ifdef ENABLE_ASYNC_EXPORT
,
options.max_concurrent_requests,
options.max_requests_per_connection
#endif
)))
{}
OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(
const OtlpHttpLogRecordExporterOptions &options,
const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options)
: options_(options),
runtime_options_(runtime_options),
http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url,
options.ssl_insecure_skip_verify,
options.ssl_ca_cert_path,
@ -59,7 +96,8 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(
options.use_json_name,
options.console_debug,
options.timeout,
options.http_headers
options.http_headers,
runtime_options.thread_instrumentation
#ifdef ENABLE_ASYNC_EXPORT
,
options.max_concurrent_requests,
@ -71,19 +109,18 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(
OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(std::unique_ptr<OtlpHttpClient> http_client)
: options_(OtlpHttpLogRecordExporterOptions()), http_client_(std::move(http_client))
{
OtlpHttpLogRecordExporterOptions &options =
const_cast<OtlpHttpLogRecordExporterOptions &>(options_);
options.url = http_client_->GetOptions().url;
options.content_type = http_client_->GetOptions().content_type;
options.json_bytes_mapping = http_client_->GetOptions().json_bytes_mapping;
options.use_json_name = http_client_->GetOptions().use_json_name;
options.console_debug = http_client_->GetOptions().console_debug;
options.timeout = http_client_->GetOptions().timeout;
options.http_headers = http_client_->GetOptions().http_headers;
options_.url = http_client_->GetOptions().url;
options_.content_type = http_client_->GetOptions().content_type;
options_.json_bytes_mapping = http_client_->GetOptions().json_bytes_mapping;
options_.use_json_name = http_client_->GetOptions().use_json_name;
options_.console_debug = http_client_->GetOptions().console_debug;
options_.timeout = http_client_->GetOptions().timeout;
options_.http_headers = http_client_->GetOptions().http_headers;
#ifdef ENABLE_ASYNC_EXPORT
options.max_concurrent_requests = http_client_->GetOptions().max_concurrent_requests;
options.max_requests_per_connection = http_client_->GetOptions().max_requests_per_connection;
options_.max_concurrent_requests = http_client_->GetOptions().max_concurrent_requests;
options_.max_requests_per_connection = http_client_->GetOptions().max_requests_per_connection;
#endif
runtime_options_.thread_instrumentation = http_client_->GetOptions().thread_instrumentation;
}
// ----------------------------- Exporter methods ------------------------------

View File

@ -4,6 +4,7 @@
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_log_record_exporter_runtime_options.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
@ -20,9 +21,18 @@ OtlpHttpLogRecordExporterFactory::Create()
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
OtlpHttpLogRecordExporterFactory::Create(const OtlpHttpLogRecordExporterOptions &options)
{
OtlpHttpLogRecordExporterRuntimeOptions runtime_options;
return Create(options, runtime_options);
}
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter>
OtlpHttpLogRecordExporterFactory::Create(
const OtlpHttpLogRecordExporterOptions &options,
const OtlpHttpLogRecordExporterRuntimeOptions &runtime_options)
{
std::unique_ptr<opentelemetry::sdk::logs::LogRecordExporter> exporter(
new OtlpHttpLogRecordExporter(options));
new OtlpHttpLogRecordExporter(options, runtime_options));
return exporter;
}

View File

@ -13,10 +13,12 @@
#include "opentelemetry/exporters/otlp/otlp_http_client.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_metric_utils.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/common/global_log_handler.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
#include "opentelemetry/sdk/metrics/instruments.h"
#include "opentelemetry/version.h"
@ -40,6 +42,43 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter()
OtlpHttpMetricExporter::OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptions &options)
: options_(options),
runtime_options_(),
aggregation_temporality_selector_{
OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)},
http_client_(new OtlpHttpClient(OtlpHttpClientOptions(
options.url,
options.ssl_insecure_skip_verify,
options.ssl_ca_cert_path,
options.ssl_ca_cert_string,
options.ssl_client_key_path,
options.ssl_client_key_string,
options.ssl_client_cert_path,
options.ssl_client_cert_string,
options.ssl_min_tls,
options.ssl_max_tls,
options.ssl_cipher,
options.ssl_cipher_suite,
options.content_type,
options.json_bytes_mapping,
options.compression,
options.use_json_name,
options.console_debug,
options.timeout,
options.http_headers,
std::shared_ptr<sdk::common::ThreadInstrumentation>{nullptr}
#ifdef ENABLE_ASYNC_EXPORT
,
options.max_concurrent_requests,
options.max_requests_per_connection
#endif
)))
{}
OtlpHttpMetricExporter::OtlpHttpMetricExporter(
const OtlpHttpMetricExporterOptions &options,
const OtlpHttpMetricExporterRuntimeOptions &runtime_options)
: options_(options),
runtime_options_(runtime_options),
aggregation_temporality_selector_{
OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)},
http_client_(new OtlpHttpClient(OtlpHttpClientOptions(options.url,
@ -60,7 +99,8 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptio
options.use_json_name,
options.console_debug,
options.timeout,
options.http_headers
options.http_headers,
runtime_options.thread_instrumentation
#ifdef ENABLE_ASYNC_EXPORT
,
options.max_concurrent_requests,
@ -75,18 +115,18 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter(std::unique_ptr<OtlpHttpClient> h
OtlpMetricUtils::ChooseTemporalitySelector(options_.aggregation_temporality)},
http_client_(std::move(http_client))
{
OtlpHttpMetricExporterOptions &options = const_cast<OtlpHttpMetricExporterOptions &>(options_);
options.url = http_client_->GetOptions().url;
options.content_type = http_client_->GetOptions().content_type;
options.json_bytes_mapping = http_client_->GetOptions().json_bytes_mapping;
options.use_json_name = http_client_->GetOptions().use_json_name;
options.console_debug = http_client_->GetOptions().console_debug;
options.timeout = http_client_->GetOptions().timeout;
options.http_headers = http_client_->GetOptions().http_headers;
options_.url = http_client_->GetOptions().url;
options_.content_type = http_client_->GetOptions().content_type;
options_.json_bytes_mapping = http_client_->GetOptions().json_bytes_mapping;
options_.use_json_name = http_client_->GetOptions().use_json_name;
options_.console_debug = http_client_->GetOptions().console_debug;
options_.timeout = http_client_->GetOptions().timeout;
options_.http_headers = http_client_->GetOptions().http_headers;
#ifdef ENABLE_ASYNC_EXPORT
options.max_concurrent_requests = http_client_->GetOptions().max_concurrent_requests;
options.max_requests_per_connection = http_client_->GetOptions().max_requests_per_connection;
options_.max_concurrent_requests = http_client_->GetOptions().max_concurrent_requests;
options_.max_requests_per_connection = http_client_->GetOptions().max_requests_per_connection;
#endif
runtime_options_.thread_instrumentation = http_client_->GetOptions().thread_instrumentation;
}
// ----------------------------- Exporter methods ------------------------------

View File

@ -4,6 +4,7 @@
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_factory.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h"
#include "opentelemetry/exporters/otlp/otlp_http_metric_exporter_runtime_options.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
@ -20,9 +21,17 @@ OtlpHttpMetricExporterFactory::Create()
std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter>
OtlpHttpMetricExporterFactory::Create(const OtlpHttpMetricExporterOptions &options)
{
OtlpHttpMetricExporterRuntimeOptions runtime_options;
return Create(options, runtime_options);
}
std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter>
OtlpHttpMetricExporterFactory::Create(const OtlpHttpMetricExporterOptions &options,
const OtlpHttpMetricExporterRuntimeOptions &runtime_options)
{
std::unique_ptr<opentelemetry::sdk::metrics::PushMetricExporter> exporter(
new OtlpHttpMetricExporter(options));
new OtlpHttpMetricExporter(options, runtime_options));
return exporter;
}

View File

@ -19,6 +19,7 @@
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/exporters/otlp/otlp_file_client.h"
#include "opentelemetry/exporters/otlp/otlp_file_client_options.h"
#include "opentelemetry/exporters/otlp/otlp_file_client_runtime_options.h"
#include "opentelemetry/exporters/otlp/otlp_recordable.h"
#include "opentelemetry/exporters/otlp/otlp_recordable_utils.h"
#include "opentelemetry/nostd/shared_ptr.h"
@ -158,7 +159,8 @@ TEST(OtlpFileClientTest, Shutdown)
opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest request;
auto client = std::unique_ptr<opentelemetry::exporter::otlp::OtlpFileClient>(
new opentelemetry::exporter::otlp::OtlpFileClient(
opentelemetry::exporter::otlp::OtlpFileClientOptions()));
opentelemetry::exporter::otlp::OtlpFileClientOptions(),
opentelemetry::exporter::otlp::OtlpFileClientRuntimeOptions()));
ASSERT_FALSE(client->IsShutdown());
ASSERT_TRUE(client->Shutdown());
ASSERT_TRUE(client->IsShutdown());
@ -181,10 +183,11 @@ TEST(OtlpFileClientTest, ExportToOstreamTest)
std::stringstream output_stream;
opentelemetry::exporter::otlp::OtlpFileClientOptions opts;
opentelemetry::exporter::otlp::OtlpFileClientRuntimeOptions rt_opts;
opts.backend_options = std::ref(output_stream);
auto client = std::unique_ptr<opentelemetry::exporter::otlp::OtlpFileClient>(
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts)));
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts), std::move(rt_opts)));
client->Export(request, 1);
{
@ -280,10 +283,11 @@ TEST(OtlpFileClientTest, ExportToFileSystemRotateIndexTest)
backend_opts.rotate_size = 3;
opentelemetry::exporter::otlp::OtlpFileClientOptions opts;
opentelemetry::exporter::otlp::OtlpFileClientRuntimeOptions rt_opts;
opts.backend_options = backend_opts;
auto client = std::unique_ptr<opentelemetry::exporter::otlp::OtlpFileClient>(
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts)));
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts), std::move(rt_opts)));
// Write 5 records with rotatation index 1,2,3,1,2
for (int i = 0; i < 4; ++i)
@ -401,10 +405,11 @@ TEST(OtlpFileClientTest, ExportToFileSystemRotateByTimeTest)
backend_opts.file_size = 1500;
opentelemetry::exporter::otlp::OtlpFileClientOptions opts;
opentelemetry::exporter::otlp::OtlpFileClientRuntimeOptions rt_opts;
opts.backend_options = backend_opts;
auto client = std::unique_ptr<opentelemetry::exporter::otlp::OtlpFileClient>(
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts)));
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts), std::move(rt_opts)));
auto start_time = std::chrono::system_clock::now();
client->Export(request, 1);
@ -508,11 +513,12 @@ TEST(OtlpFileClientTest, ConfigTest)
{
{
opentelemetry::exporter::otlp::OtlpFileClientOptions opts;
opentelemetry::exporter::otlp::OtlpFileClientRuntimeOptions rt_opts;
opts.console_debug = true;
opts.backend_options = std::ref(std::cout);
auto client = std::unique_ptr<opentelemetry::exporter::otlp::OtlpFileClient>(
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts)));
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts), std::move(rt_opts)));
ASSERT_TRUE(client->GetOptions().console_debug);
ASSERT_TRUE(opentelemetry::nostd::holds_alternative<std::reference_wrapper<std::ostream>>(
@ -524,11 +530,12 @@ TEST(OtlpFileClientTest, ConfigTest)
backend_opts.file_pattern = "test_file_pattern.jsonl";
opentelemetry::exporter::otlp::OtlpFileClientOptions opts;
opentelemetry::exporter::otlp::OtlpFileClientRuntimeOptions rt_opts;
opts.console_debug = false;
opts.backend_options = backend_opts;
auto client = std::unique_ptr<opentelemetry::exporter::otlp::OtlpFileClient>(
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts)));
new opentelemetry::exporter::otlp::OtlpFileClient(std::move(opts), std::move(rt_opts)));
ASSERT_FALSE(client->GetOptions().console_debug);
ASSERT_TRUE(opentelemetry::nostd::holds_alternative<

View File

@ -54,6 +54,7 @@ static nostd::span<T, N> MakeSpan(T (&array)[N])
OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type,
bool async_mode)
{
std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation> not_instrumented;
OtlpHttpExporterOptions options;
options.content_type = content_type;
options.console_debug = true;
@ -70,7 +71,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t
"", /* ssl_cipher */
"", /* ssl_cipher_suite */
options.content_type, options.json_bytes_mapping, options.compression, options.use_json_name,
options.console_debug, options.timeout, options.http_headers);
options.console_debug, options.timeout, options.http_headers, not_instrumented);
if (!async_mode)
{
otlp_http_client_options.max_concurrent_requests = 0;

View File

@ -54,6 +54,7 @@ static nostd::span<T, N> MakeSpan(T (&array)[N])
OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type,
bool async_mode)
{
std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation> not_instrumented;
OtlpHttpLogRecordExporterOptions options;
options.content_type = content_type;
options.console_debug = true;
@ -69,7 +70,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t
"", /* ssl_cipher */
"", /* ssl_cipher_suite */
options.content_type, options.json_bytes_mapping, options.compression, options.use_json_name,
options.console_debug, options.timeout, options.http_headers);
options.console_debug, options.timeout, options.http_headers, not_instrumented);
if (!async_mode)
{
otlp_http_client_options.max_concurrent_requests = 0;

View File

@ -26,6 +26,7 @@
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/nostd/unique_ptr.h"
#include "opentelemetry/sdk/common/exporter_utils.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/metrics/data/metric_data.h"
#include "opentelemetry/sdk/metrics/data/point_data.h"
@ -74,6 +75,7 @@ static IntegerType JsonToInteger(nlohmann::json value)
OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type,
bool async_mode)
{
std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation> not_instrumented;
OtlpHttpMetricExporterOptions options;
options.content_type = content_type;
options.console_debug = true;
@ -89,7 +91,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t
"", /* ssl_cipher */
"", /* ssl_cipher_suite */
options.content_type, options.json_bytes_mapping, options.compression, options.use_json_name,
options.console_debug, options.timeout, options.http_headers);
options.console_debug, options.timeout, options.http_headers, not_instrumented);
if (!async_mode)
{
otlp_http_client_options.max_concurrent_requests = 0;

View File

@ -23,6 +23,7 @@
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
@ -302,6 +303,7 @@ class HttpClient : public opentelemetry::ext::http::client::HttpClient
public:
// The call (curl_global_init) is not thread safe. Ensure this is called only once.
HttpClient();
HttpClient(const std::shared_ptr<sdk::common::ThreadInstrumentation> &thread_instrumentation);
~HttpClient() override;
std::shared_ptr<opentelemetry::ext::http::client::Session> CreateSession(
@ -355,6 +357,7 @@ private:
std::mutex background_thread_m_;
std::unique_ptr<std::thread> background_thread_;
std::shared_ptr<sdk::common::ThreadInstrumentation> background_thread_instrumentation_;
std::chrono::milliseconds scheduled_delay_milliseconds_;
std::chrono::milliseconds background_thread_wait_for_;

View File

@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "opentelemetry/ext/http/client/http_client.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace ext
@ -17,6 +20,8 @@ public:
static std::shared_ptr<HttpClientSync> CreateSync();
static std::shared_ptr<HttpClient> Create();
static std::shared_ptr<HttpClient> Create(
const std::shared_ptr<sdk::common::ThreadInstrumentation> &thread_instrumentation);
};
} // namespace client
} // namespace http

View File

@ -25,6 +25,7 @@
#include "opentelemetry/ext/http/common/url_parser.h"
#include "opentelemetry/nostd/shared_ptr.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
#ifdef ENABLE_OTLP_COMPRESSION_PREVIEW
@ -269,6 +270,18 @@ HttpClient::HttpClient()
: multi_handle_(curl_multi_init()),
next_session_id_{0},
max_sessions_per_connection_{8},
background_thread_instrumentation_(nullptr),
scheduled_delay_milliseconds_{std::chrono::milliseconds(256)},
background_thread_wait_for_{std::chrono::minutes{1}},
curl_global_initializer_(HttpCurlGlobalInitializer::GetInstance())
{}
HttpClient::HttpClient(
const std::shared_ptr<sdk::common::ThreadInstrumentation> &thread_instrumentation)
: multi_handle_(curl_multi_init()),
next_session_id_{0},
max_sessions_per_connection_{8},
background_thread_instrumentation_(thread_instrumentation),
scheduled_delay_milliseconds_{std::chrono::milliseconds(256)},
background_thread_wait_for_{std::chrono::minutes{1}},
curl_global_initializer_(HttpCurlGlobalInitializer::GetInstance())
@ -429,6 +442,13 @@ bool HttpClient::MaybeSpawnBackgroundThread()
background_thread_.reset(new std::thread(
[](HttpClient *self) {
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (self->background_thread_instrumentation_ != nullptr)
{
self->background_thread_instrumentation_->OnStart();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
int still_running = 1;
std::chrono::system_clock::time_point last_free_job_timepoint =
std::chrono::system_clock::now();
@ -447,6 +467,13 @@ bool HttpClient::MaybeSpawnBackgroundThread()
}
else if (still_running || need_wait_more)
{
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (self->background_thread_instrumentation_ != nullptr)
{
self->background_thread_instrumentation_->BeforeWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
// curl_multi_poll is added from libcurl 7.66.0, before 7.68.0, we can only wait util
// timeout to do the rest jobs
#if LIBCURL_VERSION_NUM >= 0x074200
@ -459,6 +486,13 @@ bool HttpClient::MaybeSpawnBackgroundThread()
static_cast<int>(self->scheduled_delay_milliseconds_.count()),
nullptr);
#endif
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (self->background_thread_instrumentation_ != nullptr)
{
self->background_thread_instrumentation_->AfterWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
}
do
@ -557,6 +591,13 @@ bool HttpClient::MaybeSpawnBackgroundThread()
// If there is no pending jobs, we can stop the background thread.
if (still_running == 0)
{
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (self->background_thread_instrumentation_ != nullptr)
{
self->background_thread_instrumentation_->OnEnd();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
if (self->background_thread_)
{
self->background_thread_->detach();

View File

@ -6,6 +6,7 @@
#include "opentelemetry/ext/http/client/curl/http_client_curl.h"
#include "opentelemetry/ext/http/client/http_client.h"
#include "opentelemetry/ext/http/client/http_client_factory.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
namespace http_client = opentelemetry::ext::http::client;
@ -14,6 +15,12 @@ std::shared_ptr<http_client::HttpClient> http_client::HttpClientFactory::Create(
return std::make_shared<http_client::curl::HttpClient>();
}
std::shared_ptr<http_client::HttpClient> http_client::HttpClientFactory::Create(
const std::shared_ptr<sdk::common::ThreadInstrumentation> &thread_instrumentation)
{
return std::make_shared<http_client::curl::HttpClient>(thread_instrumentation);
}
std::shared_ptr<http_client::HttpClientSync> http_client::HttpClientFactory::CreateSync()
{
return std::make_shared<http_client::curl::HttpClientSync>();

View File

@ -0,0 +1,92 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace common
{
/**
* Thread instrumentation interface.
* When the opentelemetry-cpp library executes internal threads,
* the application linking with the opentelemetry-cpp library
* may want to have some control on how the thread executes.
*
* There are many different use cases for this,
* listing a few to illustrate.
*
* (1) The application may need to initialize thread local storage,
* in an application specific way, because application code that
* relies on thread local storage will be executed in the thread code path.
* For example, custom samplers for traces, or custom observable instruments
* for metrics, may expect specific thread local storage keys to exist.
*
* (2) The application may want opentelemetry-cpp threads to be observable
* in a given way when exposed to the operating system.
* For example, a linux application may want to give a name to
* opentelemetry-cpp threads,
* using [pthread_setname_np(3)](https://man7.org/linux/man-pages/man3/pthread_setname_np.3.html),
* to help troubleshooting.
*
* (3) The application may want specific opentelemetry-cpp threads to use
* application defined specific named network.
* For example, a linux application may want to use
* [setns(2)](https://man7.org/linux/man-pages/man2/setns.2.html)
* on a per exporter basis, so that different exporters uses different networks.
*
* (4) The application may want to bind specific opentelemetry-cpp threads
* to specific CPUs, for performance reasons.
* For example, a linux application may want to use
* [sched_setaffinity(2)](https://man7.org/linux/man-pages/man2/sched_setaffinity.2.html)
* on a per thread basis.
*
* Providing dedicated opentelemetry-cpp interfaces in the SDK or exporters,
* to support these use cases, is not practical, because the code involved
* is highly platform dependent and use case dependent.
*
* Instead, the opentelemetry-cpp library provide hooks for applications
* to implement their own, arbitrary, platform specific, logic.
* This is done by implementing the ThreadInstrumentation interface
* in the application, and providing a given ThreadInstrumentation object
* when initializing the SDK or exporters.
*
* The opentelemetry-cpp library calls the following extension points,
* when a ThreadInstrumentation is provided.
*
* Upon thread creation and termination, the methods OnStart() and OnEnd()
* are invoked, respectively.
*
* When a thread is to block and wait, for example on a timer,
* the methods BeforeWait() and AfterWait() are invoked.
*
* When a thread is to perform a chunk of work,
* for example to process all the available data in an exporter,
* the methods BeforeLoad() and AfterLoad() are invoked.
*/
class ThreadInstrumentation
{
public:
ThreadInstrumentation() = default;
virtual ~ThreadInstrumentation() = default;
/*
* This feature is experimental, protected by a _PREVIEW flag.
*/
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
virtual void OnStart() {}
virtual void OnEnd() {}
virtual void BeforeWait() {}
virtual void AfterWait() {}
virtual void BeforeLoad() {}
virtual void AfterLoad() {}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
};
} // namespace common
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

View File

@ -14,6 +14,7 @@
#include "opentelemetry/sdk/common/circular_buffer.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_runtime_options.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/processor.h"
#include "opentelemetry/sdk/logs/recordable.h"
@ -54,12 +55,24 @@ public:
* Creates a batch log processor by configuring the specified exporter and other parameters
* as per the official, language-agnostic opentelemetry specs.
*
* @param exporter - The backend exporter to pass the logs to
* @param options - The batch SpanProcessor options.
* @param exporter The backend exporter to pass the logs to
* @param options The batch SpanProcessor configuration options.
*/
explicit BatchLogRecordProcessor(std::unique_ptr<LogRecordExporter> &&exporter,
const BatchLogRecordProcessorOptions &options);
/**
* Creates a batch log processor by configuring the specified exporter and other parameters
* as per the official, language-agnostic opentelemetry specs.
*
* @param exporter The backend exporter to pass the logs to
* @param options The batch SpanProcessor configuration options.
* @param runtime_options The batch SpanProcessor runtime options.
*/
explicit BatchLogRecordProcessor(std::unique_ptr<LogRecordExporter> &&exporter,
const BatchLogRecordProcessorOptions &options,
const BatchLogRecordProcessorRuntimeOptions &runtime_options);
/** Makes a new recordable **/
std::unique_ptr<Recordable> MakeRecordable() noexcept override;
@ -157,6 +170,7 @@ protected:
std::shared_ptr<SynchronizationData> synchronization_data_;
/* The background worker thread */
std::shared_ptr<sdk::common::ThreadInstrumentation> worker_thread_instrumentation_;
std::thread worker_thread_;
};

View File

@ -6,6 +6,7 @@
#include <memory>
#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_runtime_options.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/processor.h"
#include "opentelemetry/version.h"
@ -28,6 +29,14 @@ public:
*/
static std::unique_ptr<LogRecordProcessor> Create(std::unique_ptr<LogRecordExporter> &&exporter,
const BatchLogRecordProcessorOptions &options);
/**
* Create a BatchLogRecordProcessor.
*/
static std::unique_ptr<LogRecordProcessor> Create(
std::unique_ptr<LogRecordExporter> &&exporter,
const BatchLogRecordProcessorOptions &options,
const BatchLogRecordProcessorRuntimeOptions &runtime_options);
};
} // namespace logs

View File

@ -0,0 +1,30 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <chrono>
#include <cstddef>
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace logs
{
/**
* Struct to hold batch SpanProcessor runtime options.
*/
struct BatchLogRecordProcessorRuntimeOptions
{
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation =
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
};
} // namespace logs
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

View File

@ -11,7 +11,9 @@
#include <mutex>
#include <thread>
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_runtime_options.h"
#include "opentelemetry/sdk/metrics/instruments.h"
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
@ -28,7 +30,11 @@ class PeriodicExportingMetricReader : public MetricReader
public:
PeriodicExportingMetricReader(std::unique_ptr<PushMetricExporter> exporter,
const PeriodicExportingMetricReaderOptions &option);
const PeriodicExportingMetricReaderOptions &options);
PeriodicExportingMetricReader(std::unique_ptr<PushMetricExporter> exporter,
const PeriodicExportingMetricReaderOptions &options,
const PeriodicExportingMetricReaderRuntimeOptions &runtime_options);
AggregationTemporality GetAggregationTemporality(
InstrumentType instrument_type) const noexcept override;
@ -47,15 +53,17 @@ private:
void DoBackgroundWork();
bool CollectAndExportOnce();
/* The background worker thread */
std::thread worker_thread_;
/* Synchronization primitives */
std::atomic<bool> is_force_wakeup_background_worker_{false};
std::atomic<uint64_t> force_flush_pending_sequence_{0};
std::atomic<uint64_t> force_flush_notified_sequence_{0};
std::condition_variable cv_, force_flush_cv_;
std::mutex cv_m_, force_flush_m_;
/* The background worker thread */
std::shared_ptr<sdk::common::ThreadInstrumentation> worker_thread_instrumentation_;
std::shared_ptr<sdk::common::ThreadInstrumentation> collect_thread_instrumentation_;
std::thread worker_thread_;
};
} // namespace metrics

View File

@ -6,6 +6,7 @@
#include <memory>
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_runtime_options.h"
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/version.h"
@ -20,7 +21,12 @@ class OPENTELEMETRY_EXPORT PeriodicExportingMetricReaderFactory
{
public:
static std::unique_ptr<MetricReader> Create(std::unique_ptr<PushMetricExporter> exporter,
const PeriodicExportingMetricReaderOptions &option);
const PeriodicExportingMetricReaderOptions &options);
static std::unique_ptr<MetricReader> Create(
std::unique_ptr<PushMetricExporter> exporter,
const PeriodicExportingMetricReaderOptions &options,
const PeriodicExportingMetricReaderRuntimeOptions &runtime_options);
};
} // namespace metrics

View File

@ -0,0 +1,30 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <memory>
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace metrics
{
/**
* Struct to hold PeriodicExortingMetricReader runtime options.
*/
struct PeriodicExportingMetricReaderRuntimeOptions
{
std::shared_ptr<sdk::common::ThreadInstrumentation> periodic_thread_instrumentation =
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
std::shared_ptr<sdk::common::ThreadInstrumentation> collect_thread_instrumentation =
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
};
} // namespace metrics
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

View File

@ -14,6 +14,7 @@
#include "opentelemetry/sdk/common/circular_buffer.h"
#include "opentelemetry/sdk/trace/batch_span_processor_options.h"
#include "opentelemetry/sdk/trace/batch_span_processor_runtime_options.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/recordable.h"
@ -37,12 +38,24 @@ public:
* Creates a batch span processor by configuring the specified exporter and other parameters
* as per the official, language-agnostic opentelemetry specs.
*
* @param exporter - The backend exporter to pass the ended spans to.
* @param options - The batch SpanProcessor options.
* @param exporter The backend exporter to pass the ended spans to.
* @param options The batch SpanProcessor configuration options.
*/
BatchSpanProcessor(std::unique_ptr<SpanExporter> &&exporter,
const BatchSpanProcessorOptions &options);
/**
* Creates a batch span processor by configuring the specified exporter and other parameters
* as per the official, language-agnostic opentelemetry specs.
*
* @param exporter The backend exporter to pass the ended spans to.
* @param options The batch SpanProcessor configuration options.
* @param runtime_options The batch SpanProcessor runtime options.
*/
BatchSpanProcessor(std::unique_ptr<SpanExporter> &&exporter,
const BatchSpanProcessorOptions &options,
const BatchSpanProcessorRuntimeOptions &runtime_options);
/**
* Requests a Recordable(Span) from the configured exporter.
*
@ -158,6 +171,7 @@ protected:
std::shared_ptr<SynchronizationData> synchronization_data_;
/* The background worker thread */
std::shared_ptr<sdk::common::ThreadInstrumentation> worker_thread_instrumentation_;
std::thread worker_thread_;
};

View File

@ -6,6 +6,7 @@
#include <memory>
#include "opentelemetry/sdk/trace/batch_span_processor_options.h"
#include "opentelemetry/sdk/trace/batch_span_processor_runtime_options.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/version.h"
@ -27,6 +28,14 @@ public:
*/
static std::unique_ptr<SpanProcessor> Create(std::unique_ptr<SpanExporter> &&exporter,
const BatchSpanProcessorOptions &options);
/**
* Create a BatchSpanProcessor.
*/
static std::unique_ptr<SpanProcessor> Create(
std::unique_ptr<SpanExporter> &&exporter,
const BatchSpanProcessorOptions &options,
const BatchSpanProcessorRuntimeOptions &runtime_options);
};
} // namespace trace

View File

@ -0,0 +1,29 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <chrono>
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
namespace sdk
{
namespace trace
{
/**
* Struct to hold batch SpanProcessor runtime options.
*/
struct BatchSpanProcessorRuntimeOptions
{
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation =
std::shared_ptr<sdk::common::ThreadInstrumentation>(nullptr);
};
} // namespace trace
} // namespace sdk
OPENTELEMETRY_END_NAMESPACE

View File

@ -19,8 +19,10 @@
#include "opentelemetry/sdk/common/atomic_unique_ptr.h"
#include "opentelemetry/sdk/common/circular_buffer.h"
#include "opentelemetry/sdk/common/circular_buffer_range.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_runtime_options.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/recordable.h"
#include "opentelemetry/version.h"
@ -44,8 +46,12 @@ BatchLogRecordProcessor::BatchLogRecordProcessor(
max_export_batch_size_(max_export_batch_size),
buffer_(max_queue_size_),
synchronization_data_(std::make_shared<SynchronizationData>()),
worker_thread_(&BatchLogRecordProcessor::DoBackgroundWork, this)
{}
worker_thread_instrumentation_(nullptr),
worker_thread_()
{
// Make sure the constructor is complete before giving 'this' to a thread.
worker_thread_ = std::thread(&BatchLogRecordProcessor::DoBackgroundWork, this);
}
BatchLogRecordProcessor::BatchLogRecordProcessor(std::unique_ptr<LogRecordExporter> &&exporter,
const BatchLogRecordProcessorOptions &options)
@ -55,8 +61,29 @@ BatchLogRecordProcessor::BatchLogRecordProcessor(std::unique_ptr<LogRecordExport
max_export_batch_size_(options.max_export_batch_size),
buffer_(options.max_queue_size),
synchronization_data_(std::make_shared<SynchronizationData>()),
worker_thread_(&BatchLogRecordProcessor::DoBackgroundWork, this)
{}
worker_thread_instrumentation_(nullptr),
worker_thread_()
{
// Make sure the constructor is complete before giving 'this' to a thread.
worker_thread_ = std::thread(&BatchLogRecordProcessor::DoBackgroundWork, this);
}
BatchLogRecordProcessor::BatchLogRecordProcessor(
std::unique_ptr<LogRecordExporter> &&exporter,
const BatchLogRecordProcessorOptions &options,
const BatchLogRecordProcessorRuntimeOptions &runtime_options)
: exporter_(std::move(exporter)),
max_queue_size_(options.max_queue_size),
scheduled_delay_millis_(options.schedule_delay_millis),
max_export_batch_size_(options.max_export_batch_size),
buffer_(options.max_queue_size),
synchronization_data_(std::make_shared<SynchronizationData>()),
worker_thread_instrumentation_(runtime_options.thread_instrumentation),
worker_thread_()
{
// Make sure the constructor is complete before giving 'this' to a thread.
worker_thread_ = std::thread(&BatchLogRecordProcessor::DoBackgroundWork, this);
}
std::unique_ptr<Recordable> BatchLogRecordProcessor::MakeRecordable() noexcept
{
@ -151,10 +178,24 @@ bool BatchLogRecordProcessor::ForceFlush(std::chrono::microseconds timeout) noex
void BatchLogRecordProcessor::DoBackgroundWork()
{
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->OnStart();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
auto timeout = scheduled_delay_millis_;
while (true)
{
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->BeforeWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
// Wait for `timeout` milliseconds
std::unique_lock<std::mutex> lk(synchronization_data_->cv_m);
synchronization_data_->cv.wait_for(lk, timeout, [this] {
@ -168,6 +209,13 @@ void BatchLogRecordProcessor::DoBackgroundWork()
synchronization_data_->is_force_wakeup_background_worker.store(false,
std::memory_order_release);
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->AfterWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
if (synchronization_data_->is_shutdown.load() == true)
{
DrainQueue();
@ -182,10 +230,24 @@ void BatchLogRecordProcessor::DoBackgroundWork()
// Subtract the duration of this export call from the next `timeout`.
timeout = scheduled_delay_millis_ - duration;
}
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->OnEnd();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
}
void BatchLogRecordProcessor::Export()
{
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->BeforeLoad();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
do
{
std::vector<std::unique_ptr<Recordable>> records_arr;
@ -224,6 +286,13 @@ void BatchLogRecordProcessor::Export()
nostd::span<std::unique_ptr<Recordable>>(records_arr.data(), records_arr.size()));
NotifyCompletion(notify_force_flush, exporter_, synchronization_data_);
} while (true);
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->AfterLoad();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
}
void BatchLogRecordProcessor::NotifyCompletion(

View File

@ -7,6 +7,7 @@
#include "opentelemetry/sdk/logs/batch_log_record_processor.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_factory.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_options.h"
#include "opentelemetry/sdk/logs/batch_log_record_processor_runtime_options.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/processor.h"
#include "opentelemetry/version.h"
@ -20,9 +21,18 @@ namespace logs
std::unique_ptr<LogRecordProcessor> BatchLogRecordProcessorFactory::Create(
std::unique_ptr<LogRecordExporter> &&exporter,
const BatchLogRecordProcessorOptions &options)
{
BatchLogRecordProcessorRuntimeOptions runtime_options;
return Create(std::move(exporter), options, runtime_options);
}
std::unique_ptr<LogRecordProcessor> BatchLogRecordProcessorFactory::Create(
std::unique_ptr<LogRecordExporter> &&exporter,
const BatchLogRecordProcessorOptions &options,
const BatchLogRecordProcessorRuntimeOptions &runtime_options)
{
std::unique_ptr<LogRecordProcessor> processor(
new BatchLogRecordProcessor(std::move(exporter), options));
new BatchLogRecordProcessor(std::move(exporter), options, runtime_options));
return processor;
}

View File

@ -16,9 +16,11 @@
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/sdk/common/global_log_handler.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/sdk/metrics/export/metric_producer.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_runtime_options.h"
#include "opentelemetry/sdk/metrics/instruments.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/version.h"
@ -42,10 +44,32 @@ namespace metrics
PeriodicExportingMetricReader::PeriodicExportingMetricReader(
std::unique_ptr<PushMetricExporter> exporter,
const PeriodicExportingMetricReaderOptions &option)
const PeriodicExportingMetricReaderOptions &options)
: exporter_{std::move(exporter)},
export_interval_millis_{option.export_interval_millis},
export_timeout_millis_{option.export_timeout_millis}
export_interval_millis_{options.export_interval_millis},
export_timeout_millis_{options.export_timeout_millis},
worker_thread_instrumentation_(nullptr),
collect_thread_instrumentation_(nullptr)
{
if (export_interval_millis_ <= export_timeout_millis_)
{
OTEL_INTERNAL_LOG_WARN(
"[Periodic Exporting Metric Reader] Invalid configuration: "
"export_timeout_millis_ should be less than export_interval_millis_, using default values");
export_interval_millis_ = kExportIntervalMillis;
export_timeout_millis_ = kExportTimeOutMillis;
}
}
PeriodicExportingMetricReader::PeriodicExportingMetricReader(
std::unique_ptr<PushMetricExporter> exporter,
const PeriodicExportingMetricReaderOptions &options,
const PeriodicExportingMetricReaderRuntimeOptions &runtime_options)
: exporter_{std::move(exporter)},
export_interval_millis_{options.export_interval_millis},
export_timeout_millis_{options.export_timeout_millis},
worker_thread_instrumentation_(runtime_options.periodic_thread_instrumentation),
collect_thread_instrumentation_(runtime_options.collect_thread_instrumentation)
{
if (export_interval_millis_ <= export_timeout_millis_)
{
@ -69,18 +93,50 @@ void PeriodicExportingMetricReader::OnInitialized() noexcept
void PeriodicExportingMetricReader::DoBackgroundWork()
{
std::unique_lock<std::mutex> lk(cv_m_);
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->OnStart();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
do
{
auto start = std::chrono::steady_clock::now();
auto start = std::chrono::steady_clock::now();
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->BeforeLoad();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
auto status = CollectAndExportOnce();
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->AfterLoad();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
if (!status)
{
OTEL_INTERNAL_LOG_ERROR("[Periodic Exporting Metric Reader] Collect-Export Cycle Failure.")
}
auto end = std::chrono::steady_clock::now();
auto export_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
auto remaining_wait_interval_ms = export_interval_millis_ - export_time_ms;
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->BeforeWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
std::unique_lock<std::mutex> lk(cv_m_);
cv_.wait_for(lk, remaining_wait_interval_ms, [this]() {
if (is_force_wakeup_background_worker_.load(std::memory_order_acquire))
{
@ -89,7 +145,22 @@ void PeriodicExportingMetricReader::DoBackgroundWork()
}
return IsShutdown();
});
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->AfterWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
} while (IsShutdown() != true);
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->OnEnd();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
}
bool PeriodicExportingMetricReader::CollectAndExportOnce()
@ -108,6 +179,14 @@ bool PeriodicExportingMetricReader::CollectAndExportOnce()
task_thread.reset(
new std::thread([this, &cancel_export_for_timeout, sender = std::move(sender)] {
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (collect_thread_instrumentation_ != nullptr)
{
collect_thread_instrumentation_->OnStart();
collect_thread_instrumentation_->BeforeLoad();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
this->Collect([this, &cancel_export_for_timeout](ResourceMetrics &metric_data) {
if (cancel_export_for_timeout.load(std::memory_order_acquire))
{
@ -121,6 +200,14 @@ bool PeriodicExportingMetricReader::CollectAndExportOnce()
});
const_cast<std::promise<void> &>(sender).set_value();
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (collect_thread_instrumentation_ != nullptr)
{
collect_thread_instrumentation_->AfterLoad();
collect_thread_instrumentation_->OnEnd();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
}));
std::future_status status;

View File

@ -7,6 +7,7 @@
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_factory.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h"
#include "opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_runtime_options.h"
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/version.h"
@ -19,10 +20,19 @@ namespace metrics
std::unique_ptr<MetricReader> PeriodicExportingMetricReaderFactory::Create(
std::unique_ptr<PushMetricExporter> exporter,
const PeriodicExportingMetricReaderOptions &option)
const PeriodicExportingMetricReaderOptions &options)
{
PeriodicExportingMetricReaderRuntimeOptions runtime_options;
return Create(std::move(exporter), options, runtime_options);
}
std::unique_ptr<MetricReader> PeriodicExportingMetricReaderFactory::Create(
std::unique_ptr<PushMetricExporter> exporter,
const PeriodicExportingMetricReaderOptions &options,
const PeriodicExportingMetricReaderRuntimeOptions &runtime_options)
{
std::unique_ptr<MetricReader> reader(
new PeriodicExportingMetricReader(std::move(exporter), option));
new PeriodicExportingMetricReader(std::move(exporter), options, runtime_options));
return reader;
}

View File

@ -20,8 +20,10 @@
#include "opentelemetry/sdk/common/circular_buffer.h"
#include "opentelemetry/sdk/common/circular_buffer_range.h"
#include "opentelemetry/sdk/common/global_log_handler.h"
#include "opentelemetry/sdk/common/thread_instrumentation.h"
#include "opentelemetry/sdk/trace/batch_span_processor.h"
#include "opentelemetry/sdk/trace/batch_span_processor_options.h"
#include "opentelemetry/sdk/trace/batch_span_processor_runtime_options.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/sdk/trace/recordable.h"
@ -45,8 +47,28 @@ BatchSpanProcessor::BatchSpanProcessor(std::unique_ptr<SpanExporter> &&exporter,
max_export_batch_size_(options.max_export_batch_size),
buffer_(max_queue_size_),
synchronization_data_(std::make_shared<SynchronizationData>()),
worker_thread_(&BatchSpanProcessor::DoBackgroundWork, this)
{}
worker_thread_instrumentation_(nullptr),
worker_thread_()
{
// Make sure the constructor is complete before giving 'this' to a thread.
worker_thread_ = std::thread(&BatchSpanProcessor::DoBackgroundWork, this);
}
BatchSpanProcessor::BatchSpanProcessor(std::unique_ptr<SpanExporter> &&exporter,
const BatchSpanProcessorOptions &options,
const BatchSpanProcessorRuntimeOptions &runtime_options)
: exporter_(std::move(exporter)),
max_queue_size_(options.max_queue_size),
schedule_delay_millis_(options.schedule_delay_millis),
max_export_batch_size_(options.max_export_batch_size),
buffer_(max_queue_size_),
synchronization_data_(std::make_shared<SynchronizationData>()),
worker_thread_instrumentation_(runtime_options.thread_instrumentation),
worker_thread_()
{
// Make sure the constructor is complete before giving 'this' to a thread.
worker_thread_ = std::thread(&BatchSpanProcessor::DoBackgroundWork, this);
}
std::unique_ptr<Recordable> BatchSpanProcessor::MakeRecordable() noexcept
{
@ -148,10 +170,24 @@ bool BatchSpanProcessor::ForceFlush(std::chrono::microseconds timeout) noexcept
void BatchSpanProcessor::DoBackgroundWork()
{
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->OnStart();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
auto timeout = schedule_delay_millis_;
while (true)
{
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->BeforeWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
// Wait for `timeout` milliseconds
std::unique_lock<std::mutex> lk(synchronization_data_->cv_m);
synchronization_data_->cv.wait_for(lk, timeout, [this] {
@ -165,10 +201,17 @@ void BatchSpanProcessor::DoBackgroundWork()
synchronization_data_->is_force_wakeup_background_worker.store(false,
std::memory_order_release);
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->AfterWait();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
if (synchronization_data_->is_shutdown.load() == true)
{
DrainQueue();
return;
break;
}
auto start = std::chrono::steady_clock::now();
@ -179,10 +222,24 @@ void BatchSpanProcessor::DoBackgroundWork()
// Subtract the duration of this export call from the next `timeout`.
timeout = schedule_delay_millis_ - duration;
}
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->OnEnd();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
}
void BatchSpanProcessor::Export()
{
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->BeforeLoad();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
do
{
std::vector<std::unique_ptr<Recordable>> spans_arr;
@ -221,6 +278,13 @@ void BatchSpanProcessor::Export()
exporter_->Export(nostd::span<std::unique_ptr<Recordable>>(spans_arr.data(), spans_arr.size()));
NotifyCompletion(notify_force_flush, exporter_, synchronization_data_);
} while (true);
#ifdef ENABLE_THREAD_INSTRUMENTATION_PREVIEW
if (worker_thread_instrumentation_ != nullptr)
{
worker_thread_instrumentation_->AfterLoad();
}
#endif /* ENABLE_THREAD_INSTRUMENTATION_PREVIEW */
}
void BatchSpanProcessor::NotifyCompletion(

View File

@ -7,6 +7,7 @@
#include "opentelemetry/sdk/trace/batch_span_processor.h"
#include "opentelemetry/sdk/trace/batch_span_processor_factory.h"
#include "opentelemetry/sdk/trace/batch_span_processor_options.h"
#include "opentelemetry/sdk/trace/batch_span_processor_runtime_options.h"
#include "opentelemetry/sdk/trace/exporter.h"
#include "opentelemetry/sdk/trace/processor.h"
#include "opentelemetry/version.h"
@ -16,11 +17,22 @@ namespace sdk
{
namespace trace
{
std::unique_ptr<SpanProcessor> BatchSpanProcessorFactory::Create(
std::unique_ptr<SpanExporter> &&exporter,
const BatchSpanProcessorOptions &options)
{
std::unique_ptr<SpanProcessor> processor(new BatchSpanProcessor(std::move(exporter), options));
BatchSpanProcessorRuntimeOptions runtime_options;
return Create(std::move(exporter), options, runtime_options);
}
std::unique_ptr<SpanProcessor> BatchSpanProcessorFactory::Create(
std::unique_ptr<SpanExporter> &&exporter,
const BatchSpanProcessorOptions &options,
const BatchSpanProcessorRuntimeOptions &runtime_options)
{
std::unique_ptr<SpanProcessor> processor(
new BatchSpanProcessor(std::move(exporter), options, runtime_options));
return processor;
}