diff --git a/esp/bindings/http/platform/httpservice.cpp b/esp/bindings/http/platform/httpservice.cpp index 4f3715dc2b9..e8f95cf652b 100644 --- a/esp/bindings/http/platform/httpservice.cpp +++ b/esp/bindings/http/platform/httpservice.cpp @@ -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 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()); @@ -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 serverSpan = m_request->createServerSpan(serviceName, methodName); - ctx->setRequestSpan(serverSpan); - if (thebinding!=NULL) { if(stricmp(method.str(), POST_METHOD)==0) diff --git a/esp/bindings/http/platform/httptransport.cpp b/esp/bindings/http/platform/httptransport.cpp index 1eade1ce8ca..b91f1f93e22 100644 --- a/esp/bindings/http/platform/httptransport.cpp +++ b/esp/bindings/http/platform/httptransport.cpp @@ -1924,7 +1924,7 @@ ISpan * CHttpRequest::createServerSpan(const char * serviceName, const char * me spanName.append("/").append(methodName); spanName.toLowerCase(); Owned 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) @@ -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) diff --git a/esp/bindings/http/platform/httptransport.ipp b/esp/bindings/http/platform/httptransport.ipp index c69ce8d111f..f1264c99595 100644 --- a/esp/bindings/http/platform/httptransport.ipp +++ b/esp/bindings/http/platform/httptransport.ipp @@ -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; diff --git a/esp/platform/espcontext.cpp b/esp/platform/espcontext.cpp index 2e3d3dabf05..e1c1a69b3c1 100755 --- a/esp/platform/espcontext.cpp +++ b/esp/platform/espcontext.cpp @@ -89,7 +89,7 @@ class CEspContext : public CInterface, implements IEspContext Owned 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: