Skip to content
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

EnrichWithHttpRequest - Changes to Activity DisplayName gets overridden with route template/path in AspNetCoreInstrumentation #3977

Closed
chandramouleswaran opened this issue Dec 6, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@chandramouleswaran
Copy link

Bug Report

Here is a small snippet to repro the issue

.AddAspNetCoreInstrumentation(options =>
{
    const string incomingSpanName = "IncomingSpanName";
    options.EnrichWithHttpRequest = (activity, httpRequest) =>
    {
        if (httpRequest.Headers.TryGetValue(Header.ClientActionName, out StringValues clientActionHeaders))
        {
            var displayName = $"{serviceRole}.Incoming.{clientActionHeaders}";
            activity.AddTag(incomingSpanName, displayName);

            // Ideally this should be sufficient - however, OT ends up resetting this value to the action's route template
            activity.DisplayName = displayName;
        }
    };

    options.EnrichWithHttpResponse = (activity, response) =>
    {
        // Hack to get the value added to the tag to setup the display name
        var incomingSpan = activity.GetTagItem(incomingSpanName);
        if (incomingSpan != null)
        {
            activity.DisplayName = incomingSpan.ToString();
        }
    };
});

Symptom

We need the ability to setup DisplayName of the activity as part of the request flow - it looks like OT ends up changing the DisplayName based on the route template somewhere along the request lifecycle.

What is the expected behavior?

What did you expect to see?
image

What is the actual behavior?

What did you see instead?
image

Reproduce

See code snippet above with repro.

Packages used while reproducing
OpenTelemetry 1.4.0-beta.3
OpenTelemetry.Api 1.4.0-beta.3
OpenTelemetry.Exporter.CredScan 2.0.12
OpenTelemetry.Extensions.Hosting 1.0.0-rc9.9
OpenTelemetry.Exporter.Zipkin 1.4.0-beta.3
OpenTelemetry.Exporter.Geneva 1.4.0-beta.5
OpenTelemetry.Instrumentation.AspNetCore 1.0.0-rc9.9
OpenTelemetry.Instrumentation.GrpcNetClient 1.0.0-rc9.9
OpenTelemetry.Instrumentation.Http 1.0.0-rc9.9
OpenTelemetry.Instrumentation.Process 1.0.0-alpha.2
OpenTelemetry.Instrumentation.Runtime 1.1.0-beta.1

Runtime version: net7.0

@chandramouleswaran chandramouleswaran added the bug Something isn't working label Dec 6, 2022
@cijothomas
Copy link
Member

@vishweshbankwar Can you check this?

@vishweshbankwar
Copy link
Member

it happens due to this

. This is done to comply with spec. We need to find the alternate way of not overriding the DisplayName if it was changed using enrich options.

@cijothomas cijothomas added this to the Instrumentation-1.0.0 milestone Mar 13, 2023
@vishweshbankwar
Copy link
Member

vishweshbankwar commented Mar 14, 2023

@chandramouleswaran - Could you try the following. Try setting the DisplayName using EnrichWithHttpResponse

.AddAspNetCoreInstrumentation(o =>
{
  o.EnrichWithHttpResponse = (activity, response) =>
  {
      if (response.HttpContext.Request.Headers.TryGetValue(Header.ClientActionName, out StringValues clientActionHeaders))
      {
          var displayName = $"{serviceRole}.Incoming.{clientActionHeaders}";

          activity.DisplayName = displayName;
      }
  };
});

@utpilla
Copy link
Contributor

utpilla commented May 11, 2023

@chandramouleswaran Does the above-mentioned suggestion work?

@vishweshbankwar
Copy link
Member

@chandramouleswaran Closing this issue. please re-open if the above shared workaround does not work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants