# Elastic APM + Yarp

**URL:** <https://discuss.elastic.co/t/elastic-apm-yarp/347667>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [November 21, 2023, 8:38pm UTC](https://discuss.elastic.co/t/elastic-apm-yarp/347667 "2023-11-21T20:38:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Piart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_piart/32/127882_2.png) [@Thomas\_Piart](https://discuss.elastic.co/u/Thomas_Piart)\
**Post date:** [November 21, 2023, 8:38pm UTC](https://discuss.elastic.co/t/elastic-apm-yarp/347667/1 "2023-11-21T20:38:29Z")

</div>

Hello,

I'm doing an http call to server, which in turn does an http call to another server

All that is instrumented with Elastic APM

Http \> Server A \> Http \> Server B

If I use an httpclient to do the call from server A to server B =\> I see the full result in Elastic APM

If I use Yarp (a .Net reverse proxy) to do the same call, I don't see the full result in Elastic APM  
I see both call separated, but not "linked" in the UI

A similar request has already been posted: elastic-apm-dotnet-yarp-issue/343247

But with this one, I provide a gthub repo to reproduce:

> **[GitHub - tomap/repro-yarp-elastic-apm: repo to reproduce issue between...](https://github.com/tomap/repro-yarp-elastic-apm)**
>
> repo to reproduce issue between Elastic APM & Yart - GitHub - tomap/repro-yarp-elastic-apm: repo to reproduce issue between Elastic APM & Yart

1/ Launch both projects  
2/ call /getme from WebApplication2 =\> this works fine (using httpclient in a controller)  
3/ call /weatherforcast =\> does not work fine (only part of the trace visible in Elastic APM)

I'm wondering if the X-Forwarded headers added by yarp are messing with Elastic APM collection

I've used a free Elastic cloud trial to repro

I hope you have access to the data from my trial account:  
4ad8fed546814708965668fdd56b1d56 us-central1

TIP 2: Check out the [troubleshooting guide](https://www.elastic.co/guide/en/apm/get-started/current/troubleshooting.html) first. Not only will it help you to resolve common problems faster but it also explains in more detail which information we need before we can properly help you.

**APM Agent language and version** : 1.25.1 / dotnet 7

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**:

---

<div class="post-metadata">

**Author:** ![kuanpak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kuanpak/32/128084_2.png) [@kuanpak](https://discuss.elastic.co/u/kuanpak)\
**Post date:** [November 27, 2023, 2:17pm UTC](https://discuss.elastic.co/t/elastic-apm-yarp/347667/2 "2023-11-27T14:17:45Z")

</div>

I had the similar issue before, it should be related to Yarp customized DistributedContextPropagator. Moreover, if the incoming requests to Yarp contain traceparent / tracestate headers, it will capture the wrong parent-child hierarchy as Elastic APM does always resue the proxied HttpClient trace context headers if exists.

Here is the workaround you can apply in Yarp app to avoid those issues:

```csharp
builder.Services.AddReverseProxy()
    .AddTransforms(context => context
        .AddRequestHeaderRemove("traceparent")
        .AddRequestHeaderRemove("tracestate"))
    .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"))
    .ConfigureHttpClient((context, handler) => handler.ActivityHeadersPropagator = DistributedContextPropagator.CreateDefaultPropagator())
    ;

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 25, 2023, 2:18pm UTC](https://discuss.elastic.co/t/elastic-apm-yarp/347667/3 "2023-12-25T14:18:06Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
