Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dotnetcore/CAP
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-xiaodong committed Sep 21, 2023
2 parents c63fa87 + 203bf5a commit dd22ed3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/DotNetCore.CAP.OpenTelemetry/DiagnosticListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ public void OnNext(KeyValuePair<string, object?> evt)
activity.AddEvent(new ActivityEvent("CAP message persistence start...",
DateTimeOffset.FromUnixTimeMilliseconds(eventData.OperationTimestamp!.Value)));

if (parentContext != default) _contexts[eventData.Message.GetId()] = Activity.Current!.Context;
if (parentContext != default)
{
_contexts[eventData.Message.GetId()] = Activity.Current!.Context;
Propagator.Inject(new PropagationContext(Activity.Current.Context, Baggage.Current),
eventData.Message,
(msg, key, value) => { msg.Headers[key] = value; });
};
}
}
break;
Expand Down Expand Up @@ -89,10 +95,14 @@ public void OnNext(KeyValuePair<string, object?> evt)
case CapEvents.BeforePublish:
{
var eventData = (CapEventDataPubSend)evt.Value!;
var parentContext = Propagator.Extract(default, eventData.TransportMessage, (msg, key) =>
{
return msg.Headers.TryGetValue(key, out var value) ? (new[] { value }) : Enumerable.Empty<string>();
});
_contexts.TryRemove(eventData.TransportMessage.GetId(), out var context);
var activity = ActivitySource.StartActivity(
OperateNamePrefix + eventData.Operation + ProducerOperateNameSuffix, ActivityKind.Producer,
context);
parentContext.ActivityContext);
if (activity != null)
{
activity.SetTag("messaging.system", eventData.BrokerAddress.Name);
Expand Down

0 comments on commit dd22ed3

Please sign in to comment.