- Agent — attach
opentelemetry-javaagent.jarat startup. The agent auto-instruments popular logging frameworks (SLF4J, Logback, Log4j) and ships records over OTLP with zero code changes. - SDK — compile the OTEL SDK into your app and use
AutoConfiguredOpenTelemetrySdk. More control, but requires code.
otel-logs-v0_9).
Setup
Structured logging
With the agent, SLF4J MDC keys are forwarded automatically as log attributes — no code beyondMDC.put:
Framework recipe: Spring Boot
With the agent, Spring Boot needs no code changes — attach the agent viaJAVA_TOOL_OPTIONS and every Logger statement is shipped automatically:
MDC from a Spring filter:
Troubleshooting
- 401 / 403 — the Bearer token is missing, malformed, or the
%20separator is not URL-encoded. Re-checkOTEL_EXPORTER_OTLP_LOGS_HEADERS. - Agent not attaching — verify
JAVA_TOOL_OPTIONSis visible to the JVM (echo $JAVA_TOOL_OPTIONSin the same shell that runs Java). Some process managers strip it. - Nothing in Search (SDK path) — call
sdk.getSdkLoggerProvider().shutdown()beforemainexits so the batch processor flushes. - SDK throws
NoClassDefFoundError— the threeio.opentelemetryartifacts above are a minimal set. If you also use traces or metrics, add the matchingopentelemetry-exporter-otlppieces. - TLS errors against a self-signed endpoint — add the CA to the JVM truststore (
-Djavax.net.ssl.trustStore=...).
