Skip to main content
Logwiz accepts OpenTelemetry logs over OTLP HTTP. Java apps have two common paths:
  • Agent — attach opentelemetry-javaagent.jar at 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.
Records land in the OTEL logs index pinned by your ingest token (default: otel-logs-v0_9).

Setup

1

Install

curl -LO https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
2

Set environment variables

export OTEL_SERVICE_NAME=my-java-service
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://<your-logwiz>/api/otlp/v1/logs
export OTEL_EXPORTER_OTLP_LOGS_HEADERS=Authorization=Bearer%20<your-ingest-token>
export JAVA_TOOL_OPTIONS="-javaagent:./opentelemetry-javaagent.jar"
The %20 after Bearer is required — OTEL expects URL-encoded header values.
3

Minimal working example

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class App {
    private static final Logger log = LoggerFactory.getLogger(App.class);

    public static void main(String[] args) {
        log.info("Hello from Java to Logwiz");
    }
}
4

Verify in Logwiz

Open Search, filter on service_name:my-java-service, and your record should appear within ~2 seconds.

Structured logging

With the agent, SLF4J MDC keys are forwarded automatically as log attributes — no code beyond MDC.put:
import org.slf4j.MDC;

MDC.put("user_id", "alice");
try {
    log.info("user signed up");
} finally {
    MDC.clear();
}
With the SDK, attach attributes to the log record builder directly:
import io.opentelemetry.api.common.Attributes;

logger.logRecordBuilder()
    .setSeverity(Severity.INFO)
    .setBody("user signed up")
    .setAllAttributes(Attributes.builder()
        .put("user_id", "alice")
        .put("plan", "pro")
        .build())
    .emit();

Framework recipe: Spring Boot

With the agent, Spring Boot needs no code changes — attach the agent via JAVA_TOOL_OPTIONS and every Logger statement is shipped automatically:
JAVA_TOOL_OPTIONS="-javaagent:./opentelemetry-javaagent.jar" \
OTEL_SERVICE_NAME=my-spring-app \
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://<your-logwiz>/api/otlp/v1/logs \
OTEL_EXPORTER_OTLP_LOGS_HEADERS=Authorization=Bearer%20<token> \
./gradlew bootRun
To enrich records with request metadata, use MDC from a Spring filter:
@Component
public class RequestIdFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws ServletException, IOException {
        MDC.put("request_id", UUID.randomUUID().toString());
        try {
            chain.doFilter(req, resp);
        } finally {
            MDC.clear();
        }
    }
}

Troubleshooting

  • 401 / 403 — the Bearer token is missing, malformed, or the %20 separator is not URL-encoded. Re-check OTEL_EXPORTER_OTLP_LOGS_HEADERS.
  • Agent not attaching — verify JAVA_TOOL_OPTIONS is visible to the JVM (echo $JAVA_TOOL_OPTIONS in the same shell that runs Java). Some process managers strip it.
  • Nothing in Search (SDK path) — call sdk.getSdkLoggerProvider().shutdown() before main exits so the batch processor flushes.
  • SDK throws NoClassDefFoundError — the three io.opentelemetry artifacts above are a minimal set. If you also use traces or metrics, add the matching opentelemetry-exporter-otlp pieces.
  • TLS errors against a self-signed endpoint — add the CA to the JVM truststore (-Djavax.net.ssl.trustStore=...).