Skip to content

Commit

Permalink
Cleanup and OpenTelemetry tweaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
houseofcat committed Apr 17, 2024
1 parent 70028ad commit 0c858e5
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 63 deletions.
6 changes: 3 additions & 3 deletions src/HouseofCat.Dataflows/BaseDataflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void WrapAction(TState state)
childSpan?.SetStatus(Status.Error.WithDescription(ex.Message));
}

childSpan?.End();
childSpan.End();
state.EndRootSpan(true);
}

Expand All @@ -155,7 +155,7 @@ void WrapAction(TState state)
childSpan?.SetStatus(Status.Error.WithDescription(ex.Message));
}

childSpan?.End();
childSpan.End();
state.EndRootSpan(true);
}

Expand All @@ -180,7 +180,7 @@ async Task WrapActionAsync(TState state)
childSpan?.SetStatus(Status.Error.WithDescription(ex.Message));
}

childSpan?.End();
childSpan.End();
state.EndRootSpan(true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/HouseofCat.Dataflows/Extensions/WorkStateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public static void AddEvent(this IWorkState state, string name, string descripti
{
state.SetOpenTelemetryError();
}
state.WorkflowSpan?.End();
state.WorkflowSpan.End();
state.WorkflowSpan?.Dispose();
}
}
3 changes: 3 additions & 0 deletions src/HouseofCat.RabbitMQ/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public static class Constants
public static string MessagingConsumerNameKey { get; set; } = "messaging.rabbitmq.consumer.name";
public static string MessagingMessageMessageIdKey { get; set; } = "messaging.message.id";

public static string MessagingMessageBodySizeKey { get; set; } = "messaging.rabbitmq.message.body.size";
public static string MessagingMessageEnvelopeSizeKey { get; set; } = "messaging.rabbitmq.message.envelope.size";

public static string MessagingMessageRoutingKeyKey { get; set; } = "messaging.rabbitmq.message.routing_key";
public static string MessagingMessageDeliveryTagIdKey { get; set; } = "messaging.rabbitmq.message.delivery_tag";

Expand Down
5 changes: 2 additions & 3 deletions src/HouseofCat.RabbitMQ/Consumer/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public async Task StartConsumerAsync()
FullMode = ConsumerOptions.BehaviorWhenFull.Value
});

await Task.Yield();
var success = false;
while (!success)
{
Expand Down Expand Up @@ -308,7 +307,7 @@ protected virtual async Task ReceiveHandlerAsync(object _, BasicDeliverEventArgs
await HandleMessageAsync(bdea).ConfigureAwait(false);
}

private static readonly string _consumerSpanNameFormat = "{0}.{1}";
private static readonly string _consumerSpanNameFormat = "messaging.rabbitmq.consumer receive";

protected virtual async ValueTask<bool> HandleMessageAsync(BasicDeliverEventArgs bdea)
{
Expand All @@ -318,7 +317,7 @@ protected virtual async ValueTask<bool> HandleMessageAsync(BasicDeliverEventArgs
{
var receivedMessage = new ReceivedMessage(_chanHost.Channel, bdea, !ConsumerOptions.AutoAck);
using var span = OpenTelemetryHelpers.StartActiveSpan(
string.Format(_consumerSpanNameFormat, ConsumerOptions.ConsumerName, nameof(HandleMessageAsync)),
_consumerSpanNameFormat,
SpanKind.Consumer,
receivedMessage.ParentSpanContext ?? default);

Expand Down
6 changes: 3 additions & 3 deletions src/HouseofCat.RabbitMQ/Dataflows/ConsumerDataflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ TState WrapAction(TState state)
state.EDI = ExceptionDispatchInfo.Capture(ex);
}

childSpan?.End();
childSpan.End();
return state;
}

Expand Down Expand Up @@ -720,7 +720,7 @@ async Task<TState> WrapActionAsync(TState state)
state.EDI = ExceptionDispatchInfo.Capture(ex);
}

childSpan?.End();
childSpan.End();
return state;
}

Expand Down Expand Up @@ -748,7 +748,7 @@ async Task<TState> WrapPublishAsync(TState state)
state.EDI = ExceptionDispatchInfo.Capture(ex);
}

childSpan?.End();
childSpan.End();
return state;
}

Expand Down
1 change: 1 addition & 0 deletions src/HouseofCat.RabbitMQ/Extensions/MessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public static void EnrichSpanWithTags(this IMessage message, TelemetrySpan span)
span.SetAttribute(Constants.MessagingMessageContentTypeKey, message.ContentType);
}

span.SetAttribute(Constants.MessagingMessageBodySizeKey, message.Body.Length);
span.SetAttribute(Constants.MessagingMessageDeliveryModeKey, message.DeliveryMode);
span.SetAttribute(Constants.MessagingMessagePriorityKey, message.PriorityLevel);
span.SetAttribute(Constants.MessagingMessageMandatoryKey, message.Mandatory);
Expand Down

0 comments on commit 0c858e5

Please sign in to comment.