Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-32967 Avoid Otel GetGlobalProp spinlock #19282

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions system/jlib/jtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ class CHPCCHttpTextMapCarrier : public opentelemetry::context::propagation::Text
};

//---------------------------------------------------------------------------------------------------------------------

using namespace opentelemetry::v1::context::propagation;
class CTraceManager : implements ITraceManager, public CInterface
{
private:
Expand Down Expand Up @@ -530,6 +530,12 @@ class CTraceManager : implements ITraceManager, public CInterface

static Singleton<CTraceManager> theTraceManager;

// thePropagator can be used be regardless of whether tracing is enabled or not.
// Can be used to inject context into or extract it from carriers that travel in-band
// across process boundaries. Encoding is expected to conform to the HTTP Header Field semantics.
// Reference this propagator rather than fetching globalpropagator
static nostd::shared_ptr<TextMapPropagator> thePropagator = nostd::shared_ptr<TextMapPropagator>(new opentelemetry::trace::propagation::HttpTraceContext());

//What is the global trace manager? Only valid to call within this module from spans
//Which can only be created if the trace manager has been initialized
static inline CTraceManager & queryInternalTraceManager() { return *theTraceManager.query(); }
Expand Down Expand Up @@ -631,13 +637,11 @@ class CSpan : public CInterfaceOf<ISpan>
{
assertex(carrier);

auto propagator = opentelemetry::context::propagation::GlobalTextMapPropagator::GetGlobalPropagator();

opentelemetry::context::Context emptyCtx;
auto spanCtx = SetSpan(emptyCtx, span);

//and have the propagator inject the ctx into carrier
propagator->Inject(*carrier, spanCtx);
thePropagator->Inject(*carrier, spanCtx);

if (!isEmptyString(queryGlobalId()))
carrier->Set(kGlobalIdHttpHeaderName, queryGlobalId());
Expand Down Expand Up @@ -1037,18 +1041,16 @@ class CServerSpan : public CSpan
hpccCallerId.set(httpHeaders->queryProp(kLegacyCallerIdHttpHeaderName));

const CHPCCHttpTextMapCarrier carrier(httpHeaders);
auto globalPropegator = context::propagation::GlobalTextMapPropagator::GetGlobalPropagator();
//avoiding getCurrent: https://github.com/open-telemetry/opentelemetry-cpp/issues/1467
opentelemetry::context::Context empty;
auto wrappedSpanCtx = SetSpan(empty, span);
opentelemetry::v1::context::Context runtimeCtx = globalPropegator->Extract(carrier, wrappedSpanCtx);
opentelemetry::v1::context::Context runtimeCtx = thePropagator->Extract(carrier, wrappedSpanCtx);
opentelemetry::v1::nostd::shared_ptr<opentelemetry::v1::trace::Span> remoteParentSpan = opentelemetry::trace::GetSpan(runtimeCtx);

if (remoteParentSpan != nullptr && remoteParentSpan->GetContext().IsValid())
{
remoteParentSpanCtx = remoteParentSpan->GetContext();
opts.parent = remoteParentSpanCtx;

}
}
}
Expand Down Expand Up @@ -1429,15 +1431,6 @@ void CTraceManager::initTracer(const IPropertyTree * traceConfig)
optAlwaysCreateTraceIds = traceConfig->getPropBool("@alwaysCreateTraceIds", optAlwaysCreateTraceIds);
}

// The global propagator should be set regardless of whether tracing is enabled or not.
// Injects Context into and extracts it from carriers that travel in-band
// across process boundaries. Encoding is expected to conform to the HTTP
// Header Field semantics.
// Values are often encoded as RPC/HTTP request headers.
opentelemetry::context::propagation::GlobalTextMapPropagator::SetGlobalPropagator(
opentelemetry::nostd::shared_ptr<opentelemetry::context::propagation::TextMapPropagator>(
new opentelemetry::trace::propagation::HttpTraceContext()));

}
catch (IException * e)
{
Expand Down
Loading