diff --git a/exporters/otlp/src/otlp_http_client.cc b/exporters/otlp/src/otlp_http_client.cc index 8ea20919df..76fc826d76 100644 --- a/exporters/otlp/src/otlp_http_client.cc +++ b/exporters/otlp/src/otlp_http_client.cc @@ -981,16 +981,19 @@ void OtlpHttpClient::addSession(HttpSessionData &&session_data) noexcept return; } - opentelemetry::ext::http::client::Session *key = session_data.session.get(); - ResponseHandler *handle = static_cast(session_data.event_handle.get()); - - handle->Bind(this, *key); + std::shared_ptr session = session_data.session; + std::shared_ptr handle = + session_data.event_handle; + { + std::lock_guard guard{session_manager_lock_}; + static_cast(handle.get())->Bind(this, *session); - HttpSessionData &store_session_data = running_sessions_[key]; - store_session_data = std::move(session_data); + HttpSessionData &store_session_data = running_sessions_[session.get()]; + store_session_data = std::move(session_data); + } // Send request after the session is added - key->SendRequest(store_session_data.event_handle); + session->SendRequest(handle); } bool OtlpHttpClient::cleanupGCSessions() noexcept