Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public static CallTargetState OnMethodBegin<TTarget, TRequest>(TTarget instance,
return new CallTargetState(scope);
}
}
else
{
headers.Remove(HttpHeaderNames.TracingEnabled);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice in theory, but it could run into potential issues 🤔 e.g. there are often nested handlers, and if we remove this header from the first one, the innermost handler may create a span 🤔 I think instead we may need to implement the "black hole" span approach which has been discussed a few times, but which is non-trivial to implement at the moment 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Was worth a shot. I can close this out for now. But before I do...

Do you have any recommendations for folks in my position? I've tried delegating handlers as the PrimaryHttpMessageHandler, HttpClientHandler, but the headers are still present. I'd really like to have tracing enabled for my other services and the one I'm trying to instrument is a bit of a monolith, so there are a lot of other http requests coming in and out of it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, currently, the tracing (span generation) of HttpClient spans is tied to propagation. Assuming you do want to see spans for the requests, you just don't want to include the headers in the outgoing request, I think there's currently only one avenue:

  • Disable tracing (and propagation) for the Url's you don't want to trace by setting DD_TRACE_HTTP_CLIENT_EXCLUDED_URL_SUBSTRINGS, e.g. DD_TRACE_HTTP_CLIENT_EXCLUDED_URL_SUBSTRINGS=some.domain.com,some.other.domain/and/path.
  • Manually create a span around the calls to these HttpClient requests to emulate the span that you would have got.

The need to use the manual span is obviously a bit hacky, but I think it's the only real workaround available at the moment. Hope that helps, and we'll bear this request in mind as a possible new feature in the future, thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DD_TRACE_HTTP_CLIENT_EXCLUDED_URL_SUBSTRINGS is exactly what I needed! Totally worked. Didn't know that existed, for what it's worth, but I see it in the code now. Thanks a ton!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, glad that solved your issue 🙂

}

return CallTargetState.GetDefault();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public static CallTargetState GetRequestStream_OnMethodBegin<TTarget>(TTarget in
/// <returns>Returns <c>true</c> if injection was performed, and <c>/false</c> otherwise</returns>
public static bool TryInjectHeaders<TTarget>(TTarget instance)
{
if (instance is HttpWebRequest request && IsTracingEnabled(request))
if (instance is not HttpWebRequest request)
{
return false;
}

if (IsTracingEnabled(request))
{
var tracer = Tracer.Instance;

Expand Down Expand Up @@ -74,6 +79,8 @@ public static bool TryInjectHeaders<TTarget>(TTarget instance)
}
}

request.Headers.Remove(HttpHeaderNames.TracingEnabled);

return false;
}

Expand Down