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

org.zalando.nakadiproducer.flowid.TracerFlowIdComponent Maven / Gradle / Ivy

There is a newer version: 30.0.0-RC1
Show newest version
package org.zalando.nakadiproducer.flowid;

import org.zalando.tracer.Tracer;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TracerFlowIdComponent implements FlowIdComponent {
    
    private static final String X_FLOW_ID = "X-Flow-ID";
    
    private final Tracer tracer;
    
    public TracerFlowIdComponent(Tracer tracer) {
        this.tracer = tracer;
    }

    public String getXFlowIdKey() {
        return X_FLOW_ID;
    }

    @Override
    public String getXFlowIdValue() {
        if (tracer != null) {
            try {
                return tracer.get(X_FLOW_ID).getValue();
            } catch (IllegalArgumentException e) {
                log.warn("No trace was configured for the name {}. Returning null. " +
                        "To configure Tracer provide an application property: " +
                        "tracer.traces.X-Flow-ID=flow-id", X_FLOW_ID);
            } catch (IllegalStateException e) {
                log.warn("Unexpected Error while receiving the Trace Id {}. Returning null. " +
                    "Please check your tracer configuration: {}", X_FLOW_ID, e.getMessage());
            }
        } else {
            log.warn("No bean of class Tracer was found. Returning null.");
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy