graphql-platform
graphql-platform copied to clipboard
RenameRootActivity not working anymore
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 but it looks like that they do not allow the rename anymore
We are intrested in this bug. Any news coming?
@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:
- Create a custom
ActivityEnricherwhich add the operation name to the activity. (this we would not need it if HotChocolate will attach this information on theActivity)
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;
}
}
- Register the activity enricher
services.AddSingleton<ActivityEnricher, GraphQLActivityEnricher>();
- In the
OpenTelemetryregistration 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;
}
};
}));
Thank you, it's clear.
@michaelstaib @monco83 @glucaci
I opened a pr on the otel repo: https://github.com/open-telemetry/opentelemetry-dotnet/pull/5402#issue-2161254541
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 in 14 you can use the new semantic routes in Hot Chocolate.