/// <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> public 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 { 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"; } 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="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> /// OnMethodEnd callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <typeparam name="TResult">Type of the BasicGetResult</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="basicGetResult">BasicGetResult instance</param> /// <param name="exception">Exception instance in case the original code threw an exception.</param> /// <param name="state">Calltarget state value</param> /// <returns>A default CallTargetReturn to satisfy the CallTarget contract</returns> public static CallTargetReturn <TResult> OnMethodEnd <TTarget, TResult>(TTarget instance, TResult basicGetResult, Exception exception, CallTargetState state) where TResult : IBasicGetResult, IDuckType { string queue = (string)state.State; DateTimeOffset?startTime = state.StartTime; Tracer tracer = Tracer.Instance; SpanContext propagatedContext = null; string messageSize = null; if (basicGetResult.Instance != null) { messageSize = basicGetResult.Body?.Length.ToString(); var basicPropertiesHeaders = basicGetResult.BasicProperties?.Headers; // try to extract propagated context values from headers if (basicPropertiesHeaders != null) { try { propagatedContext = tracer.Propagator.Extract(basicPropertiesHeaders, ContextPropagation.HeadersGetter); } catch (Exception ex) { Log.Error(ex, "Error extracting propagated headers."); } } } using (var scope = RabbitMQIntegration.CreateScope(tracer, out RabbitMQTags tags, Command, parentContext: propagatedContext, spanKind: SpanKinds.Consumer, queue: queue, startTime: startTime)) { if (scope != null) { string queueDisplayName = string.IsNullOrEmpty(queue) || !queue.StartsWith("amq.gen-") ? queue : "<generated>"; scope.Span.ResourceName = $"{Command} {queueDisplayName}"; if (tags != null && messageSize != null) { tags.MessageSize = messageSize; } if (exception != null) { scope.Span.SetException(exception); } } } return(new CallTargetReturn <TResult>(basicGetResult)); }
/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="queue">Name of the queue.</param> /// <param name="passive">The original passive setting</param> /// <param name="durable">The original durable setting</param> /// <param name="exclusive">The original exclusive settings</param> /// <param name="autoDelete">The original autoDelete setting</param> /// <param name="nowait">The original nowait setting</param> /// <param name="arguments">The original arguments setting</param> /// <returns>Calltarget state value</returns> public static CallTargetState OnMethodBegin <TTarget>(TTarget instance, string queue, bool passive, bool durable, bool exclusive, bool autoDelete, bool nowait, IDictionary <string, object> arguments) { return(new CallTargetState(RabbitMQIntegration.CreateScope(Tracer.Instance, out _, Command, SpanKinds.Client, queue: queue))); }
/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="queue">Name of the queue.</param> /// <param name="exchange">The original exchange argument.</param> /// <param name="routingKey">The original routingKey argument.</param> /// <param name="arguments">The original arguments setting</param> /// <returns>Calltarget state value</returns> internal static CallTargetState OnMethodBegin <TTarget>(TTarget instance, string queue, string exchange, string routingKey, IDictionary <string, object> arguments) { return(new CallTargetState(RabbitMQIntegration.CreateScope(Tracer.Instance, out _, Command, SpanKinds.Client, queue: queue, exchange: exchange, routingKey: routingKey))); }
/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="exchange">Name of the exchange.</param> /// <param name="type">Type of the exchange.</param> /// <param name="passive">The original passive setting</param> /// <param name="durable">The original durable setting</param> /// <param name="autoDelete">The original autoDelete setting</param> /// <param name="internal">The original internal setting</param> /// <param name="nowait">The original nowait setting</param> /// <param name="arguments">The original arguments setting</param> /// <returns>Calltarget state value</returns> internal static CallTargetState OnMethodBegin <TTarget>(TTarget instance, string exchange, string type, bool passive, bool durable, bool autoDelete, bool @internal, bool nowait, IDictionary <string, object> arguments) { return(new CallTargetState(RabbitMQIntegration.CreateScope(Tracer.Instance, out _, Command, SpanKinds.Client, exchange: exchange))); }