graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

RenameRootActivity not working anymore

Open glucaci opened this issue 1 year ago • 7 comments

Product

Hot Chocolate

Version

13.7.0

Link to minimal reproduction

https://github.com/open-telemetry/opentelemetry-dotnet/pull/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 https://github.com/open-telemetry/opentelemetry-dotnet/pull/5026

glucaci avatar Jan 30 '24 19:01 glucaci

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

michaelstaib avatar Feb 02 '24 16:02 michaelstaib

We are intrested in this bug. Any news coming?

monco83 avatar Feb 22 '24 07:02 monco83

@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;
        }
    };
}));

glucaci avatar Feb 22 '24 15:02 glucaci

Thank you, it's clear.

monco83 avatar Feb 26 '24 05:02 monco83

@michaelstaib @monco83 @glucaci

I opened a pr on the otel repo: https://github.com/open-telemetry/opentelemetry-dotnet/pull/5402#issue-2161254541

PascalSenn avatar Feb 29 '24 13:02 PascalSenn

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.

huysentruitw avatar Jun 11 '24 10:06 huysentruitw

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

michaelstaib avatar Jun 11 '24 11:06 michaelstaib