Skip to content

Commit 1f6a575

Browse files
committed
chore(observability): remove the arcus.observability hard-link in messaging
1 parent 8a10927 commit 1f6a575

File tree

15 files changed

+153
-45
lines changed

15 files changed

+153
-45
lines changed

src/Arcus.Messaging.Abstractions.ServiceBus/AzureServiceBusMessageContext.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,25 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using Azure.Messaging.ServiceBus;
7-
using Microsoft.Extensions.Logging;
87

98
namespace Arcus.Messaging.Abstractions.ServiceBus
109
{
10+
/// <summary>
11+
/// Represents the type of Azure Service Bus entity on which the message was received.
12+
/// </summary>
13+
public enum ServiceBusEntityType
14+
{
15+
/// <summary>
16+
/// The Azure Service Bus entity is a queue.
17+
/// </summary>
18+
Queue,
19+
20+
/// <summary>
21+
/// The Azure Service Bus entity is a topic subscription.
22+
/// </summary>
23+
Topic
24+
}
25+
1126
/// <summary>
1227
/// Represents the contextual information concerning an Azure Service Bus message.
1328
/// </summary>

src/Arcus.Messaging.Abstractions.ServiceBus/MessageHandling/AzureServiceBusMessageRouter.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using Arcus.Messaging.Abstractions.MessageHandling;
77
using Arcus.Messaging.Abstractions.Telemetry;
8-
using Arcus.Observability.Telemetry.Core;
98
using Azure.Messaging.ServiceBus;
109
using Microsoft.Extensions.DependencyInjection;
1110
using Microsoft.Extensions.Logging;
@@ -100,31 +99,12 @@ protected async Task<MessageProcessingResult> RouteMessageWithPotentialFallbackA
10099
throw new ArgumentNullException(nameof(correlationInfo));
101100
}
102101

103-
string entityName = messageReceiver?.EntityPath ?? "<not-available>";
104-
string serviceBusNamespace = messageReceiver?.FullyQualifiedNamespace ?? "<not-available>";
105-
106-
using DurationMeasurement measurement = DurationMeasurement.Start();
107102
using IServiceScope serviceScope = ServiceProvider.CreateScope();
108103
#pragma warning disable CS0618 // Type or member is obsolete: will be refactored when moving towards v3.0.
109104
using IDisposable _ = LogContext.Push(new MessageCorrelationInfoEnricher(correlationInfo, Options.CorrelationEnricher));
110105
#pragma warning restore CS0618 // Type or member is obsolete
111106

112-
try
113-
{
114-
MessageProcessingResult routingResult = await TryRouteMessageWithPotentialFallbackAsync(serviceScope.ServiceProvider, messageReceiver, message, messageContext, correlationInfo, cancellationToken);
115-
116-
#pragma warning disable CS0618 // Type or member is obsolete: specific telemetry calls will be removed in v3.0.
117-
Logger.LogServiceBusRequest(serviceBusNamespace, entityName, Options.Telemetry.OperationName, routingResult.IsSuccessful, measurement, messageContext.EntityType);
118-
#pragma warning restore CS0618 // Type or member is obsolete
119-
return routingResult;
120-
}
121-
catch
122-
{
123-
#pragma warning disable CS0618 // Type or member is obsolete: specific telemery calls will be removed in v3.0.
124-
Logger.LogServiceBusRequest(serviceBusNamespace, entityName, Options.Telemetry.OperationName, false, measurement, messageContext.EntityType);
125-
#pragma warning restore CS0618 // Type or member is obsolete
126-
throw;
127-
}
107+
return await TryRouteMessageWithPotentialFallbackAsync(serviceScope.ServiceProvider, messageReceiver, message, messageContext, correlationInfo, cancellationToken);
128108
}
129109

