/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <typeparam name="TBasicProperties">Type of the message properties</typeparam> /// <typeparam name="TBody">Type of the message body</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="exchange">Name of the exchange.</param> /// <param name="routingKey">The routing key.</param> /// <param name="mandatory">The mandatory routing flag.</param> /// <param name="basicProperties">The message properties.</param> /// <param name="body">The message body.</param> /// <returns>Calltarget state value</returns> internal static CallTargetState OnMethodBegin <TTarget, TBasicProperties, TBody>(TTarget instance, string exchange, string routingKey, bool mandatory, TBasicProperties basicProperties, TBody body) where TBasicProperties : IBasicProperties, IDuckType where TBody : IBody, IDuckType // Versions < 6.0.0: TBody is byte[] // Versions >= 6.0.0: TBody is ReadOnlyMemory<byte> { var tracer = Tracer.Instance; var scope = RabbitMQIntegration.CreateScope(tracer, out RabbitMQTags tags, Command, spanKind: SpanKinds.Producer, exchange: exchange, routingKey: routingKey); if (scope != null) { string exchangeDisplayName = string.IsNullOrEmpty(exchange) ? "<default>" : exchange; string routingKeyDisplayName = string.IsNullOrEmpty(routingKey) ? "<all>" : routingKey.StartsWith("amq.gen-") ? "<generated>" : routingKey; scope.Span.ResourceName = $"{Command} {exchangeDisplayName} -> {routingKeyDisplayName}"; if (tags != null) { tags.MessageSize = body.Instance != null?body.Length.ToString() : "0"; RabbitMQIntegration.SetTagsFromBasicProperties(tags, basicProperties); } if (basicProperties.Instance != null) { // add distributed tracing headers to the message if (basicProperties.Headers == null) { basicProperties.Headers = new Dictionary <string, object>(); } SpanContextPropagator.Instance.Inject(scope.Span.Context, basicProperties.Headers, ContextPropagation.HeadersSetter); } } return(new CallTargetState(scope)); }
/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <typeparam name="TBasicProperties">Type of the message properties</typeparam> /// <typeparam name="TBody">Type of the message body</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="consumerTag">The original consumerTag argument</param> /// <param name="deliveryTag">The original deliveryTag argument</param> /// <param name="redelivered">The original redelivered argument</param> /// <param name="exchange">Name of the exchange.</param> /// <param name="routingKey">The routing key.</param> /// <param name="basicProperties">The message properties.</param> /// <param name="body">The message body.</param> /// <returns>Calltarget state value</returns> internal static CallTargetState OnMethodBegin <TTarget, TBasicProperties, TBody>(TTarget instance, string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, TBasicProperties basicProperties, TBody body) where TBasicProperties : IBasicProperties where TBody : IBody // ReadOnlyMemory<byte> body in 6.0.0 { Tracer tracer = Tracer.Instance; SpanContext propagatedContext = null; // try to extract propagated context values from headers if (basicProperties?.Headers != null) { try { propagatedContext = SpanContextPropagator.Instance.Extract(basicProperties.Headers, ContextPropagation.HeadersGetter); } catch (Exception ex) { Log.Error(ex, "Error extracting propagated headers."); } } var scope = RabbitMQIntegration.CreateScope(Tracer.Instance, out RabbitMQTags tags, Command, parentContext: propagatedContext, spanKind: SpanKinds.Consumer, exchange: exchange, routingKey: routingKey); if (tags != null) { tags.MessageSize = body?.Length.ToString() ?? "0"; RabbitMQIntegration.SetTagsFromBasicProperties(tags, basicProperties); } return(new CallTargetState(scope)); }