---
title: Java
metaTitle: "Java Distributed Tracing with OpenTelemetry - OpenObserve"
description: Instrument Java applications on Red Hat Enterprise Linux and Windows Server to send distributed traces to OpenObserve using the OpenTelemetry Java agent.
---
# OpenObserve Java Tracing Guide

Send distributed traces from Java applications on Red Hat Enterprise Linux and Windows Server to OpenObserve through the OpenTelemetry Collector. No code changes are needed.

> **How to use this guide.** Read Before you begin and fill in the table of values. Then follow **Part A** on Red Hat Enterprise Linux servers or **Part B** on Windows servers, one step at a time. Every value you must replace is shown in angle brackets, like `<SERVICE_NAME>`, and the steps that contain one are marked with ✏️. Everything else can be copied as it is. Each part ends with a check that your traces arrived in OpenObserve.

## Contents

1. [Before you begin](#before-you-begin)
2. [Part A: Red Hat Enterprise Linux](#part-a-red-hat-enterprise-linux)
    - [Step A1. Install and configure the OpenTelemetry Collector](#step-a1-install-and-configure-the-opentelemetry-collector)
    - [Step A2. Instrument the Java application](#step-a2-instrument-the-java-application)
    - [Step A3. Verify traces in OpenObserve](#step-a3-verify-traces-in-openobserve)
3. [Part B: Windows Server](#part-b-windows-server)
    - [Step B1. Install and configure the OpenTelemetry Collector](#step-b1-install-and-configure-the-opentelemetry-collector)
    - [Step B2. Instrument the Java application](#step-b2-instrument-the-java-application)
    - [Step B3. Verify traces in OpenObserve](#step-b3-verify-traces-in-openobserve)
4. [Troubleshooting](#troubleshooting)
5. [Tested versions](#tested-versions)

## Before you begin

This guide sends distributed traces from a Java application to OpenObserve. No code changes are needed: the OpenTelemetry Java agent instruments Spring, Servlet containers, JDBC, HTTP clients, Kafka and other common libraries automatically.

![Java trace data path: application, OpenTelemetry Collector, OpenObserve](./images/java-trace-data-path.svg)

The application sends traces to an OpenTelemetry Collector on the same server. The Collector batches them, retries on network errors, and forwards them to OpenObserve. Only the Collector holds your OpenObserve credentials.

### Which part to follow

| Your server | Follow | Steps |
| --- | --- | --- |
| Red Hat Enterprise Linux 8 or 9 | **Part A** | A1 Install the Collector → A2 Instrument the app → A3 Verify |
| Windows Server 2016 or later | **Part B** | B1 Install the Collector → B2 Instrument the app → B3 Verify |

Do all steps in order on **each** application server. Allow about 20 minutes per server.

### Values you need to provide

Throughout this guide, **every value in angle brackets, like `<SERVICE_NAME>`, is a value you must replace with your own.** Replace the angle brackets too. Copy everything else exactly as shown. Fill in this table before you start:

| Placeholder | What to enter | Where to find it | Example |
| --- | --- | --- | --- |
| `<OPENOBSERVE_URL>` | Base URL of your OpenObserve, with no trailing `/` | OpenObserve Cloud: `https://api.openobserve.ai`. Self-hosted: the URL you use to open OpenObserve | `https://o2.example.com` |
| `<ORG_ID>` | Your OpenObserve organization ID | OpenObserve → **Data sources**. It's part of the endpoint shown there | `default` |
| `<BASE64_CREDENTIALS>` | Base64 of `email:password-or-token` for the ingestion user | OpenObserve → **Data sources** shows a ready-made `Authorization: Basic ...` value; use the part after `Basic `. To build it yourself, see the note below | `dXNlcjpwYXNz` |
| `<TRACE_STREAM>` | Traces stream to write to | Your choice. It is created on first use | `default` |
| `<SERVICE_NAME>` | Name this application will have in OpenObserve | Your choice. Lowercase, unique per application | `checkout-api` |
| `<ENVIRONMENT>` | Environment label | Your choice | `production` |
| `<SERVICE_VERSION>` | Application version label | Your release version | `2.3.1` |
| `<APP_JAR>` | Full path to the application's JAR | Your server | RHEL: `/opt/checkout/checkout.jar` · Windows: `C:\apps\checkout\checkout.jar` |
| `<APP_UNIT>` | systemd service name of the application (RHEL) | `systemctl list-units --type=service` | `checkout` |
| `<WINDOWS_SERVICE>` | Windows service name of the application (Windows) | `Get-Service` | `CheckoutApi` |
| `<APP_URL>` | A URL of the application for a test request | Your application | `http://localhost:8080/health` |
| `<O2_USER_EMAIL>` / `<O2_PASSWORD_OR_TOKEN>` | An OpenObserve login, used only for the optional API check in step A3/B3 | OpenObserve | `ingest@example.com` |

To build `<BASE64_CREDENTIALS>` yourself:

- RHEL: `echo -n '<O2_USER_EMAIL>:<O2_PASSWORD_OR_TOKEN>' | base64`
- Windows PowerShell: `[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('<O2_USER_EMAIL>:<O2_PASSWORD_OR_TOKEN>'))`

Use a dedicated OpenObserve user or service account for ingestion, not a personal administrator login.

### Prerequisites

- Administrator rights on the server: `sudo` on RHEL, an elevated PowerShell on Windows.
- Java 8 or later on the application server.
- Outbound HTTPS (port 443) from the server to `<OPENOBSERVE_URL>`. Self-hosted OpenObserve may use port 5080 instead.
- Internet access to `github.com` to download the Collector and the agent. Without it, download the files on another machine and copy them over.
- A short restart window for the application. The agent loads at JVM startup.

### Agent or eBPF?

On Red Hat Enterprise Linux, you can also trace Java applications with **eBPF** instead of the Java agent. One OBI service per server traces every application on it from the kernel, with no change to the applications. See the companion **OpenObserve eBPF Tracing Guide**.

| Use | When |
| --- | --- |
| **Java agent (this guide)** | You need framework detail (Spring controllers, JDBC statements, exceptions, custom spans), the server runs Windows, or you can't run a root-level service |
| **eBPF** | You want broad coverage quickly, can't change how applications start, or also run services with no agent (Go, Rust, C/C++, web servers) |

In testing, eBPF traced the Java sample application with complete linking: incoming request, outgoing call and downstream request in one trace. Both methods can run on the same server. OBI automatically skips applications that use the agent.

## Part A: Red Hat Enterprise Linux

Run every command as a user with `sudo` rights on the application server. Commands without placeholders can be copied as they are.

### Step A1. Install and configure the OpenTelemetry Collector

**A1.1 Download the Collector package and verify its checksum.** On ARM servers, set `ARCH=arm64`.

```bash
OTEL_VERSION=0.166.0
ARCH=amd64
BASE=https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${OTEL_VERSION}
cd /tmp
curl -LO ${BASE}/otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpm
curl -LO ${BASE}/otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpm.sha256
echo "$(cat otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpm.sha256)  otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpm" | sha256sum -c -
```

Expected output: `otelcol-contrib_0.166.0_linux_amd64.rpm: OK`

**A1.2 Install the package.** This creates the `otelcol-contrib` systemd service and the `/etc/otelcol-contrib/` folder.

```bash
sudo dnf install -y ./otelcol-contrib_${OTEL_VERSION}_linux_${ARCH}.rpm
```

**A1.3 Write the Collector configuration.** This file contains no values of yours; they come from the next step. Copy the whole block as it is.

```bash
sudo cp /etc/otelcol-contrib/config.yaml /etc/otelcol-contrib/config.yaml.orig
sudo tee /etc/otelcol-contrib/config.yaml >/dev/null <<'EOF'
extensions:
  health_check:
    endpoint: 127.0.0.1:13133

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 127.0.0.1:4317
      http:
        endpoint: 127.0.0.1:4318

processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 80
    spike_limit_percentage: 25
  resource_detection:
    detectors: [env, system]
    system:
      hostname_sources: [os]
  batch:
    send_batch_size: 1024
    timeout: 5s

exporters:
  otlp_http/openobserve:
    endpoint: ${env:O2_OTLP_ENDPOINT}
    headers:
      Authorization: "Basic ${env:O2_AUTH_TOKEN}"
      stream-name: ${env:O2_TRACE_STREAM}
    compression: gzip
    retry_on_failure:
      enabled: true
    sending_queue:
      enabled: true
      queue_size: 5000

service:
  extensions: [health_check]
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, resource_detection, batch]
      exporters: [otlp_http/openobserve]
EOF
```

The Collector listens only on `127.0.0.1`, so only applications on this server can send to it. To accept traces from other servers too, change the two receiver endpoints to `0.0.0.0:4317` and `0.0.0.0:4318`, and open those ports in the firewall (A1.6).

**A1.4 Enter your OpenObserve values.** ✏️ Replace the three placeholders, then run:

```bash
sudo tee -a /etc/otelcol-contrib/otelcol-contrib.conf >/dev/null <<'EOF'
O2_OTLP_ENDPOINT=<OPENOBSERVE_URL>/api/<ORG_ID>
O2_AUTH_TOKEN=<BASE64_CREDENTIALS>
O2_TRACE_STREAM=<TRACE_STREAM>
EOF
sudo chown root:otelcol-contrib /etc/otelcol-contrib/otelcol-contrib.conf
sudo chmod 640 /etc/otelcol-contrib/otelcol-contrib.conf
```

Filled in, the three lines look like this:

```bash
O2_OTLP_ENDPOINT=https://o2.example.com/api/default
O2_AUTH_TOKEN=dXNlcjpwYXNz
O2_TRACE_STREAM=default
```

Don't add `/v1/traces` to the endpoint; the Collector adds it. Don't add `Basic ` to the token; the configuration adds it.

**A1.5 Check the configuration, then start the Collector:**

```bash
sudo bash -c 'set -a; . /etc/otelcol-contrib/otelcol-contrib.conf; otelcol-contrib validate --config=/etc/otelcol-contrib/config.yaml' && echo CONFIG OK
sudo systemctl enable otelcol-contrib
sudo systemctl restart otelcol-contrib
sudo systemctl status otelcol-contrib --no-pager
curl -s http://127.0.0.1:13133
```

Expected: `CONFIG OK`, status `active (running)`, and `{"status":"Server available",...}`.

**A1.6 (Only if other servers send to this Collector) Open the firewall:**

```bash
sudo firewall-cmd --permanent --add-port=4317/tcp --add-port=4318/tcp
sudo firewall-cmd --reload
```

**A1.7 Send a test trace from the Collector to OpenObserve.** This confirms the connection and credentials before you touch the application.

```bash
NOW=$(date +%s); TID=$(openssl rand -hex 16); SID=$(openssl rand -hex 8)
curl -s -w ' HTTP %{http_code}\n' -X POST http://127.0.0.1:4318/v1/traces -H 'Content-Type: application/json' -d '{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"collector-smoke-test"}}]},"scopeSpans":[{"spans":[{"traceId":"'$TID'","spanId":"'$SID'","name":"smoke-test","kind":1,"startTimeUnixNano":"'${NOW}000000000'","endTimeUnixNano":"'${NOW}500000000'"}]}]}]}'
```

Expected: `{"partialSuccess":{}} HTTP 200`. Within about 10 seconds, a service named `collector-smoke-test` appears under **Traces** in OpenObserve. If it doesn't, check `sudo journalctl -u otelcol-contrib -n 50 --no-pager` and see Troubleshooting.

### Step A2. Instrument the Java application

**A2.1 Make sure Java is installed** (Java 8 or later): `java -version`. If it is missing, install it with `sudo dnf install -y java-17-openjdk-headless`.

**A2.2 Download the OpenTelemetry Java agent:**

```bash
sudo mkdir -p /opt/opentelemetry
sudo curl -sSLo /opt/opentelemetry/opentelemetry-javaagent.jar \
  https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.34.0/opentelemetry-javaagent.jar
sudo chmod 644 /opt/opentelemetry/opentelemetry-javaagent.jar
```

**A2.3 Create the tracing settings file for the application.** ✏️ Replace `<APP_UNIT>`, `<SERVICE_NAME>`, `<ENVIRONMENT>` and `<SERVICE_VERSION>`:

```bash
sudo tee /etc/sysconfig/<APP_UNIT>-otel >/dev/null <<'EOF'
JAVA_TOOL_OPTIONS=-javaagent:/opt/opentelemetry/opentelemetry-javaagent.jar
OTEL_SERVICE_NAME=<SERVICE_NAME>
OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=<ENVIRONMENT>,service.version=<SERVICE_VERSION>
OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=none
OTEL_LOGS_EXPORTER=none
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318
EOF
```

`JAVA_TOOL_OPTIONS` makes the JVM load the agent, so you don't need to change the application's start command.

**A2.4 Attach the settings to the application's service.** ✏️ Replace `<APP_UNIT>` in both places:

```bash
sudo mkdir -p /etc/systemd/system/<APP_UNIT>.service.d
sudo tee /etc/systemd/system/<APP_UNIT>.service.d/otel.conf >/dev/null <<'EOF'
[Service]
EnvironmentFile=/etc/sysconfig/<APP_UNIT>-otel
EOF
```

If the application doesn't run as a systemd service, use the matching row instead:

| How the app runs | What to do |
| --- | --- |
| Apache Tomcat | Add the lines from A2.3, each prefixed with `export `, to `$CATALINA_BASE/bin/setenv.sh` (create the file if it doesn't exist) |
| JBoss EAP / WildFly | Add the lines from A2.3, each prefixed with `export `, to `bin/standalone.conf` |
| Started by a script | Export the lines from A2.3 in that script before the `java` command |

**A2.5 Restart the application and confirm the agent loaded.** ✏️ Replace `<APP_UNIT>` and `<APP_URL>`:

```bash
sudo systemctl daemon-reload
sudo systemctl restart <APP_UNIT>
sudo journalctl -u <APP_UNIT> -n 100 --no-pager | grep -E 'JAVA_TOOL_OPTIONS|otel.javaagent'
curl -s <APP_URL> > /dev/null
```

Expected log lines:

```
Picked up JAVA_TOOL_OPTIONS: -javaagent:/opt/opentelemetry/opentelemetry-javaagent.jar
[otel.javaagent ...] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 2.34.0
```

### Step A3. Verify traces in OpenObserve

1. Send a few requests to the application, or wait for normal traffic.
2. In OpenObserve, open **Traces**, select the `<TRACE_STREAM>` stream and the **Last 15 minutes** time range.
3. Filter on `service_name = '<SERVICE_NAME>'`. Your requests appear within about 10 seconds.
4. Open a trace. It shows the incoming request (for example `GET /orders`) with child spans for database queries and outgoing HTTP calls. Calls to other instrumented services appear in the **same** trace.

Optional check from the command line. ✏️ Replace the placeholders:

```bash
END=$(($(date +%s)*1000000)); START=$((END-3600*1000000))
cat > /tmp/q.json <<EOF
{"query":{"sql":"SELECT service_name, count(*) AS spans FROM \"<TRACE_STREAM>\" GROUP BY service_name","start_time":$START,"end_time":$END}}
EOF
curl -s -u '<O2_USER_EMAIL>:<O2_PASSWORD_OR_TOKEN>' -H 'Content-Type: application/json' \
  "<OPENOBSERVE_URL>/api/<ORG_ID>/_search?type=traces" -d @/tmp/q.json
```

Expected: a `hits` list that includes `<SERVICE_NAME>` with a span count above 0.

Repeat Part A on every RHEL application server. Use a different `<SERVICE_NAME>` for each application, but the same name for every server that runs the same application.

## Part B: Windows Server

Run every command in **PowerShell as Administrator** on the application server. Commands without placeholders can be copied as they are.

### Step B1. Install and configure the OpenTelemetry Collector

**B1.1 Download the Collector installer and verify its checksum:**

```powershell
$v = '0.166.0'
$base = "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v$v"
$msi = "otelcol-contrib_${v}_windows_x64.msi"
New-Item -ItemType Directory -Force C:\temp | Out-Null; Set-Location C:\temp
Invoke-WebRequest "$base/$msi" -OutFile $msi
Invoke-WebRequest "$base/$msi.sha256" -OutFile "$msi.sha256"
$expected = (Get-Content "$msi.sha256" -Raw).Trim().Split(' ')[0]
if ((Get-FileHash $msi -Algorithm SHA256).Hash -ne $expected.ToUpper()) { throw 'Checksum mismatch - do not install' } else { 'Checksum OK' }
```

**B1.2 Install the Collector.** This creates the Windows service `otelcol-contrib` (automatic start) and the folder `C:\Program Files\OpenTelemetry Collector\`.

```powershell
Start-Process msiexec.exe -Wait -ArgumentList "/i `"C:\temp\$msi`" /qn /l*v C:\temp\otelcol-install.log"
Get-Service otelcol-contrib
```

**B1.3 Write the Collector configuration.** This file contains no values of yours; they come from the next step. Copy the whole block as it is.

```powershell
$dir = 'C:\Program Files\OpenTelemetry Collector'
Copy-Item "$dir\config.yaml" "$dir\config.yaml.orig" -Force
@'
extensions:
  health_check:
    endpoint: 127.0.0.1:13133

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 127.0.0.1:4317
      http:
        endpoint: 127.0.0.1:4318

processors:
  memory_limiter:
    check_interval: 1s
    limit_percentage: 80
    spike_limit_percentage: 25
  resource_detection:
    detectors: [env, system]
    system:
      hostname_sources: [os]
  batch:
    send_batch_size: 1024
    timeout: 5s

exporters:
  otlp_http/openobserve:
    endpoint: ${env:O2_OTLP_ENDPOINT}
    headers:
      Authorization: "Basic ${env:O2_AUTH_TOKEN}"
      stream-name: ${env:O2_TRACE_STREAM}
    compression: gzip
    retry_on_failure:
      enabled: true
    sending_queue:
      enabled: true
      queue_size: 5000

service:
  extensions: [health_check]
  pipelines:
    traces:
      receivers: [otlp]
      processors: [memory_limiter, resource_detection, batch]
      exporters: [otlp_http/openobserve]
'@ | Set-Content -Path "$dir\config.yaml" -Encoding ascii
```

To accept traces from other servers too, change the two receiver endpoints to `0.0.0.0:4317` and `0.0.0.0:4318`, and open the firewall (B1.6).

**B1.4 Enter your OpenObserve values.** ✏️ Replace the three placeholders, then run. The values are stored on the Collector service only; other programs can't see them.

```powershell
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\otelcol-contrib' -Name Environment -Type MultiString -Value @(
  'O2_OTLP_ENDPOINT=<OPENOBSERVE_URL>/api/<ORG_ID>',
  'O2_AUTH_TOKEN=<BASE64_CREDENTIALS>',
  'O2_TRACE_STREAM=<TRACE_STREAM>'
)
```

Filled in, the first line looks like `'O2_OTLP_ENDPOINT=https://o2.example.com/api/default',`. Don't add `/v1/traces` or `Basic `.

**B1.5 Check the configuration, then restart the Collector.** ✏️ Use the same three values as in B1.4:

```powershell
$env:O2_OTLP_ENDPOINT = '<OPENOBSERVE_URL>/api/<ORG_ID>'; $env:O2_AUTH_TOKEN = '<BASE64_CREDENTIALS>'; $env:O2_TRACE_STREAM = '<TRACE_STREAM>'
& 'C:\Program Files\OpenTelemetry Collector\otelcol-contrib.exe' validate --config 'C:\Program Files\OpenTelemetry Collector\config.yaml'; if ($LASTEXITCODE -eq 0) { 'CONFIG OK' }
Restart-Service otelcol-contrib
Get-Service otelcol-contrib
(Invoke-WebRequest http://127.0.0.1:13133 -UseBasicParsing).Content
```

Expected: `CONFIG OK`, status `Running`, and `{"status":"Server available",...}`.

**B1.6 (Only if other servers send to this Collector) Open the firewall:**

```powershell
New-NetFirewallRule -DisplayName 'OpenTelemetry Collector OTLP' -Direction Inbound -Protocol TCP -LocalPort 4317,4318 -Action Allow
```

**B1.7 Send a test trace from the Collector to OpenObserve:**

```powershell
$now = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
$tid = -join ((1..32) | % { '{0:x}' -f (Get-Random -Max 16) }); $sid = -join ((1..16) | % { '{0:x}' -f (Get-Random -Max 16) })
$body = '{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"collector-smoke-test"}}]},"scopeSpans":[{"spans":[{"traceId":"' + $tid + '","spanId":"' + $sid + '","name":"smoke-test","kind":1,"startTimeUnixNano":"' + ($now*1000000) + '","endTimeUnixNano":"' + (($now+500)*1000000) + '"}]}]}]}'
$r = Invoke-WebRequest -Uri http://127.0.0.1:4318/v1/traces -Method Post -ContentType 'application/json' -Body $body -UseBasicParsing
"HTTP $($r.StatusCode) $($r.Content)"
```

Expected: `HTTP 200 {"partialSuccess":{}}`. Within about 10 seconds, the service `collector-smoke-test` appears under **Traces** in OpenObserve. Collector messages are in **Event Viewer → Windows Logs → Application**; filter on source `otelcol-contrib`.

### Step B2. Instrument the Java application

**B2.1 Make sure Java is installed** (Java 8 or later): `java -version`.

**B2.2 Download the OpenTelemetry Java agent:**

```powershell
New-Item -ItemType Directory -Force C:\opentelemetry | Out-Null
Invoke-WebRequest 'https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.34.0/opentelemetry-javaagent.jar' -OutFile C:\opentelemetry\opentelemetry-javaagent.jar
```

**B2.3 Add the tracing settings to the application's Windows service.** ✏️ Replace `<WINDOWS_SERVICE>`, `<SERVICE_NAME>`, `<ENVIRONMENT>` and `<SERVICE_VERSION>`. Existing service settings are kept.

```powershell
$svc = '<WINDOWS_SERVICE>'
$key = "HKLM:\SYSTEM\CurrentControlSet\Services\$svc"
$current = @((Get-ItemProperty $key -Name Environment -ErrorAction SilentlyContinue).Environment | Where-Object { $_ })
$otel = @(
  'JAVA_TOOL_OPTIONS=-javaagent:C:\opentelemetry\opentelemetry-javaagent.jar',
  'OTEL_SERVICE_NAME=<SERVICE_NAME>',
  'OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=<ENVIRONMENT>,service.version=<SERVICE_VERSION>',
  'OTEL_TRACES_EXPORTER=otlp',
  'OTEL_METRICS_EXPORTER=none',
  'OTEL_LOGS_EXPORTER=none',
  'OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf',
  'OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318'
)
Set-ItemProperty $key -Name Environment -Type MultiString -Value ($current + $otel)
(Get-ItemProperty $key).Environment
```

Set these values on the application's service only. Don't set `JAVA_TOOL_OPTIONS` as a machine-wide variable: every Java program on the server would load the agent.

If the application doesn't run as a plain Windows service, use the matching row instead:

| How the app runs | What to do |
| --- | --- |
| Apache Tomcat service | Open **Tomcat Monitor → Configure → Java**, add `-javaagent:C:\opentelemetry\opentelemetry-javaagent.jar` as a new line under **Java Options**, and add the `OTEL_*` values from B2.3 the same way as `-Dotel.service.name=<SERVICE_NAME>`, `-Dotel.metrics.exporter=none` and so on, then restart Tomcat |
| Started from a `.bat` / `.cmd` script | Add `set NAME=value` lines for each value from B2.3 before the `java` command |
| Started from a console for testing | Set them in the PowerShell session, then start Java (see below) |

For a quick test from a console. ✏️ Replace the placeholders:

```powershell
$env:OTEL_SERVICE_NAME = '<SERVICE_NAME>'
$env:OTEL_RESOURCE_ATTRIBUTES = 'deployment.environment.name=<ENVIRONMENT>,service.version=<SERVICE_VERSION>'
$env:OTEL_TRACES_EXPORTER = 'otlp'; $env:OTEL_METRICS_EXPORTER = 'none'; $env:OTEL_LOGS_EXPORTER = 'none'
$env:OTEL_EXPORTER_OTLP_PROTOCOL = 'http/protobuf'; $env:OTEL_EXPORTER_OTLP_ENDPOINT = 'http://127.0.0.1:4318'
java -javaagent:C:\opentelemetry\opentelemetry-javaagent.jar -jar '<APP_JAR>'
```

**B2.4 Restart the application and send a request.** ✏️ Replace `<WINDOWS_SERVICE>` and `<APP_URL>`:

```powershell
Restart-Service '<WINDOWS_SERVICE>'
Invoke-WebRequest '<APP_URL>' -UseBasicParsing | Out-Null
```

The application's console or log file shows `Picked up JAVA_TOOL_OPTIONS: -javaagent:...` and `opentelemetry-javaagent - version: 2.34.0` at startup.

### Step B3. Verify traces in OpenObserve

1. Send a few requests to the application, or wait for normal traffic.
2. In OpenObserve, open **Traces**, select the `<TRACE_STREAM>` stream and the **Last 15 minutes** time range.
3. Filter on `service_name = '<SERVICE_NAME>'`. Your requests appear within about 10 seconds.
4. Open a trace. It shows the incoming request with child spans for database queries and outgoing HTTP calls.

Optional check from PowerShell. ✏️ Replace the placeholders:

```powershell
$end = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() * 1000; $start = $end - 3600000000
$body = @{ query = @{ sql = 'SELECT service_name, count(*) AS spans FROM "<TRACE_STREAM>" GROUP BY service_name'; start_time = $start; end_time = $end } } | ConvertTo-Json
$auth = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('<O2_USER_EMAIL>:<O2_PASSWORD_OR_TOKEN>'))
(Invoke-RestMethod -Method Post -Uri '<OPENOBSERVE_URL>/api/<ORG_ID>/_search?type=traces' -Headers @{ Authorization = "Basic $auth" } -ContentType 'application/json' -Body $body).hits
```

Expected: a row for `<SERVICE_NAME>` with a span count above 0.

Repeat Part B on every Windows application server.

## Troubleshooting

Start with the Collector test trace (A1.7 / B1.7). If `collector-smoke-test` reaches OpenObserve, the connection to OpenObserve is fine, and the problem is between the application and the Collector. If it doesn't arrive, fix the Collector first.

Where to look:

- **Collector log.** RHEL: `sudo journalctl -u otelcol-contrib -n 100 --no-pager`. Windows: Event Viewer → Windows Logs → Application, source `otelcol-contrib`.
- **Application log.** The agent writes its lines, prefixed `[otel.javaagent`, to the application's standard output.

| Symptom | Cause | Fix |
| --- | --- | --- |
| Collector log shows `401` or `403` | Wrong `<BASE64_CREDENTIALS>`, or the user has no access to `<ORG_ID>` | Rebuild the Base64 value from `email:password-or-token` and check the org ID. Restart the Collector |
| Collector log shows `404` | Wrong endpoint path | `O2_OTLP_ENDPOINT` must be `<OPENOBSERVE_URL>/api/<ORG_ID>`, without `/v1/traces` |
| Collector log shows `connection refused`, a timeout, or a TLS error | No network route or a proxy in between | Test with `curl -I <OPENOBSERVE_URL>`. If you need a proxy, add `HTTPS_PROXY=http://<proxy-host>:<port>` next to the other `O2_*` values |
| `validate` reports `at least one endpoint must be specified` | The `O2_*` values were not loaded in the shell where you ran it | Run the command exactly as in A1.5 / B1.5 |
| No `Picked up JAVA_TOOL_OPTIONS` line at startup | The settings file isn't attached to the service that actually starts the app | RHEL: `systemctl cat <APP_UNIT>` must show `otel.conf`. Windows: check the service's `Environment` value (B2.3) |
| Agent loaded, but no traces | Wrong `OTEL_EXPORTER_OTLP_ENDPOINT`, or the Collector isn't running | It must be `http://127.0.0.1:4318` with `OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf`. Check that the Collector service is running |
| Agent logs errors exporting metrics or logs | `OTEL_METRICS_EXPORTER` / `OTEL_LOGS_EXPORTER` missing | Set both to `none`; this setup collects traces only |
| Calls between services show as separate traces | A proxy or API gateway removes the `traceparent` header | Configure it to forward the `traceparent` and `tracestate` headers |
| Too much trace volume | Every request is traced | Add `OTEL_TRACES_SAMPLER=parentbased_traceidratio` and `OTEL_TRACES_SAMPLER_ARG=0.1` (10%) to the application settings |

For detailed agent output while troubleshooting, add `-Dotel.javaagent.debug=true` to `JAVA_TOOL_OPTIONS`. It is very verbose, so remove it afterwards.

To remove tracing, delete the settings: on RHEL, the files from A2.3 and A2.4; on Windows, the `OTEL_*` and `JAVA_TOOL_OPTIONS` entries from B2.3. Then restart the application.

## Tested versions

This procedure was tested end to end on Red Hat Enterprise Linux 9.9 and Windows Server 2022 with the versions below. Other versions usually work. Before upgrading a component, check its release notes for removed settings.

| Component | Version |
| --- | --- |
| OpenTelemetry Collector Contrib | 0.166.0 |
| OpenTelemetry Java agent | 2.34.0 |
| Java | OpenJDK 17.0.21 (RHEL), Eclipse Temurin 17.0.21 (Windows) |
| OpenObserve | v1.2.0 |

The agent supports Java 8 and later. For the full list of auto-instrumented libraries and frameworks, see [Supported libraries](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/supported-libraries.md).
