-
Notifications
You must be signed in to change notification settings - Fork 843
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
Wire up DiagnosticsHandler #456
Wire up DiagnosticsHandler #456
Conversation
@MihaZupan can you supervise this PR? |
@jmezach are there any tests you could bring over or add for this? |
@Tratcher I did find this test class in dotnet/runtime but that class is abstract. It looks like there's the SocketsHttpHandlerTest class which inherits from that base class but surely we don't want to include all those tests in here? @MihaZupan I also found out that the DiagnosticsHandler I based this on was a slightly older version from dotnet/corefx rather than dotnet/runtime. The latter seems to be slightly different in its implementation. Should I base this implementation on that? |
Now that |
@Kahbazi That's an interesting question. I did some testing and it seems that if we send a I'm not too sure about the specifics of the W3C Trace Context specification, but this behaviour does make sense to me. Essentially the reverse proxy is just another service in the chain if you're looking at distributed tracing. Were you expecting different behaviour? |
@Kahbazi Yeah, you might be on to something there since I'm seeing the traceparent being transmitted as is to the downstream service. Perhaps @Tratcher and @MihaZupan could chime in here. Is this what we're expecting to see here? I'm getting a feeling that we might have to do somethings differently in the case of YARP. |
@Kahbazi I've run a couple of experiments to validate your theory. I currently have an API gateway setup using YARP and I've recompiled it using the changes in this PR. I then setup OpenTelemetry for both the API gateway and the downstream service which is an ASP.NET Core API that simply echoes the incoming headers in the response body. I've setup the Jaeger exporter with OpenTelemetry since I couldn't get the Zipkin exporter to work, or at least not on my machine. If I don't send a When I sent along a So yes, it seems that when we sent along a |
@Kahbazi @MihaZupan @Tratcher I've added an additional check for the |
{ | ||
if (!string.IsNullOrEmpty(currentActivity.ParentId)) | ||
{ | ||
request.Headers.Remove(DiagnosticsHandlerLoggingStrings.TraceParentHeaderName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if a user wants to add its own traceparent
header in a Transform?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah, that could be an issue. Not sure how we could tackle that though. I believe transforms are performed before we get to this handler so how would we know whether the header was added by a transform or if it was in the original request? If the original request didn't have such a header then ParentId
on the currentActivity
would be null
which is why I added the if
. But if the original request has such a header and a transform has modified it in some way then I don't think we'll be able to detect that here, unless we add some metadata to the header somehow.
@MihaZupan Is there something more that I can do here? I think there's a couple of design issues here that we need to tackle to take this further, but would love some input on that. |
@Tratcher Is there anything I can do to get this moving? |
Sorry for the late reply. Correct me if I'm wrong, but the main thing we want from this is to propagate the trace context via headers, to enable distributed tracing. Do you actually need the diagnostic events written here? Looking at all the DiagnosticHandler-related issues I gather there are a few pain points:
What I would suggest is to drop the writing of events and creation of activity, and only bring over the The behavior I would expect would be:
|
@MihaZupan I can totally live with that, makes everything a lot simpler imho. I just did a rebase of my branch on the latest changes and I'll get to work on this. Perhaps we should also rename the handler to ActivityPropagationHandler? |
c61ce39
to
dee121e
Compare
src/ReverseProxy/Service/Proxy/Infrastructure/ProxyHttpClientFactory.cs
Outdated
Show resolved
Hide resolved
test/ReverseProxy.Tests/Service/Proxy/Infrastructure/ProxyHttpClientFactoryTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments, otherwise LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add a test to assert the header modifications, but the behavior LGTM.
I've been trying to write some tests for the I've also tried setting |
I believe the Would you be okay with me pushing test changes to this PR branch directly? |
@MihaZupan Sure, go ahead :). |
Looks like I don't have the perms to push onto your branch directly, could you pick up the commit/changes from my branch: MihaZupan@ff6e65f |
@MihaZupan Done. I had to make one additional change in order for things to build on my dev machine. There was a using statement missing. |
There's a conflict with the master branch now (small conflict in the test file) |
@MihaZupan I fixed the merge conflict. |
@MihaZupan One thing I noticed is that you've put the tests for the handler into Service/Proxy/Infrastructure while the actual handler is in Telemetry. I would expect the tests and corresponding class in the same folder structure, but do you have a preference as to whether the handler should move or the tests? |
Yes, please move ActivityPropagationHandlerTests. |
@Tratcher Sure thing. Done :). |
As discussed in #292 I've wired up the
DiagnosticsHandler
in theProxyHttpClientFactory
as a workaround to make sure that the trace context is propagated to the downstream services. I also had to bring in theDiagnosticsHandlerLoggingStrings
class to ensure that it compiles.I've already seen it working on my local development machine in that I receive a
traceparent
header in the downstream service. I'm a little bit hesitant to put this into production to see if it solves our problem with distributed tracing (using New Relic) so I figured I might as well create a draft PR here first to get some input on things that could be improved.