Skip to content

Commit 9eb4d06

Browse files
committed
agents: fix crash in HttpCurlGlobalInitializer
Make sure the HttpCurlGlobalInitializer static instance is created before the OTLPAgent so it's destroyed after the OTLPAgent in __run_exit_handlers. This fixes an insidious crash which happened if between the HttpCurlGlobalInitializer and OTLPAgent destruction, a config update caused the metrics_exporter_ to be reset to a specific exporter. This caused the HttpCurlGlobalInitializer instance destructor to be called twice thus crashing. Fixes: #33 PR-URL: #34 Reviewed-by: Trevor Norris <[email protected]>
1 parent 5a47d7e commit 9eb4d06

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

agents/otlp/src/otlp_agent.cc

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "opentelemetry/sdk/resource/resource.h"
77
#include "opentelemetry/sdk/trace/recordable.h"
88
#include "opentelemetry/exporters/otlp/otlp_http_exporter.h"
9+
#include "opentelemetry/ext/http/client/curl/http_client_curl.h"
910
#include "opentelemetry/trace/propagation/detail/hex.h"
1011

1112
using ThreadMetricsStor = node::nsolid::ThreadMetrics::MetricsStor;
@@ -14,6 +15,7 @@ using nlohmann::json;
1415
namespace nostd = OPENTELEMETRY_NAMESPACE::nostd;
1516
namespace sdk = OPENTELEMETRY_NAMESPACE::sdk;
1617
namespace exporter = OPENTELEMETRY_NAMESPACE::exporter;
18+
namespace ext = OPENTELEMETRY_NAMESPACE::ext;
1719
namespace trace = OPENTELEMETRY_NAMESPACE::trace;
1820
namespace resource = sdk::resource;
1921
namespace detail = trace::propagation::detail;
@@ -44,6 +46,15 @@ inline void DebugJSON(const char* str, const json& msg) {
4446

4547

4648
OTLPAgent* OTLPAgent::Inst() {
49+
// Make sure the HttpCurlGlobalInitializer static instance is created before
50+
// the OTLPAgent so it's destroyed after the OTLPAgent in __run_exit_handlers.
51+
// This fixes an insidious crash which happened if between the
52+
// HttpCurlGlobalInitializer and OTLPAgent destruction, a config update caused
53+
// the metrics_exporter_ to be reset to a specific exporter. This caused the
54+
// HttpCurlGlobalInitializer instance destructor to be called twice thus
55+
// crashing.
56+
auto initializer =
57+
ext::http::client::curl::HttpCurlGlobalInitializer::GetInstance();
4758
static OTLPAgent agent;
4859
return &agent;
4960
}

0 commit comments

Comments
 (0)