/// <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> internal static CallTargetState OnMethodBegin <TTarget, TTopicPartition, TMessage>(TTarget instance, TTopicPartition topicPartition, TMessage message, CancellationToken cancellationToken) where TMessage : IMessage { Scope scope = KafkaHelper.CreateProducerScope( Tracer.Instance, topicPartition.DuckCast <ITopicPartition>(), isTombstone: message.Value is null, finishOnClose: true); if (scope is not null) { KafkaHelper.TryInjectHeaders <TTopicPartition, TMessage>(scope.Span.Context, message); return(new CallTargetState(scope)); } return(CallTargetState.GetDefault()); }
/// <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> internal static CallTargetState OnMethodBegin <TTarget, TTopicPartition, TMessage, TDeliveryHandler>(TTarget instance, TTopicPartition topicPartition, TMessage message, TDeliveryHandler deliveryHandler) where TMessage : IMessage { // manually doing duck cast here so we have access to the _original_ TopicPartition type // as a generic parameter, for injecting headers Scope scope = KafkaHelper.CreateProducerScope( Tracer.Instance, topicPartition.DuckCast <ITopicPartition>(), isTombstone: message.Value is null, finishOnClose: deliveryHandler is null); if (scope is not null) { KafkaHelper.TryInjectHeaders <TTopicPartition, TMessage>(scope.Span.Context, message); return(new CallTargetState(scope)); } return(CallTargetState.GetDefault()); }