Skip to content

Commit

Permalink
HPCC-33118 Update ESP to use new span scope classes
Browse files Browse the repository at this point in the history
- Change server span storage from OwnedSpanScope to OwnedSpanLifetime.
- Use ActiveSpanScope in CEspHttpServer::processRequest to activate the server
  span.
- Replace use of IEspContext::queryActiveSpan with queryThreadedActiveSpan.
- Replace queryActiveSpan with queryRequestSpan in IEspContext to allow server
  span access outside of processRequest.

Signed-off-by: Tim Klemm <Tim.Klemm@lexisnexisrisk.com>
  • Loading branch information
Tim Klemm authored and Tim Klemm committed Dec 19, 2024
1 parent 2cd34ef commit 1a93f86
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions esp/bindings/http/platform/httpservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ int CEspHttpServer::processRequest()
//ensure the span is also terminated at the same time.
Owned<ISpan> serverSpan = m_request->createServerSpan(serviceName, methodName);
ctx->setRequestSpan(serverSpan);
ActiveSpanScope spanScope(serverSpan);

if (thebinding!=NULL)
{
Expand Down
2 changes: 1 addition & 1 deletion esp/bindings/http/platform/httptransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@ ISpan * CHttpRequest::createServerSpan(const char * serviceName, const char * me

void CHttpRequest::annotateSpan(const char * key, const char * value)
{
m_context->queryActiveSpan()->setSpanAttribute(key, value);
queryThreadedActiveSpan()->setSpanAttribute(key, value);
}

void CHttpRequest::updateContext()
Expand Down
2 changes: 1 addition & 1 deletion esp/platform/esp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ interface IEspContext : extends IInterface
virtual IHttpMessage* queryRequest() = 0;

virtual void setRequestSpan(ISpan * span)=0; // Call this function to set the server span for the query. The spans's lifetime will match the lifetime of the context object.
virtual ISpan * queryActiveSpan() const = 0;
virtual ISpan * queryRequestSpan() const = 0;
virtual IProperties * getClientSpanHeaders() const = 0;
virtual const char* getGlobalId() const = 0;
virtual const char* getCallerId() const = 0;
Expand Down
8 changes: 5 additions & 3 deletions esp/platform/espcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CEspContext : public CInterface, implements IEspContext
Owned<IEspSecureContextEx> m_secureContext;

StringAttr m_transactionID;
OwnedActiveSpanScope m_requestSpan; // When the context is destroy the span will end.
OwnedSpanLifetime m_requestSpan; // When the context is destroy the span will end.
IHttpMessage* m_request;

public:
Expand Down Expand Up @@ -628,9 +628,11 @@ class CEspContext : public CInterface, implements IEspContext
}
virtual void setRequestSpan(ISpan * span) override
{
m_requestSpan.set(span);
// The server span for a request can be set only once.
if (span && span != m_requestSpan && m_requestSpan == queryNullSpan())
m_requestSpan.set(span);
}
virtual ISpan * queryActiveSpan() const override
virtual ISpan * queryRequestSpan() const override
{
return m_requestSpan;
}
Expand Down
2 changes: 1 addition & 1 deletion esp/services/esdl_svc_engine/esdl_binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ void EsdlServiceImpl::sendTargetSOAP(IEspContext & context,
httpclient->setPassword(password.str());
}

ISpan * activeSpan = context.queryActiveSpan();
ISpan * activeSpan = queryThreadedActiveSpan();
OwnedActiveSpanScope clientSpan(activeSpan->createClientSpan("soapcall"));

Owned<IProperties> headers = ::getClientHeaders(clientSpan);
Expand Down
2 changes: 1 addition & 1 deletion esp/services/ws_ecl/ws_ecl_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ int CWsEclBinding::submitWsEclWorkunit(IEspContext & context, WsEclWuInfo &wsinf

bool noTimeout = false;

ISpan * activeSpan = context.queryActiveSpan();
ISpan * activeSpan = queryThreadedActiveSpan();
OwnedActiveSpanScope clientSpan(activeSpan->createClientSpan("run_workunit"));
Owned<IProperties> httpHeaders = ::getClientHeaders(clientSpan);
recordTraceDebugOptions(workunit, httpHeaders);
Expand Down
2 changes: 1 addition & 1 deletion esp/services/ws_workunits/ws_workunitsHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3792,7 +3792,7 @@ void WsWuHelpers::submitWsWorkunit(IEspContext& context, IConstWorkUnit* cw, con
}
}

ISpan * activeSpan = context.queryActiveSpan();
ISpan * activeSpan = queryThreadedActiveSpan();
OwnedActiveSpanScope clientSpan(activeSpan->createClientSpan("run_workunit"));
Owned<IProperties> httpHeaders = ::getClientHeaders(clientSpan);
recordTraceDebugOptions(wu, httpHeaders);
Expand Down
2 changes: 1 addition & 1 deletion system/jlib/jtrace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ extern jlib_decl void testJLogExporterPrintAttributes(StringBuffer & out, const
*/

//The following class is responsible for ensuring that the active span is restored in a context when the scope is exited
//Use a template class so it can be reused for IContextLogger and IEspContext
//Use a template class so it can be used for IContextLogger and any other conforming interface.
template <class CONTEXT>
class ContextSpanScopeImp
{
Expand Down

0 comments on commit 1a93f86

Please sign in to comment.