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-33145: Optimize ESP server span creation #19373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
43 changes: 38 additions & 5 deletions esp/bindings/http/platform/httpservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,44 @@ int CEspHttpServer::processRequest()
m_request->getEspPathInfo(stype, &pathEx, &serviceName, &methodName, false);
ESPLOG(LogNormal,"sub service type: %s. parm: %s", getSubServiceDesc(stype), m_request->queryParamStr());

// getEspPathInfo provides all information needed to decide if the request should be
// traced. Create a server span, if needed, before proceding with request processing
// so maximize the amount of request processing that can be traced. Specifically, user
// authentication and authorization may generate trace output.
bool wantTracing = true;
if (!queryTraceManager().isTracingEnabled())
wantTracing = false;
else if (streq(method, GET_METHOD))
{
if (sub_serv_root == stype)
wantTracing = false;
else if (strieq(serviceName, "esp"))
{
wantTracing = !(methodName.isEmpty() ||
strieq(methodName, "files") ||
strieq(methodName, "xslt") ||
strieq(methodName, "frame") ||
strieq(methodName, "titlebar") ||
strieq(methodName, "nav") ||
strieq(methodName, "navdata") ||
strieq(methodName, "navmenuevent") ||
strieq(methodName, "soapreq"));
}
}
else if (!m_apport)
wantTracing = false;
Owned<ISpan> serverSpan;
if (wantTracing)
{
// The context will be destroyed when this request is destroyed. So initialise a
// SpanScope in the context to ensure the span is also terminated at the same time.
serverSpan.setown(m_request->createServerSpan(serviceName, methodName));
ctx->setRequestSpan(serverSpan);
}
else
serverSpan.setown(getNullSpan());
ActiveSpanScope serverSpanScope(serverSpan);

m_request->updateContext();
ctx->setServiceName(serviceName.str());
ctx->setHTTPMethod(method.str());
Expand Down Expand Up @@ -500,11 +538,6 @@ int CEspHttpServer::processRequest()
return 0;
}

//The context will be destroyed when this request is destroyed. So initialise a SpanScope in the context to
//ensure the span is also terminated at the same time.
Owned<ISpan> serverSpan = m_request->createServerSpan(serviceName, methodName);
ctx->setRequestSpan(serverSpan);

if (thebinding!=NULL)
{
if(stricmp(method.str(), POST_METHOD)==0)
Expand Down
3 changes: 2 additions & 1 deletion esp/bindings/http/platform/httptransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ ISpan * CHttpRequest::createServerSpan(const char * serviceName, const char * me
spanName.append("/").append(methodName);
spanName.toLowerCase();
Owned<IProperties> httpHeaders = getHeadersAsProperties(m_headers);
return queryTraceManager().createServerSpan(spanName, httpHeaders, SpanFlags::EnsureGlobalId);
return queryTraceManager().createServerSpan(spanName, httpHeaders, &m_receivedAt, SpanFlags::EnsureGlobalId);
}

void CHttpRequest::annotateSpan(const char * key, const char * value)
Expand Down Expand Up @@ -2089,6 +2089,7 @@ int CHttpRequest::processHeaders(IMultiException *me)
char oneline[MAX_HTTP_HEADER_LEN + 2];

int lenread = m_bufferedsocket->readline(oneline, MAX_HTTP_HEADER_LEN + 1, me);
m_receivedAt.now(); // use receipt of a first loe as the start time for a server span
if(lenread <= 0) //special case client connected and disconnected, load balancer ping?
return -1;
else if (lenread > MAX_HTTP_HEADER_LEN)
Expand Down
1 change: 1 addition & 0 deletions esp/bindings/http/platform/httptransport.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ const char* getSubServiceDesc(sub_service stype);
class esp_http_decl CHttpRequest : public CHttpMessage
{
private:
SpanTimeStamp m_receivedAt;
StringAttr m_httpMethod;
StringAttr m_espServiceName;
StringAttr m_espMethodName;
Expand Down
2 changes: 1 addition & 1 deletion 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
Loading