Skip to content

Commit 3975855

Browse files
committed
[POC] Better control of threads executed by opentelemetry-cpp
Fixes #3174
1 parent fe68d51 commit 3975855

25 files changed

+254
-37
lines changed

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_client.h

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "opentelemetry/nostd/string_view.h"
2121
#include "opentelemetry/nostd/variant.h"
2222
#include "opentelemetry/sdk/common/exporter_utils.h"
23+
#include "opentelemetry/sdk/common/thread_instrumentation.h"
2324
#include "opentelemetry/version.h"
2425

2526
// forward declare google::protobuf::Message
@@ -83,28 +84,32 @@ struct OtlpHttpClientOptions
8384
// User agent
8485
std::string user_agent;
8586

86-
inline OtlpHttpClientOptions(nostd::string_view input_url,
87-
bool input_ssl_insecure_skip_verify,
88-
nostd::string_view input_ssl_ca_cert_path,
89-
nostd::string_view input_ssl_ca_cert_string,
90-
nostd::string_view input_ssl_client_key_path,
91-
nostd::string_view input_ssl_client_key_string,
92-
nostd::string_view input_ssl_client_cert_path,
93-
nostd::string_view input_ssl_client_cert_string,
94-
nostd::string_view input_ssl_min_tls,
95-
nostd::string_view input_ssl_max_tls,
96-
nostd::string_view input_ssl_cipher,
97-
nostd::string_view input_ssl_cipher_suite,
98-
HttpRequestContentType input_content_type,
99-
JsonBytesMappingKind input_json_bytes_mapping,
100-
nostd::string_view input_compression,
101-
bool input_use_json_name,
102-
bool input_console_debug,
103-
std::chrono::system_clock::duration input_timeout,
104-
const OtlpHeaders &input_http_headers,
105-
std::size_t input_concurrent_sessions = 64,
106-
std::size_t input_max_requests_per_connection = 8,
107-
nostd::string_view input_user_agent = GetOtlpDefaultUserAgent())
87+
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation;
88+
89+
inline OtlpHttpClientOptions(
90+
nostd::string_view input_url,
91+
bool input_ssl_insecure_skip_verify,
92+
nostd::string_view input_ssl_ca_cert_path,
93+
nostd::string_view input_ssl_ca_cert_string,
94+
nostd::string_view input_ssl_client_key_path,
95+
nostd::string_view input_ssl_client_key_string,
96+
nostd::string_view input_ssl_client_cert_path,
97+
nostd::string_view input_ssl_client_cert_string,
98+
nostd::string_view input_ssl_min_tls,
99+
nostd::string_view input_ssl_max_tls,
100+
nostd::string_view input_ssl_cipher,
101+
nostd::string_view input_ssl_cipher_suite,
102+
HttpRequestContentType input_content_type,
103+
JsonBytesMappingKind input_json_bytes_mapping,
104+
nostd::string_view input_compression,
105+
bool input_use_json_name,
106+
bool input_console_debug,
107+
std::chrono::system_clock::duration input_timeout,
108+
const OtlpHeaders &input_http_headers,
109+
const std::shared_ptr<sdk::common::ThreadInstrumentation> &input_thread_instrumentation,
110+
std::size_t input_concurrent_sessions = 64,
111+
std::size_t input_max_requests_per_connection = 8,
112+
nostd::string_view input_user_agent = GetOtlpDefaultUserAgent())
108113
: url(input_url),
109114
ssl_options(input_url,
110115
input_ssl_insecure_skip_verify,
@@ -127,7 +132,8 @@ struct OtlpHttpClientOptions
127132
http_headers(input_http_headers),
128133
max_concurrent_requests(input_concurrent_sessions),
129134
max_requests_per_connection(input_max_requests_per_connection),
130-
user_agent(input_user_agent)
135+
user_agent(input_user_agent),
136+
thread_instrumentation(input_thread_instrumentation)
131137
{}
132138
};
133139

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_exporter_options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#pragma once
55

66
#include <chrono>
7+
#include <memory>
78
#include <string>
89

910
#include "opentelemetry/exporters/otlp/otlp_environment.h"
1011
#include "opentelemetry/exporters/otlp/otlp_http.h"
12+
#include "opentelemetry/sdk/common/thread_instrumentation.h"
1113
#include "opentelemetry/version.h"
1214

1315
OPENTELEMETRY_BEGIN_NAMESPACE
@@ -101,6 +103,8 @@ struct OPENTELEMETRY_EXPORT OtlpHttpExporterOptions
101103

102104
/** Compression type. */
103105
std::string compression;
106+
107+
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation;
104108
};
105109

106110
} // namespace otlp

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_log_record_exporter_options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
#pragma once
55

66
#include <chrono>
7+
#include <memory>
78
#include <string>
89

910
#include "opentelemetry/exporters/otlp/otlp_environment.h"
1011
#include "opentelemetry/exporters/otlp/otlp_http.h"
12+
#include "opentelemetry/sdk/common/thread_instrumentation.h"
1113
#include "opentelemetry/version.h"
1214

