Ver a proveniência

Fixed Activity is created as null when ASP.NET Core instrument is not enabled.

master
Savorboard há 2 anos
ascendente
cometimento
9c8baeccf7
1 ficheiros alterados com 12 adições e 9 eliminações
  1. +12
    -9
      src/DotNetCore.CAP.OpenTelemetry/DiagnosticListener.cs

+ 12
- 9
src/DotNetCore.CAP.OpenTelemetry/DiagnosticListener.cs Ver ficheiro

@@ -26,7 +26,7 @@ namespace DotNetCore.CAP.OpenTelemetry
private const string OperateNamePrefix = "CAP/";
private const string ProducerOperateNameSuffix = "/Publisher";
private const string ConsumerOperateNameSuffix = "/Subscriber";
public void OnCompleted()
{
}
@@ -42,22 +42,25 @@ namespace DotNetCore.CAP.OpenTelemetry
case CapEvents.BeforePublishMessageStore:
{
var eventData = (CapEventDataPubStore)evt.Value!;
var useParent = false;
if (Activity.Current != null)
ActivityContext parentContext = default;

if (Activity.Current != null && Activity.Current.Source.Name == "OpenTelemetry.Instrumentation.AspNetCore")
{
if (_contexts.TryAdd(eventData.Message.GetId(), Activity.Current.Context))
{
useParent = true;
}
_contexts.TryAdd(eventData.Message.GetId(), parentContext = Activity.Current.Context);
}
var activity = ActivitySource.StartActivity("Event Persistence: " + eventData.Operation);
else
{
Activity.Current = null;
}

var activity = ActivitySource.StartActivity("Event Persistence: " + eventData.Operation, ActivityKind.Internal, parentContext);
if (activity != null)
{
activity.SetTag("message.name", eventData.Operation);
activity.AddEvent(new ActivityEvent("CAP message persistence start...",
DateTimeOffset.FromUnixTimeMilliseconds(eventData.OperationTimestamp!.Value)));

if (!useParent)
if (parentContext != default)
{
_contexts[eventData.Message.GetId()] = Activity.Current!.Context;
}


Carregando…
Cancelar
Guardar