Skip to content
Permalink
Browse files
wrapping json for zipkin tracing
  • Loading branch information
rmannibucau committed May 21, 2018
1 parent 23647ae commit ca655103e914658de9d67bb198cd6993be3478ed
Showing 2 changed files with 12 additions and 1 deletion.
@@ -30,4 +30,5 @@ NOTE: if you are using Microprofile Config it is used, otherwise it uses system
|geronimo.opentracing.id.generator|`counter` (to generate longs), `uuid` (to generate random uuids) or `hex` (to use the hexa representation of the uuid generator). Specifies which kind of trace and span id are in use.|hex
|geronimo.opentracing.span.converter.zipkin.active|Should spans converted to a zipkin representation. True until there is a standard opentracing format.|true
|geronimo.opentracing.span.converter.zipkin.logger.active|Should a logger named `org.apache.geronimo.opentracing.zipkin` log each span as a Zipkin JSON. This allows to use a logger implementation to push the spans to any backend (like log4j2 kafka appender). It uses JUL as a facade.|true
|geronimo.opentracing.span.converter.zipkin.logger.wrapAsList|Should zipkin JSON be logged wrapped in a list.|true
|===
@@ -22,20 +22,29 @@
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.json.bind.Jsonb;
import javax.json.bind.JsonbBuilder;

import org.apache.geronimo.microprofile.opentracing.config.GeronimoOpenTracingConfig;

// this allows to integrate with any backend using appenders.
@ApplicationScoped
public class ZipkinLogger {

private final Logger logger = Logger.getLogger(ZipkinLogger.class.getName());

@Inject
private GeronimoOpenTracingConfig config;

private Jsonb jsonb;

private boolean wrapAsList;

@PostConstruct
private void init() {
jsonb = JsonbBuilder.create();
wrapAsList = Boolean.parseBoolean(config.read("span.converter.zipkin.logger.wrapAsList", "true"));
}

@PreDestroy
@@ -48,6 +57,7 @@ private void destroy() {
}

public void onZipkinSpan(@Observes final ZipkinSpan zipkinSpan) {
logger.info(jsonb.toJson(zipkinSpan));
final String json = jsonb.toJson(zipkinSpan);
logger.info(wrapAsList ? '[' + json + ']' : json);
}
}

0 comments on commit ca65510

Please sign in to comment.