Installation

Attach the official OpenTelemetry Java agent to your JVM and configure it with environment variables to send traces, metrics, and logs to Sophonz.

This installs the upstream OpenTelemetry Java agent — not a Sophonz package. The agent auto-instruments your JVM at startup; environment variables tell it where to send telemetry and how to identify itself.

Quick start

Enter the collector URL, project, app, version and app key below and pick a tab (Env vars · System properties) to generate the snippet from those values. Advanced options are behind the "Advanced options" toggle.

# shell — set before starting the JVM (.env file, Docker ENV, or systemd Environment=)
OTEL_SERVICE_NAME=next-sample
OTEL_EXPORTER_OTLP_ENDPOINT=https://in.sophonz.ai
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=authorization=sk_tYtJUa4WweXXedj6lxjSqoPW5O0DnbXz
OTEL_RESOURCE_ATTRIBUTES=service.key=sk_tYtJUa4WweXXedj6lxjSqoPW5O0DnbXz,service.namespace=sophonz,service.version=1.0.0,deployment.environment.name=production
OTEL_LOGS_EXPORTER=otlp

export JAVA_TOOL_OPTIONS="-javaagent:/path/to/opentelemetry-javaagent.jar"
java -jar your-app.jar

Prerequisites

  • Java 8 or later.
  • A service registered in the Sophonz console, and the sk_... API key issued for it.

Download the agent

curl -L -o opentelemetry-javaagent.jar \
  https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

Commit the jar to your image or artifact — there's nothing to install into your build, it's a standalone file you attach at JVM startup.

TIP — Get your API key

Log in to the Sophonz console, register the service, and copy the issued sk_... key. It carries your tenant identity — see service.key below.

Attach the agent

Add the jar with -javaagent, or set JAVA_TOOL_OPTIONS so you don't have to touch your existing start command:

export JAVA_TOOL_OPTIONS="-javaagent:/path/to/opentelemetry-javaagent.jar"
java -jar your-app.jar

In a Dockerfile:

COPY opentelemetry-javaagent.jar /app/opentelemetry-javaagent.jar
ENV JAVA_TOOL_OPTIONS="-javaagent:/app/opentelemetry-javaagent.jar"

Configure environment variables

OTEL_SERVICE_NAME=my-java-service
OTEL_EXPORTER_OTLP_ENDPOINT=https://in.sophonz.ai
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=authorization=sk_your_api_key
OTEL_RESOURCE_ATTRIBUTES=service.key=sk_your_api_key,service.namespace=my-project,deployment.environment.name=production
OTEL_LOGS_EXPORTER=otlp
VariableValueNotes
OTEL_SERVICE_NAMEyour service nameMust match the service name registered in the console — the portal joins telemetry to the registered service on (project, service.name). A mismatch means data is accepted but the service page stays empty.
OTEL_EXPORTER_OTLP_ENDPOINThttps://in.sophonz.aiBase OTLP endpoint. The agent derives /v1/traces, /v1/logs, and /v1/metrics from it.
OTEL_EXPORTER_OTLP_PROTOCOLhttp/protobufOTLP over HTTP. (The Java agent 2.x already defaults to http/protobuf; set it explicitly so behavior doesn't depend on the agent version.)
OTEL_EXPORTER_OTLP_HEADERSauthorization=sk_your_api_keySent as an HTTP header on every export request.
OTEL_RESOURCE_ATTRIBUTESservice.key=sk_your_api_key,service.namespace=...,deployment.environment.name=...service.key is the tenant identity the collector checks — required. service.namespace groups services into a project; deployment.environment.name labels the environment (production, staging, etc.).
OTEL_LOGS_EXPORTERotlpEnables OTLP log export alongside traces and metrics.

CAUTION — service.key is required

The collector runs in enforce mode: telemetry without a resolvable service.key resource attribute is dropped silently. Your app keeps running, no exception is thrown, and nothing shows up in Sophonz. Always set service.key via OTEL_RESOURCE_ATTRIBUTES, and send the same key as the authorization header via OTEL_EXPORTER_OTLP_HEADERS.

Framework notes

The agent instruments supported frameworks automatically at class-load time — nothing framework-specific to configure beyond the environment variables above.

  • Spring Boot — HTTP endpoints, RestTemplate/WebClient, JDBC, and scheduled tasks are traced out of the box. OTEL_SERVICE_NAME overrides spring.application.name for the reported service name.
  • Servlet containers (Tomcat, Jetty, Undertow) — incoming requests are traced without touching web.xml or filter chains.
  • JDBC drivers — query spans are created automatically; no DataSource wrapping required.

NOTE — System properties as an alternative

Every OTEL_* environment variable has a matching -Dotel.* JVM system property (for example -Dotel.service.name=my-java-service). Environment variables are usually easier to manage across containers and CI, so this guide uses those, but either form works.

Verify

Run your app with the environment variables set and watch stdout — the agent logs its own startup line:

OTEL_SERVICE_NAME=my-java-service \
OTEL_EXPORTER_OTLP_ENDPOINT=https://in.sophonz.ai \
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
OTEL_EXPORTER_OTLP_HEADERS=authorization=sk_your_api_key \
OTEL_RESOURCE_ATTRIBUTES=service.key=sk_your_api_key,service.namespace=my-project,deployment.environment.name=production \
java -javaagent:opentelemetry-javaagent.jar -jar your-app.jar
[otel.javaagent ...] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: 2.x.x

That line only confirms the agent attached — it says nothing about whether telemetry actually reached Sophonz, since an invalid or missing service.key fails silently (see the caution above). Generate some traffic, then check the Sophonz console for the service you registered.

NOTE — Debug logging

Set OTEL_JAVAAGENT_DEBUG=true to log every export attempt, including HTTP response codes from the collector — useful when traffic isn't showing up and you need to confirm requests are actually leaving the JVM.

TIP — This is just the beginning

Now ship your app. Sophonz surfaces the problems real users hit — so your app evolves on its own.