130110
private async Task<MessageProcessingResult> TryRouteMessageWithPotentialFallbackAsync(

src/Arcus.Messaging.Abstractions/Arcus.Messaging.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
<ItemGroup>
3030
<!-- TODO: will be removed in v3.0 -->
31-
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Enrichers" Version="[3.0.0,4.0.0)" />
3231
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
32+
<PackageReference Include="Serilog" Version="4.3.0" />
3333
<!-- TODO: will be removed in v3.0 -->
3434
</ItemGroup>
3535

src/Arcus.Messaging.Abstractions/MessageCorrelationInfo.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
using System;
2-
using Arcus.Observability.Correlation;
32

43
namespace Arcus.Messaging.Abstractions
54
{
65
/// <summary>
76
/// Represents the information concerning correlation of telemetry &amp; processes with main focus on messaging scenarios.
87
/// </summary>
9-
public class MessageCorrelationInfo : CorrelationInfo
8+
public class MessageCorrelationInfo
109
{
1110
/// <summary>
1211
/// Initializes a new instance of the <see cref="MessageCorrelationInfo"/> class.
1312
/// </summary>
1413
/// <param name="operationId">The unique identifier that spans one operation end-to-end.</param>
1514
/// <param name="transactionId">The unique identifier that spans one or more operations and are considered a transaction/session.</param>
16-
/// <exception cref="ArgumentException">Thrown when the <paramref name="operationId"/> is blank.</exception>
15+
/// <exception cref="ArgumentException">Thrown when the <paramref name="operationId"/> or <paramref name="transactionId"/> is blank.</exception>
1716
public MessageCorrelationInfo(string operationId, string transactionId)
18-
: base(operationId, transactionId, operationParentId: null)
1917
{
18+
ArgumentException.ThrowIfNullOrWhiteSpace(operationId);
19+
ArgumentException.ThrowIfNullOrWhiteSpace(transactionId);
20+
21+
OperationId = operationId;
22+
TransactionId = transactionId;
2023
CycleId = Guid.NewGuid().ToString("D");
2124
}
2225

@@ -26,13 +29,37 @@ public MessageCorrelationInfo(string operationId, string transactionId)
2629
/// <param name="operationId">The unique identifier that spans one operation end-to-end.</param>
2730
/// <param name="transactionId">The unique identifier that spans one or more operations and are considered a transaction/session.</param>
2831
/// <param name="operationParentId">The unique identifier of the original service that initiated this request.</param>
29-
/// <exception cref="ArgumentException">Thrown when the <paramref name="operationId"/> is blank.</exception>
32+
/// <exception cref="ArgumentException">
33+
/// Thrown when the <paramref name="operationId"/>, <paramref name="transactionId"/> or <paramref name="operationParentId"/> is blank.
34+
/// </exception>
3035
public MessageCorrelationInfo(string operationId, string transactionId, string operationParentId)
31-
: base(operationId, transactionId, operationParentId)
3236
{
37+
ArgumentException.ThrowIfNullOrWhiteSpace(operationId);
38+
ArgumentException.ThrowIfNullOrWhiteSpace(transactionId);
39+
ArgumentException.ThrowIfNullOrWhiteSpace(operationParentId);
40+
41+
OperationId = operationId;
42+
TransactionId = transactionId;
43+
OperationParentId = operationParentId;
44+
3345
CycleId = Guid.NewGuid().ToString("D");
3446
}
3547

48+
/// <summary>
49+
/// Gets the ID that relates different messaging requests together in a single transaction.
50+
/// </summary>
51+
public string TransactionId { get; }
52+
53+
/// <summary>
54+
/// Gets the unique ID information of the messaging request.
55+
/// </summary>
56+
public string OperationId { get; }
57+
58+
/// <summary>
59+
/// Gets the ID of the original service that initiated this messaging request.
60+
/// </summary>
61+
public string OperationParentId { get; }
62+
3663
/// <summary>
3764
/// Gets the unique identifier that indicates an attempt to process a given message.
3865
/// </summary>

src/Arcus.Messaging.Abstractions/MessageHandling/MessageCorrelationEnricherOptions.cs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,60 @@
11
using System;
22
using Arcus.Messaging.Abstractions.Telemetry;
3-
using Arcus.Observability.Telemetry.Serilog.Enrichers.Configuration;
43

54
namespace Arcus.Messaging.Abstractions.MessageHandling
65
{
76
/// <summary>
87
/// Represents the consumer configurable options model to change the behavior of the Serilog <see cref="MessageCorrelationInfoEnricher"/>.
98
/// </summary>
109
[Obsolete("Will be removed in v3.0 as W3C will be the only supported correlation format")]
11-
public class MessageCorrelationEnricherOptions : CorrelationInfoEnricherOptions
10+
public class MessageCorrelationEnricherOptions
1211
{
1312
private string _cycleIdPropertyName = "CycleId";
13+
private string _operationIdPropertyName = "OperationId";
14+
private string _transactionIdPropertyName = "TransactionId";
15+
private string _operationParentIdPropertyName = "OperationParentId";
16+
17+
/// <summary>
18+
/// Gets or sets the property name to enrich the log event with the correlation information operation ID.
19+
/// </summary>
20+
/// <exception cref="T:System.ArgumentException">Thrown when the <paramref name="value" /> is blank.</exception>
21+
public string OperationIdPropertyName
22+
{
23+
get => _operationIdPropertyName;
24+
set
25+
{
26+
ArgumentException.ThrowIfNullOrWhiteSpace(value);
27+
_operationIdPropertyName = value;
28+
}
29+
}
30+
31+
/// <summary>
32+
/// Gets or sets the property name to enrich the log event with the correlation information transaction ID.
33+
/// </summary>
34+
/// <exception cref="T:System.ArgumentException">Thrown when the <paramref name="value" /> is blank.</exception>
35+
public string TransactionIdPropertyName
36+
{
37+
get => _transactionIdPropertyName;
38+
set
39+
{
40+
ArgumentException.ThrowIfNullOrWhiteSpace(value);
41+
_transactionIdPropertyName = value;
42+
}
43+
}
44+
45+
/// <summary>
46+
/// Gets or sets the property name to enrich the log event with the correlation information parent operation ID.
47+
/// </summary>
48+
/// <exception cref="T:System.ArgumentException">Thrown when the <paramref name="value" /> is blank.</exception>
49+
public string OperationParentIdPropertyName
50+
{
51+
get => _operationParentIdPropertyName;
52+
set
53+
{
54+
ArgumentException.ThrowIfNullOrWhiteSpace(value);
55+
_operationParentIdPropertyName = value;
56+
}
57+
}
1458

1559
/// <summary>
1660
/// Gets or sets the property name to enrich the log event with the correlation information cycle ID.
@@ -21,11 +65,7 @@ public string CycleIdPropertyName
2165
get => _cycleIdPropertyName;
2266
set
2367
{
24-
if (string.IsNullOrWhiteSpace(value))
25-
{
26-
throw new ArgumentException("Requires a non-blank property name for the cycle ID", nameof(value));
27-
}
28-
68+
ArgumentException.ThrowIfNullOrWhiteSpace(value);
2969
_cycleIdPropertyName = value;
3070
}
3171
}

src/Arcus.Messaging.Pumps.ServiceBus/Extensions/IServiceCollectionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Arcus.Messaging.Abstractions.ServiceBus;
23
using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling;
34
using Arcus.Messaging.Pumps.Abstractions.Resiliency;
45
using Arcus.Messaging.Pumps.ServiceBus;

src/Arcus.Messaging.Pumps.ServiceBus/ServiceBusMessageRouter.cs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq;
45
using System.Text;
56
using System.Threading;
@@ -9,7 +10,6 @@
910
using Arcus.Messaging.Abstractions.ServiceBus;
1011
using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling;
1112
using Arcus.Messaging.Abstractions.Telemetry;
12-
using Arcus.Observability.Telemetry.Core;
1313
using Azure.Messaging.ServiceBus;
1414
using Microsoft.Extensions.DependencyInjection;
1515
using Microsoft.Extensions.Logging;
@@ -55,7 +55,9 @@ internal async Task<MessageProcessingResult> RouteMessageAsync(
5555
MessageCorrelationInfo correlationInfo,
5656
CancellationToken cancellationToken)
5757
{
58-
using DurationMeasurement measurement = DurationMeasurement.Start();
58+
var startTime = DateTimeOffset.UtcNow;
59+
var watch = Stopwatch.StartNew();
60+
5961
using IServiceScope serviceScope = ServiceProvider.CreateScope();
6062
#pragma warning disable CS0618 // Type or member is obsolete: will be refactored when moving towards v3.0.
6163
using IDisposable _ = LogContext.Push(new MessageCorrelationInfoEnricher(correlationInfo, Options.CorrelationEnricher));
@@ -71,8 +73,9 @@ internal async Task<MessageProcessingResult> RouteMessageAsync(
7173
}
7274
finally
7375
{
76+
watch.Stop();
7477
#pragma warning disable CS0618 // Type or member is obsolete
75-
Logger.LogServiceBusRequest(messageContext.FullyQualifiedNamespace, messageContext.EntityPath, Options.Telemetry.OperationName, isSuccessful, measurement, messageContext.EntityType);
78+
Logger.LogServiceBusRequest(messageContext.FullyQualifiedNamespace, messageContext.EntityPath, Options.Telemetry.OperationName, isSuccessful, watch.Elapsed, startTime, messageContext.EntityType);
7679
#pragma warning restore CS0618 // Type or member is obsolete
7780
}
7881
}
@@ -190,4 +193,44 @@ private async Task AbandonMessageMatchedHandlerFailedAsync(AzureServiceBusMessag
190193
await messageContext.AbandonMessageAsync(new Dictionary<string, object>(), CancellationToken.None);
191194
}
192195
}
196+
197+
internal static class ILoggerExtensions
198+
{
199+
public static void LogServiceBusRequest(
200+
this ILogger logger,
201+
string serviceBusNamespace,
202+
string entityName,
203+
string operationName,
204+
bool isSuccessful,
205+
TimeSpan duration,
206+
DateTimeOffset startTime,
207+
ServiceBusEntityType entityType,
208+
Dictionary<string, object> context = null)
209+
{
210+
if (string.IsNullOrWhiteSpace(operationName))
211+
{
212+
operationName = "Azure Service Bus message processing";
213+
}
214+
215+
context = context is null ? new Dictionary<string, object>() : new Dictionary<string, object>(context);
216+
context["Endpoint"] = serviceBusNamespace;
217+
context["EntityName"] = entityName;
218+
context["EntityType"] = entityType;
219+
220+
logger.LogWarning("@{Request}", new
221+
{
222+
SourceSystem = RequestSourceSystem.AzureServiceBus,
223+
RequestMethod = "<not-applicable>",
224+
RequestHost = "<not-applicable>",
225+
RequestUri = "<not-applicable>",
226+
ResponseStatusCode = isSuccessful ? 200 : 500,
227+
OperationName = operationName,
228+
RequestDuration = duration,
229+
RequestTime = startTime.ToString("yyyy-MM-ddTHH:mm:ss.fffffff zzz"),
230+
Context = context
231+
});
232+
}
233+
234+
private enum RequestSourceSystem { AzureServiceBus }
235+
}
193236
}

src/Arcus.Messaging.Tests.Core/Arcus.Messaging.Tests.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9+
<PackageReference Include="Arcus.Observability.Telemetry.Core" Version="3.0.0" />
910
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
1011
<PackageReference Include="Bogus" Version="29.0.2" />
1112
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />

src/Arcus.Messaging.Tests.Integration/Arcus.Messaging.Tests.Integration.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<PackageReference Include="Arcus.Testing.Messaging.ServiceBus" Version="2.0.0" />
1313
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
15-
<PackageReference Include="Serilog" Version="2.11.0" />
1615
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.1.0" />
1716
<PackageReference Include="xunit.v3" Version="2.*" />
1817
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">

src/Arcus.Messaging.Tests.Integration/MessagePump/Fixture/ServiceBusTestContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Microsoft.Extensions.Logging.Abstractions;
2323
using Newtonsoft.Json;
2424
using Xunit;
25+
using ServiceBusEntityType = Arcus.Messaging.Abstractions.ServiceBus.ServiceBusEntityType;
2526

2627
namespace Arcus.Messaging.Tests.Integration.MessagePump.Fixture
2728
{

0 commit comments

Comments
 (0)