-
-
Notifications
You must be signed in to change notification settings - Fork 803
[Fusion] Add OpenTelemetry instrumentation #8909
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fe11d05
Add basic implementation
tobias-tengler 7b9a3f8
Merge remote-tracking branch 'origin/main' into tte/fusion-opentelemetry
tobias-tengler 77117c0
Fix build
tobias-tengler 0ceb7a7
Merge remote-tracking branch 'origin/main' into tte/fusion-opentelemetry
tobias-tengler 86fefd9
Cleanup
tobias-tengler 022efd1
Add tests
tobias-tengler 4b6af61
Add server instrumentation tests
tobias-tengler 425c0eb
Merge remote-tracking branch 'origin/main' into tte/fusion-opentelemetry
tobias-tengler e68bad3
Track nodes
tobias-tengler 12349a5
Merge remote-tracking branch 'origin/main' into tte/fusion-opentelemetry
tobias-tengler 9a2c0d7
Just record exceptions
tobias-tengler 2764e22
Remove test that doesn't apply to fusion
tobias-tengler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/HotChocolate/Fusion-vnext/src/Fusion.Diagnostics/ContextKeys.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| namespace HotChocolate.Fusion.Diagnostics; | ||
|
|
||
| internal static class ContextKeys | ||
| { | ||
| public const string HttpRequestActivity = "HotChocolate.Fusion.Diagnostics.HttpRequest"; | ||
| public const string ParseHttpRequestActivity = "HotChocolate.Fusion.Diagnostics.ParseHttpRequest"; | ||
| public const string FormatHttpResponseActivity = "HotChocolate.Fusion.Diagnostics.FormatHttpResponse"; | ||
| public const string RequestActivity = "HotChocolate.Fusion.Diagnostics.Request"; | ||
| public const string ValidateActivity = "HotChocolate.Fusion.Diagnostics.Validate"; | ||
| } |
56 changes: 56 additions & 0 deletions
56
...sion-vnext/src/Fusion.Diagnostics/Extensions/DiagnosticsFusionGatewayBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| using System.Text; | ||
| using HotChocolate.Fusion.Diagnostics; | ||
| using HotChocolate.Fusion.Diagnostics.Listeners; | ||
| using HotChocolate.Fusion.Configuration; | ||
| using Microsoft.Extensions.DependencyInjection.Extensions; | ||
| using Microsoft.Extensions.ObjectPool; | ||
|
|
||
| namespace Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| public static class DiagnosticsFusionGatewayBuilderExtensions | ||
| { | ||
| public static IFusionGatewayBuilder AddInstrumentation( | ||
| this IFusionGatewayBuilder builder, | ||
| Action<InstrumentationOptions>? options = null) | ||
| => AddInstrumentation(builder, (_, opt) => options?.Invoke(opt)); | ||
|
|
||
| public static IFusionGatewayBuilder AddInstrumentation( | ||
| this IFusionGatewayBuilder builder, | ||
| Action<IServiceProvider, InstrumentationOptions> options) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
| ArgumentNullException.ThrowIfNull(options); | ||
|
|
||
| builder.Services.TryAddSingleton( | ||
| sp => | ||
| { | ||
| var optionInst = new InstrumentationOptions(); | ||
| options(sp, optionInst); | ||
| return optionInst; | ||
| }); | ||
|
|
||
| builder.Services.TryAddSingleton<InternalActivityEnricher>(); | ||
|
|
||
| builder.AddApplicationService<InstrumentationOptions>(); | ||
| builder.AddApplicationService<InternalActivityEnricher>(); | ||
|
|
||
| builder.AddDiagnosticEventListener( | ||
| sp => new ActivityFusionExecutionDiagnosticEventListener( | ||
| sp.GetService<FusionActivityEnricher>() ?? | ||
| sp.GetRequiredService<InternalActivityEnricher>(), | ||
| sp.GetRequiredService<InstrumentationOptions>())); | ||
|
|
||
| builder.AddDiagnosticEventListener( | ||
| sp => new ActivityServerDiagnosticListener( | ||
| sp.GetService<FusionActivityEnricher>() ?? | ||
| sp.GetRequiredService<InternalActivityEnricher>(), | ||
| sp.GetRequiredService<InstrumentationOptions>())); | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| private sealed class InternalActivityEnricher( | ||
| ObjectPool<StringBuilder> stringBuilderPool, | ||
| InstrumentationOptions options) | ||
| : FusionActivityEnricher(stringBuilderPool, options); | ||
| } |
27 changes: 27 additions & 0 deletions
27
...ocolate/Fusion-vnext/src/Fusion.Diagnostics/Extensions/TracerProviderBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| using HotChocolate.Fusion.Diagnostics; | ||
|
|
||
| namespace OpenTelemetry.Trace; | ||
|
|
||
| /// <summary> | ||
| /// Provides configuration methods to open-telemetry. | ||
| /// </summary> | ||
| public static class TracerProviderBuilderExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds the Hot Chocolate Fusion instrumentation to open-telemetry. | ||
| /// </summary> | ||
| /// <param name="builder"> | ||
| /// The tracing builder. | ||
| /// </param> | ||
| /// <returns> | ||
| /// Returns the tracing builder for configuration chaining. | ||
| /// </returns> | ||
| public static TracerProviderBuilder AddHotChocolateFusionInstrumentation( | ||
| this TracerProviderBuilder builder) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(builder); | ||
|
|
||
| builder.AddSource(HotChocolateFusionActivitySource.GetName()); | ||
| return builder; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.