> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tracelit.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Java [Logs]

> Official OpenTelemetry Java agent → Tracelit for Spring Boot and other JVM apps.

## 1. Environment

```bash theme={null}
OTEL_SERVICE_NAME=my-service
OTEL_RESOURCE_ATTRIBUTES=deployment.environment=production
OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.tracelit.app
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer <WORKSPACE_INGEST_KEY>
```

## 2. Download the agent

```bash theme={null}
mkdir -p .tracelit/otel
curl -sSL -o .tracelit/otel/opentelemetry-javaagent.jar \
  https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
```

## 3. Attach at JVM start

```bash theme={null}
JAVA_TOOL_OPTIONS="-javaagent:$PWD/.tracelit/otel/opentelemetry-javaagent.jar" <your-start-command>
```

## 4. Log libraries

The Java agent instruments common logging frameworks automatically. Keep your existing config.

<Tabs>
  <Tab title="Logback">
    Default for Spring Boot. The agent instruments Logback automatically — keep your existing `logback.xml`.

    ```java theme={null}
    log.info("order listed count={}", 3);
    log.error("payment failed", ex);
    ```
  </Tab>

  <Tab title="Log4j2">
    Common alternative. The agent instruments Log4j2 out of the box. Use your normal Logger API:

    ```java theme={null}
    log.info("order listed count={}", 3);
    log.error("payment failed", ex);
    ```
  </Tab>
</Tabs>

## 5. Verify

Produce **one INFO log** and **one ERROR log**, then confirm both in Tracelit Logs (or the onboarding live preview).
