Skip to content

Commit

Permalink
OpenTelemetryConsumerEventsHandler codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
simaoribeiro committed Oct 13, 2023
1 parent 02572b1 commit 1d4b811
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
internal static class OpenTelemetryConsumerEventsHandler
{
private static readonly TextMapPropagator Propagator = Propagators.DefaultTextMapPropagator;
private static readonly string ProcessString = "process";
private const string ProcessString = "process";

public static Task OnConsumeStarted(IMessageContext context)
{
try
{
var activityName = !string.IsNullOrEmpty(context?.ConsumerContext.Topic) ? $"{context.ConsumerContext.Topic} {ProcessString}" : ProcessString;
var activityName = !string.IsNullOrEmpty(context?.ConsumerContext.Topic) ? $"{context?.ConsumerContext.Topic} {ProcessString}" : ProcessString;

// Extract the PropagationContext of the upstream parent from the message headers.
var parentContext = Propagator.Extract(new PropagationContext(default, Baggage.Current), context, ExtractTraceContextIntoBasicProperties);
Expand All @@ -33,7 +33,7 @@ public static Task OnConsumeStarted(IMessageContext context)
activity.AddBaggage(item.Key, item.Value);
}

context.Items.Add(KafkaFlowActivitySourceHelper.ActivityString, activity);
context?.Items.Add(KafkaFlowActivitySourceHelper.ActivityString, activity);

KafkaFlowActivitySourceHelper.SetGenericTags(activity);

Expand All @@ -44,6 +44,7 @@ public static Task OnConsumeStarted(IMessageContext context)
}
catch
{
// If there is any failure, do not propagate the context.
}

return Task.CompletedTask;
Expand Down

0 comments on commit 1d4b811

Please sign in to comment.