-
Notifications
You must be signed in to change notification settings - Fork 12
feat(correlation): add open-telemetry as msg correlation scope #616
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
Draft
stijnmoreels
wants to merge
27
commits into
arcus-azure:main
Choose a base branch
from
stijnmoreels:feature/add-open-telemetry-msg-correlation-scope
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
d9f58a1
feat(correlation): add open-telemetry as msg correlation scope
stijnmoreels 01bf8aa
fix(test): use correct auto-tracking 'is successful' + strictken acti…
stijnmoreels 183c50a
chore(test): provide better test assertion failure messages + use bug…
stijnmoreels 6e5e66e
chore(deps): upgrade sql client package
stijnmoreels 7293eee
chore(deps): use stable open-telemetry http exporter
stijnmoreels fde3632
chore(log): correct log message with missing closing ')'
stijnmoreels 6ad28b2
chore(otel): use additional missing tags
stijnmoreels c162084
Merge branch 'main' into feature/add-open-telemetry-msg-correlation-s…
stijnmoreels ffce365
Merge branch 'main' into feature/add-open-telemetry-msg-correlation-s…
stijnmoreels a43da08
chore(main): finalize merge w/ 'main'
stijnmoreels d85e713
chore(main): finalize merge w/ 'main'
stijnmoreels a01f689
Update docs/preview/03-Features/01-Azure/01-service-bus.mdx
stijnmoreels 9cc8121
Merge branch 'main' into feature/add-open-telemetry-msg-correlation-s…
stijnmoreels b45a9a5
Merge branch 'feature/add-open-telemetry-msg-correlation-scope' of ht…
stijnmoreels b8ef4b0
Update docs/preview/03-Features/01-Azure/01-service-bus.mdx
stijnmoreels 6df1db3
Update src/Arcus.Messaging.Abstractions/MessageHandling/MessageTeleme…
stijnmoreels 0fa96dd
Update docs/preview/03-Features/01-Azure/01-service-bus.mdx
stijnmoreels 1f59973
Merge branch 'main' into feature/add-open-telemetry-msg-correlation-s…
stijnmoreels c3d9fe2
Merge branch 'feature/add-open-telemetry-msg-correlation-scope' of ht…
stijnmoreels 80ac955
Merge branch 'main' into feature/add-open-telemetry-msg-correlation-s…
stijnmoreels 2acba82
Delete src/Arcus.Messaging.Abstractions.ServiceBus/Telemetry/IService…
stijnmoreels 5e8d652
Update src/Arcus.Messaging.Core/MessageHandling/MessageTelemetryOptio…
stijnmoreels 5b5c1f2
Update src/Arcus.Messaging.ServiceBus/ServiceBusReceiverMessagePump.cs
stijnmoreels b5b0736
Update src/Arcus.Messaging.ServiceBus/ServiceBusReceiverMessagePump.cs
stijnmoreels b7de48a
Merge branch 'main' into feature/add-open-telemetry-msg-correlation-s…
stijnmoreels c54fbb4
Merge branch 'feature/add-open-telemetry-msg-correlation-scope' of ht…
stijnmoreels fe3ecda
Merge branch 'main' into feature/add-open-telemetry-msg-correlation-s…
stijnmoreels 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
18 changes: 18 additions & 0 deletions
18
src/Arcus.Messaging.Abstractions.ServiceBus/Telemetry/IServiceBusMessageCorrelationScope.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,18 @@ | ||
| using Arcus.Messaging.Abstractions.MessageHandling; | ||
| using Arcus.Messaging.Abstractions.Telemetry; | ||
|
|
||
| namespace Arcus.Messaging.Abstractions.ServiceBus.Telemetry | ||
| { | ||
| /// <summary> | ||
| /// Represents an approach to track the correlation information of a received Azure Service Bus message within a message pump. | ||
| /// </summary> | ||
| public interface IServiceBusMessageCorrelationScope | ||
|
fgheysels marked this conversation as resolved.
|
||
| { | ||
| /// <summary> | ||
| /// Starts a new Azure Service bus request operation on the telemetry system. | ||
| /// </summary> | ||
| /// <param name="messageContext">The message context for the currently received Azure Service bus message.</param> | ||
| /// <param name="options">The user-configurable options to manipulate the telemetry.</param> | ||
| MessageOperationResult StartOperation(AzureServiceBusMessageContext messageContext, MessageTelemetryOptions options); | ||
| } | ||
| } | ||
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
33 changes: 33 additions & 0 deletions
33
...viceBus.Telemetry.OpenTelemetry/Arcus.Messaging.ServiceBus.Telemetry.OpenTelemetry.csproj
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,33 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <LangVersion>latest</LangVersion> | ||
| <Authors>Arcus</Authors> | ||
| <Company>Arcus</Company> | ||
| <Product>Arcus.Messaging</Product> | ||
| <Description>Provides capability to track message correlation information using OpenTelemetry for Azure Service Bus message pumps</Description> | ||
| <Copyright>Copyright (c) Arcus</Copyright> | ||
| <PackageProjectUrl>https://messaging.arcus-azure.net/</PackageProjectUrl> | ||
| <RepositoryUrl>https://github.com/arcus-azure/arcus.messaging</RepositoryUrl> | ||
| <PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
| <PackageIcon>icon.png</PackageIcon> | ||
| <PackageReadmeFile>README.md</PackageReadmeFile> | ||
| <RepositoryType>Git</RepositoryType> | ||
| <PackageTags>Azure;Messaging;ServiceBus</PackageTags> | ||
| <GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
| <GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
| <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="..\..\README.md" Pack="true" PackagePath="\" /> | ||
| <None Include="..\..\LICENSE" Pack="true" PackagePath="\" /> | ||
| <None Include="..\..\docs\static\img\icon.png" Pack="true" PackagePath="\" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Arcus.Messaging.Abstractions.ServiceBus\Arcus.Messaging.Abstractions.ServiceBus.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
39 changes: 39 additions & 0 deletions
39
...iceBus.Telemetry.OpenTelemetry/Extensions/ServiceBusMessageHandlerCollectionExtensions.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,39 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
| using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling; | ||
| using Arcus.Messaging.Abstractions.ServiceBus.Telemetry; | ||
| using Arcus.Messaging.ServiceBus.Telemetry.OpenTelemetry; | ||
| using Microsoft.Extensions.DependencyInjection.Extensions; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| // ReSharper disable once CheckNamespace | ||
| namespace Microsoft.Extensions.DependencyInjection | ||
| { | ||
| /// <summary> | ||
| /// Extensions on the <see cref="ServiceBusMessageHandlerCollection"/> to register OpenTelemetry services for Azure Service Bus message pumps. | ||
| /// </summary> | ||
| public static class ServiceBusMessageHandlerCollectionExtensions | ||
| { | ||
| /// <summary> | ||
| /// Register OpenTelemetry as the correlation system to track Azure Service Bus message requests within the message pump. | ||
| /// </summary> | ||
| /// <param name="handlers">The collection of Azure Service Bus message handler collection.</param> | ||
| /// <param name="activitySource">The activity source to start <see cref="Activity"/> instances from upon receiving Azure Service Bus messages.</param> | ||
| /// <exception cref="ArgumentNullException">Thrown when the <paramref name="handlers"/> or the <paramref name="activitySource"/> is <c>null</c>.</exception> | ||
| public static ServiceBusMessageHandlerCollection UseServiceBusOpenTelemetryRequestTracking( | ||
| this ServiceBusMessageHandlerCollection handlers, | ||
| ActivitySource activitySource) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(handlers); | ||
| ArgumentNullException.ThrowIfNull(activitySource); | ||
|
|
||
| handlers.Services.TryAddSingleton<IServiceBusMessageCorrelationScope>(serviceProvider => | ||
| { | ||
| var logger = serviceProvider.GetService<ILogger<OpenTelemetryServiceBusMessageCorrelationScope>>(); | ||
| return new OpenTelemetryServiceBusMessageCorrelationScope(activitySource, logger); | ||
| }); | ||
|
|
||
| return handlers; | ||
| } | ||
| } | ||
| } |
111 changes: 111 additions & 0 deletions
111
...ging.ServiceBus.Telemetry.OpenTelemetry/OpenTelemetryServiceBusMessageCorrelationScope.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,111 @@ | ||
| using System; | ||
| using System.Diagnostics; | ||
| using Arcus.Messaging.Abstractions; | ||
| using Arcus.Messaging.Abstractions.MessageHandling; | ||
| using Arcus.Messaging.Abstractions.ServiceBus; | ||
| using Arcus.Messaging.Abstractions.ServiceBus.Telemetry; | ||
| using Arcus.Messaging.Abstractions.Telemetry; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
|
|
||
| namespace Arcus.Messaging.ServiceBus.Telemetry.OpenTelemetry | ||
| { | ||
| /// <summary> | ||
| /// Represents the OpenTelemetry implementation of the <see cref="IServiceBusMessageCorrelationScope"/> | ||
| /// to track the correlation information of a received Azure Service Bus message within a message pump. | ||
| /// </summary> | ||
| internal class OpenTelemetryServiceBusMessageCorrelationScope : IServiceBusMessageCorrelationScope | ||
| { | ||
| private readonly ActivitySource _activitySource; | ||
| private readonly ILogger _logger; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="OpenTelemetryServiceBusMessageCorrelationScope"/> class. | ||
| /// </summary> | ||
| internal OpenTelemetryServiceBusMessageCorrelationScope(ActivitySource activitySource, ILogger<OpenTelemetryServiceBusMessageCorrelationScope> logger) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(activitySource); | ||
| _activitySource = activitySource; | ||
| _logger = logger ?? NullLogger<OpenTelemetryServiceBusMessageCorrelationScope>.Instance; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Starts a new Azure Service bus request operation on the telemetry system. | ||
| /// </summary> | ||
| /// <param name="messageContext">The message context for the currently received Azure Service bus message.</param> | ||
| /// <param name="options">The user-configurable options to manipulate the telemetry.</param> | ||
| public MessageOperationResult StartOperation(AzureServiceBusMessageContext messageContext, MessageTelemetryOptions options) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(messageContext); | ||
| ArgumentNullException.ThrowIfNull(options); | ||
|
|
||
| _logger.LogTrace("Start Azure Service Bus request '{OperationName}' operation...", options.OperationName); | ||
| (string transactionId, string operationParentId) = messageContext.Properties.GetTraceParent(); | ||
|
|
||
| ActivityContext context = new( | ||
| ActivityTraceId.CreateFromString(transactionId), | ||
| ActivitySpanId.CreateFromString(operationParentId), | ||
| ActivityTraceFlags.None); | ||
|
|
||
| Activity activity = _activitySource.CreateActivity( | ||
| name: options.OperationName, | ||
| kind: ActivityKind.Consumer, | ||
| context); | ||
|
|
||
| activity?.Start(); | ||
| if (activity is null) | ||
| { | ||
| return new UnlinkedMessageOperationResult(transactionId, operationParentId); | ||
| } | ||
|
|
||
| activity.SetTag("az.namespace", "Microsoft.ServiceBus"); | ||
| activity.SetTag("messaging.system", "servicebus"); | ||
| activity.SetTag("messaging.operation.type", "receive"); | ||
| activity.SetTag("messaging.destination.name", messageContext.EntityPath); | ||
| activity.SetTag("messaging.message.id", messageContext.MessageId); | ||
| activity.SetTag("network.protocol.name", "amqp"); | ||
|
|
||
| activity.SetTag("ServiceBus-Endpoint", messageContext.FullyQualifiedNamespace); | ||
| activity.SetTag("ServiceBus-Entity", messageContext.EntityPath); | ||
| activity.SetTag("ServiceBus-EntityType", messageContext.EntityType.ToString()); | ||
|
|
||
| return new OpenTelemetryMessageOperationResult(activity, _logger); | ||
| } | ||
|
|
||
| private sealed class OpenTelemetryMessageOperationResult : MessageOperationResult | ||
| { | ||
| private readonly Activity _activity; | ||
| private readonly ILogger _logger; | ||
|
|
||
| internal OpenTelemetryMessageOperationResult(Activity activity, ILogger logger) | ||
| : base(new MessageCorrelationInfo(activity.TraceId.ToString(), activity.SpanId.ToString(), activity.ParentSpanId.ToString())) | ||
| { | ||
| _activity = activity; | ||
| _logger = logger; | ||
| } | ||
|
|
||
| protected override void StopOperation(bool isSuccessful, DateTimeOffset startTime, TimeSpan duration) | ||
| { | ||
| _logger.LogTrace("Stop Azure Service Bus request '{OperationName}' operation (isSuccessful={IsSuccessful})", _activity.OperationName, isSuccessful); | ||
|
|
||
| _activity.SetStatus(isSuccessful ? ActivityStatusCode.Ok : ActivityStatusCode.Error); | ||
| _activity.SetTag("messaging.operation.name", isSuccessful ? "ack" : "nack"); | ||
|
|
||
| _activity.SetEndTime(_activity.StartTimeUtc.Add(duration)); | ||
| _activity.Dispose(); | ||
| } | ||
| } | ||
|
|
||
| private sealed class UnlinkedMessageOperationResult : MessageOperationResult | ||
| { | ||
| internal UnlinkedMessageOperationResult(string transactionId, string operationParentId) | ||
| : base(new MessageCorrelationInfo(Guid.NewGuid().ToString(), transactionId, operationParentId)) | ||
| { | ||
| } | ||
|
|
||
| protected override void StopOperation(bool isSuccessful, DateTimeOffset startTime, TimeSpan duration) | ||
| { | ||
| } | ||
| } | ||
| } | ||
| } |
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.