
ca.bitcoco.jsk.operation.Operation Maven / Gradle / Ivy
package ca.bitcoco.jsk.operation;
import ca.bitcoco.jsk.operation.log.Logger;
import io.opentracing.Span;
import io.opentracing.Tracer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
public class Operation {
Logger logger;
Tracer tracer;
String serviceName;
String agentHost;
String operationName;
Span span;
String traceId;
public Operation(String serviceName, String agentHost) {
this.serviceName = serviceName;
this.agentHost = agentHost;
this.tracer = SpringOperationAutoConfiguration.getTracer(serviceName, agentHost);
}
public Operation start(String name) {
operationName = name;
span = tracer.buildSpan(operationName).start();
traceId = span.context().toTraceId();
return this;
}
public void finish() {
if (tracer != null) {
System.out.println(this.serviceName + " " + this.operationName + " " + "finish == " + traceId);
tracer.close();
}
}
public Logger logger(Class thisClass) {
if (this.logger == null) {
this.logger = new Logger(thisClass.getName());
}
this.logger.setOperationName(operationName);
if (this.traceId != null) {
this.logger.setTraceId(this.traceId);
}
this.logger.setServiceName(serviceName);
return this.logger;
}
public Logger logger(Class thisClass, String operationName) {
if (this.logger == null) {
this.logger = new Logger(thisClass.getName());
}
if (operationName != null) {
this.logger.setOperationName(operationName);
} else if (this.operationName != null) {
this.logger.setOperationName(this.operationName);
}
if (this.traceId != null) {
this.logger.setTraceId(this.traceId);
}
this.logger.setServiceName(serviceName);
return this.logger;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy