microsoft / reverse-proxy

A toolkit for developing high-performance HTTP reverse proxy applications.
https://microsoft.github.io/reverse-proxy
MIT License
8.59k stars 842 forks source link

Documentation improvement - Distributed tracing - Elastic APM #2372

Open tomap opened 10 months ago

tomap commented 10 months ago

Hello,

I cam across an issue where Elastic APM was not able to link the calls between my BFF (using Yarp) and my backend

I tried to follow the suggestion here: https://microsoft.github.io/reverse-proxy/articles/distributed-tracing.html#pass-through-proxy

but it did not help

But by following the suggestion from Elastic Team:

https://discuss.elastic.co/t/elastic-apm-yarp/347667/2

It worked! Here is the code that I used in the end:

builder.Services.AddReverseProxy()
    .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
    .ConfigureHttpClient((context, handler) => handler.ActivityHeadersPropagator = DistributedContextPropagator.CreateDefaultPropagator());

You could add it to the documentation just in case of similar issue

Thank you

MihaZupan commented 10 months ago

Thanks for the report. It appears Elastic's .NET integration is relying on the existing header being set on the request, and not on the ambient Activity. This is unlike other integrations we've tested against.

I don't believe there's much we can do by default that would work for both scenarios. Documenting that changing ActivityHeadersPropagator back to default works for Elastic in the existing tracing doc makes sense.