All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jashmore.sqs.brave.propogation.SendMessageRemoteSetter Maven / Gradle / Ivy

package com.jashmore.sqs.brave.propogation;

import static brave.Span.Kind.PRODUCER;

import brave.Span;
import brave.Tracing;
import brave.propagation.Propagation;
import brave.propagation.TraceContext;
import software.amazon.awssdk.services.sqs.model.MessageAttributeValue;

import java.util.Map;

/**
 * Used to set the tracing information into the message attributes of a SQS message.
 *
 * @see SendMessageRemoteGetter for extraction this information from the message attributes
 */
public class SendMessageRemoteSetter implements Propagation.RemoteSetter> {

    @Override
    public Span.Kind spanKind() {
        return PRODUCER;
    }

    @Override
    public void put(final Map carrier, final String fieldName, final String value) {
        carrier.put(fieldName, MessageAttributeValue.builder()
                .dataType("String")
                .stringValue(value)
                .build());
    }

    /**
     * Helper static function to create an injector for this {@link Propagation.RemoteGetter}.
     *
     * @param tracing trace instrumentation utilities
     * @return the injector
     */
    public static TraceContext.Injector> create(final Tracing tracing) {
        return tracing.propagation().injector(new SendMessageRemoteSetter());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy