0

I have one legacy project which is using jetty,apache http client, log4j2. I want to implement distributed tracing and want to populate trace id and span id into the logs,since this is not a spring boot project I cannot use spring slueth which do all the heavy lifting and do auto intrumentation, I came across brave and brave-context-log4j, but I am not able to configure the brave with my project.

I am referring this https://github.com/openzipkin/brave/tree/master/context/log4j2 but my logs are not populating with trace id and span id, is there any way to automatically instrument with brave or any other lib where i don't have to touch much code.

Sys32
  • 1

1 Answers1

0

You can use the java agent to instrument your application.

The java agent supports log4j, including your use case:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" packages="io.opentelemetry.instrumentation.log4j.appender.v2_17">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout
          pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} trace_id: %X{trace_id} span_id: %X{span_id} trace_flags: %X{trace_flags} - %msg%n"/>
    </Console>
    <OpenTelemetry name="OpenTelemetryAppender"/>
  </Appenders>
  <Loggers>
    <Root>
      <AppenderRef ref="OpenTelemetryAppender" level="All"/>
      <AppenderRef ref="Console" level="All"/>
    </Root>
  </Loggers>
</Configuration>