/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <typeparam name="TTopicPartition">Type of the TopicPartition</typeparam> /// <typeparam name="TMessage">Type of the message</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="topicPartition">TopicPartition instance</param> /// <param name="message">Message instance</param> /// <param name="cancellationToken">CancellationToken instance</param> /// <returns>Calltarget state value</returns> public static CallTargetState OnMethodBegin <TTarget, TTopicPartition, TMessage>(TTarget instance, TTopicPartition topicPartition, TMessage message, CancellationToken cancellationToken) where TMessage : IMessage { var agent = Agent.Instance; var span = KafkaIntegration.CreateProducerSpan( agent, topicPartition.DuckCast <ITopicPartition>(), isTombstone: message.Value is null, finishOnClose: true); if (span is not null) { KafkaIntegration.TryInjectHeaders <TTopicPartition, TMessage>(agent, span, message); } return(new CallTargetState(span)); }
/// <summary> /// OnMethodBegin callback /// </summary> /// <typeparam name="TTarget">Type of the target</typeparam> /// <typeparam name="TTopicPartition">Type of the TopicPartition</typeparam> /// <typeparam name="TMessage">Type of the message</typeparam> /// <typeparam name="TDeliveryHandler">Type of the delivery handler action</typeparam> /// <param name="instance">Instance value, aka `this` of the instrumented method.</param> /// <param name="topicPartition">TopicPartition instance</param> /// <param name="message">Message instance</param> /// <param name="deliveryHandler">Delivery Handler instance</param> /// <returns>Calltarget state value</returns> public static CallTargetState OnMethodBegin <TTarget, TTopicPartition, TMessage, TDeliveryHandler>(TTarget instance, TTopicPartition topicPartition, TMessage message, TDeliveryHandler deliveryHandler) where TMessage : IMessage { var agent = Agent.Instance; // manually doing duck cast here so we have access to the _original_ TopicPartition type // as a generic parameter, for injecting headers var span = KafkaIntegration.CreateProducerSpan( agent, topicPartition.DuckCast <ITopicPartition>(), isTombstone: message.Value is null, finishOnClose: deliveryHandler is null); if (span is not null) { KafkaIntegration.TryInjectHeaders <TTopicPartition, TMessage>(agent, span, message); } return(new CallTargetState(span)); }