Skip to content

Clean up header when tracing is disabled #7367

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

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
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.

}

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