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

RenameRootActivity not working anymore #6862

Open
glucaci opened this issue Jan 30, 2024 · 7 comments
Open

RenameRootActivity not working anymore #6862

glucaci opened this issue Jan 30, 2024 · 7 comments

Comments

@glucaci
Copy link
Contributor

glucaci commented Jan 30, 2024

Product

Hot Chocolate

Version

13.7.0

Link to minimal reproduction

open-telemetry/opentelemetry-dotnet#5026

Steps to reproduce

builder.AddInstrumentation(o =>
{
    o.RenameRootActivity = true;
});

What is expected?

The root Activity to include the graphql operation

What is actually happening?

The root Activity contains only the default AspNetCore DisplayName

Relevant log output

No response

Additional context

This happens since OpenTelemetry.Instrumentation.AspNetCore 1.6.0-beta.3 because of this change open-telemetry/opentelemetry-dotnet#5026

@michaelstaib
Copy link
Member

@glucaci but it looks like that they do not allow the rename anymore

@monco83
Copy link

monco83 commented Feb 22, 2024

We are intrested in this bug. Any news coming?

@glucaci
Copy link
Contributor Author

glucaci commented Feb 22, 2024

@michaelstaib yes, there is no flexibility to rename it anymore.

I would in HotChocolate mark the RenameRootActivity as obsolate because there is no way to do it anymore and instead of directly renaming the Activity I would add the operation name as tag to the activity. Afterwords the user can rename it with the Enrich support from OpenTelemetry.Instrumentation.AspNetCore package.

For the current version what we did as workaround is:

  1. Create a custom ActivityEnricher which add the operation name to the activity. (this we would not need it if HotChocolate will attach this information on the Activity)
public sealed class GraphQLActivityEnricher : ActivityEnricher
{
    public GraphQLActivityEnricher(
        ObjectPool<StringBuilder> stringBuilderPool,
        InstrumentationOptions options)
        : base(stringBuilderPool, options)
    {
    }

    protected override string CreateRootActivityName(
        Activity activity,
        Activity root,
        string operationDisplayName)
    {
        activity.SetCustomProperty("graphqlDisplayName", operationDisplayName);
        root.SetCustomProperty("graphqlDisplayName", operationDisplayName);

        return operationDisplayName;
    }
}
  1. Register the activity enricher
services.AddSingleton<ActivityEnricher, GraphQLActivityEnricher>();
  1. In the OpenTelemetry registration configure the Enricher
openTelemetryBuilder.WithTracing(tracer => tracer.AddAspNetCoreInstrumentation(o =>
{
    o.EnrichWithHttpResponse = (activity, _) =>
    {
        var rawDisplayName = activity.GetCustomProperty("graphqlDisplayName");
        if (rawDisplayName is string graphqlDisplayName &&
            !string.IsNullOrEmpty(graphqlDisplayName))
        {
            activity.DisplayName = graphqlDisplayName;
        }
    };
}));

@monco83
Copy link

monco83 commented Feb 26, 2024

Thank you, it's clear.

@PascalSenn
Copy link
Member

@michaelstaib @monco83 @glucaci

I opened a pr on the otel repo:
open-telemetry/opentelemetry-dotnet#5402 (comment)

@huysentruitw
Copy link
Contributor

huysentruitw commented Jun 11, 2024

I was trying this work-around on Azure Application Insights and it took me somewhile to realize Application Insights doesn't show the trace DisplayName if the tags http.route and url.path are set. Instead, it shows the HTTP-method followed by http.route (with fallback to url.path). So to get the graphql operation visible, I also had to manipulate the http.route-tag on the activity.

@michaelstaib
Copy link
Member

@huysentruitw in 14 you can use the new semantic routes in Hot Chocolate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants