Skip to Content

Java App Instrumentation

Follow the steps below to auto-instrument your Java service. When complete, your service will start emitting logs, metrics, and traces to Lakerunner.

Local Testing

  1. Get a Cardinal API key.

    Follow the steps in the Overview to mint an ingest API key.

  2. Download the OpenTelemetry Java auto-instrumentation agent:

    wget https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
  3. Export the following environment variables:

    export OTEL_SERVICE_NAME="your-service-name" export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=local" # local/dev/staging/prod export OTEL_METRICS_EXPORTER="otlp" export OTEL_LOGS_EXPORTER="otlp" export OTEL_TRACES_EXPORTER="otlp" export OTEL_EXPORTER_OTLP_ENDPOINT="https://otelhttp.intake.<your-region>.aws.cardinalhq.io" export OTEL_EXPORTER_OTLP_HEADERS="x-cardinalhq-api-key=<your-api-key>" export JAVA_TOOL_OPTIONS="-javaagent:path/to/opentelemetry-javaagent.jar"
  4. Run your application:

    java -jar <your-app.jar>
  5. Validate that Lakerunner is receiving data.

    Exercise the service by calling some API endpoints or causing some logs and metrics to be emitted. Wait a few minutes, then query for your service in the Cardinal dashboard.

Docker

Set the environment variables outlined above in your Docker container runtime configuration.

  • Update OTEL_RESOURCE_ATTRIBUTES to set deployment.environment.name for your environment.
  • If you run an OpenTelemetry Collector, set OTEL_EXPORTER_OTLP_ENDPOINT to your Collector’s OTLP receiver endpoint, and forward to Lakerunner from the Collector. See Already running an OpenTelemetry Collector?.

Kubernetes

Set the environment variables outlined above in your Deployment or StatefulSet manifest.

  • Update OTEL_RESOURCE_ATTRIBUTES to set deployment.environment.name for your environment.
  • If you run an OpenTelemetry Collector, set OTEL_EXPORTER_OTLP_ENDPOINT to your Collector’s OTLP receiver endpoint, and forward to Lakerunner from the Collector. See Already running an OpenTelemetry Collector?.

Reach out to support@cardinalhq.io for support or to ask questions not answered in our documentation.

Last updated on