public static Activity StartActivity()

in extension/WebJobs.Extensions.RabbitMQ/Trigger/RabbitMQActivitySource.cs [20:46]


    public static Activity StartActivity(IBasicProperties basicProperties)
    {
        // Ideally, we would have used string values for headers, but RabbitMQ client has an old quirk where it does
        // not differentiate between string headers and byte-array headers when decoding them. See:
        // https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/415. Hence, it is decided to also set a byte[]
        // as the value for 'traceparent' header to keep its types consistent for all cases.
        if (basicProperties.Headers?.ContainsKey("traceparent") == true)
        {
            byte[] traceParentIdInBytes = basicProperties.Headers["traceparent"] as byte[];
            string traceparentId = Encoding.UTF8.GetString(traceParentIdInBytes);
            return ActivitySource.StartActivity("Trigger", ActivityKind.Consumer, traceparentId);
        }
        else
        {
            Activity activity = ActivitySource.StartActivity("Trigger", ActivityKind.Consumer);

            // Method 'StartActivity' will return null if it has no event listeners.
            if (activity != null)
            {
                basicProperties.Headers ??= new Dictionary<string, object>();
                byte[] traceParentIdInBytes = Encoding.UTF8.GetBytes(activity.Id);
                basicProperties.Headers["traceparent"] = traceParentIdInBytes;
            }

            return activity;
        }
    }