1315
OPENTELEMETRY_BEGIN_NAMESPACE
@@ -101,6 +103,8 @@ struct OPENTELEMETRY_EXPORT OtlpHttpLogRecordExporterOptions
101103

102104
/** Compression type. */
103105
std::string compression;
106+
107+
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation;
104108
};
105109

106110
} // namespace otlp

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
#pragma once
55

66
#include <chrono>
7+
#include <memory>
78
#include <string>
89

910
#include "opentelemetry/exporters/otlp/otlp_environment.h"
1011
#include "opentelemetry/exporters/otlp/otlp_http.h"
1112
#include "opentelemetry/exporters/otlp/otlp_preferred_temporality.h"
13+
#include "opentelemetry/sdk/common/thread_instrumentation.h"
1214
#include "opentelemetry/version.h"
1315

1416
OPENTELEMETRY_BEGIN_NAMESPACE
@@ -104,6 +106,8 @@ struct OPENTELEMETRY_EXPORT OtlpHttpMetricExporterOptions
104106

105107
/** Compression type. */
106108
std::string compression;
109+
110+
std::shared_ptr<sdk::common::ThreadInstrumentation> thread_instrumentation;
107111
};
108112

109113
} // namespace otlp

exporters/otlp/src/otlp_http_client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ void ConvertListFieldToJson(nlohmann::json &value,
665665
OtlpHttpClient::OtlpHttpClient(OtlpHttpClientOptions &&options)
666666
: is_shutdown_(false),
667667
options_(options),
668-
http_client_(http_client::HttpClientFactory::Create()),
668+
http_client_(http_client::HttpClientFactory::Create(options.thread_instrumentation)),
669669
start_session_counter_(0),
670670
finished_session_counter_(0)
671671
{

exporters/otlp/src/otlp_http_exporter.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ OtlpHttpExporter::OtlpHttpExporter(const OtlpHttpExporterOptions &options)
5757
options.use_json_name,
5858
options.console_debug,
5959
options.timeout,
60-
options.http_headers
60+
options.http_headers,
61+
options.thread_instrumentation
6162
#ifdef ENABLE_ASYNC_EXPORT
6263
,
6364
options.max_concurrent_requests,

exporters/otlp/src/otlp_http_log_record_exporter.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ OtlpHttpLogRecordExporter::OtlpHttpLogRecordExporter(
6060
options.use_json_name,
6161
options.console_debug,
6262
options.timeout,
63-
options.http_headers
63+
options.http_headers,
64+
options.thread_instrumentation
6465
#ifdef ENABLE_ASYNC_EXPORT
6566
,
6667
options.max_concurrent_requests,

exporters/otlp/src/otlp_http_metric_exporter.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ OtlpHttpMetricExporter::OtlpHttpMetricExporter(const OtlpHttpMetricExporterOptio
6161
options.use_json_name,
6262
options.console_debug,
6363
options.timeout,
64-
options.http_headers
64+
options.http_headers,
65+
options.thread_instrumentation
6566
#ifdef ENABLE_ASYNC_EXPORT
6667
,
6768
options.max_concurrent_requests,

exporters/otlp/test/otlp_http_exporter_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static nostd::span<T, N> MakeSpan(T (&array)[N])
5454
OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type,
5555
bool async_mode)
5656
{
57+
std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation> not_instrumented;
5758
OtlpHttpExporterOptions options;
5859
options.content_type = content_type;
5960
options.console_debug = true;
@@ -70,7 +71,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t
7071
"", /* ssl_cipher */
7172
"", /* ssl_cipher_suite */
7273
options.content_type, options.json_bytes_mapping, options.compression, options.use_json_name,
73-
options.console_debug, options.timeout, options.http_headers);
74+
options.console_debug, options.timeout, options.http_headers, not_instrumented);
7475
if (!async_mode)
7576
{
7677
otlp_http_client_options.max_concurrent_requests = 0;

exporters/otlp/test/otlp_http_log_record_exporter_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static nostd::span<T, N> MakeSpan(T (&array)[N])
5454
OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type,
5555
bool async_mode)
5656
{
57+
std::shared_ptr<opentelemetry::sdk::common::ThreadInstrumentation> not_instrumented;
5758
OtlpHttpLogRecordExporterOptions options;
5859
options.content_type = content_type;
5960
options.console_debug = true;
@@ -69,7 +70,7 @@ OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_t
6970
"", /* ssl_cipher */
7071
"", /* ssl_cipher_suite */
7172
options.content_type, options.json_bytes_mapping, options.compression, options.use_json_name,
72-
options.console_debug, options.timeout, options.http_headers);
73+
options.console_debug, options.timeout, options.http_headers, not_instrumented);
7374
if (!async_mode)
7475
{
7576
otlp_http_client_options.max_concurrent_requests = 0;

0 commit comments

Comments
 (0)