Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/additional-metrics' into additio…
Browse files Browse the repository at this point in the history
…nal-metrics
  • Loading branch information
saratry committed May 21, 2024
2 parents 4e04ce5 + a71af58 commit 09cc106
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/CommonConfigurations/EmitNServiceBusMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ protected override void Setup(FeatureConfigurationContext context)
context.Pipeline.OnReceivePipelineCompleted((e, _) =>
{
e.TryGetMessageType(out var messageType);
e.TryGetRequestId(out var requestId);

var tags = new TagList(
[
new(Tags.QueueName, queueName ?? ""),
new(Tags.EndpointDiscriminator, discriminator ?? ""),
new(Tags.MessageType, messageType ?? ""),
new(Tags.LoanBrokerRequestId, requestId ?? "")
]);

ProcessingTime.Record((e.CompletedAt - e.StartedAt).TotalMilliseconds, tags);
Expand All @@ -51,5 +53,6 @@ static class Tags
public const string EndpointDiscriminator = "nservicebus.discriminator";
public const string QueueName = "nservicebus.queue";
public const string MessageType = "nservicebus.message_type";
public const string LoanBrokerRequestId = "loan_broker.request_id";
}
}
16 changes: 15 additions & 1 deletion src/CommonConfigurations/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public static bool TryGetDeliverAt(this ReceivePipelineCompleted completed, out
public static bool TryGetMessageType(this ReceivePipelineCompleted completed, out string processedMessageType)
=> completed.ProcessedMessage.Headers.TryGetMessageType(out processedMessageType);

internal static bool TryGetMessageType(this IReadOnlyDictionary<string, string> headers, out string processedMessageType)
public static bool TryGetRequestId(this ReceivePipelineCompleted completed, out string requestId)
=> completed.ProcessedMessage.Headers.TryGetRequestId(out requestId);

static bool TryGetMessageType(this IReadOnlyDictionary<string, string> headers, out string processedMessageType)
{
if (headers.TryGetValue(Headers.EnclosedMessageTypes, out var enclosedMessageType))
{
Expand All @@ -43,4 +46,15 @@ internal static bool TryGetMessageType(this IReadOnlyDictionary<string, string>
processedMessageType = null;

Check warning on line 46 in src/CommonConfigurations/Extensions.cs

View workflow job for this annotation

GitHub Actions / Linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 46 in src/CommonConfigurations/Extensions.cs

View workflow job for this annotation

GitHub Actions / Linux

Cannot convert null literal to non-nullable reference type.
return false;
}

static bool TryGetRequestId(this IReadOnlyDictionary<string, string> headers, out string requestId)
{
if (headers.TryGetValue("LoanBroker.RequestId", out var requestIdValue))
{
requestId = requestIdValue;
return true;
}
requestId = null;

Check warning on line 57 in src/CommonConfigurations/Extensions.cs

View workflow job for this annotation

GitHub Actions / Linux

Cannot convert null literal to non-nullable reference type.

Check warning on line 57 in src/CommonConfigurations/Extensions.cs

View workflow job for this annotation

GitHub Actions / Linux

Cannot convert null literal to non-nullable reference type.
return false;
}
}

0 comments on commit 09cc106

Please sign in to comment.