Skip to main content

Collecting Application Logs Using OTEL Java Agent

You can directly send your application logs to SigNoz using Java Agent provided by opentlemetry. In this blog we will run a sample java application and send the application logs to SigNoz.

For collecting logs we will have to download the java agent from here.

To sends logs from a Java application you will have to add the agent and add the environment variables for the agent

The command for it will look like

For Sending Logs To SigNoz Cloud

OTEL_LOGS_EXPORTER=otlp OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.{region}" OTEL_EXPORTER_OTLP_HEADERS=signoz-access-token=<SIGNOZ_INGESTION_KEY><app_name> java -javaagent:/path/opentelemetry-javaagent.jar -jar  <myapp>.jar

You will have to add <SIGNOZ_INGESTION_KEY> and depending on the choice of your region for SigNoz cloud, the otlp endpoint will vary according to this table.


For Sending Logs To SigNoz Hosted Locally

OTEL_LOGS_EXPORTER=otlp OTEL_EXPORTER_OTLP_ENDPOINT="http://<IP of SigNoz Backend>:4317"<app_name> java -javaagent:/path/opentelemetry-javaagent.jar -jar  <myapp>.jar

In the below example we will configure a java application to send logs to SigNoz.

How to Collect Application Logs Using OTEL Java Agent?

  • Clone this repository

  • Build the application using ./mvnw package

  • Now run the application

    For SigNoz Cloud

    OTEL_LOGS_EXPORTER=otlp OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.{region}" OTEL_EXPORTER_OTLP_HEADERS=signoz-access-token=<SIGNOZ_INGESTION_KEY> java -javaagent:/path/opentelemetry-javaagent.jar -jar target/*.jar

    You will have to replace the value of {region} according to region of your cloud account and also add <SIGNOZ_INGESTION_KEY>

    For SigNoz Hosted Locally

    OTEL_LOGS_EXPORTER=otlp OTEL_EXPORTER_OTLP_ENDPOINT="http://<host>:4317" java -javaagent:/path/opentelemetry-javaagent.jar -jar target/*.jar

    You will have to replace your the value of host as if SigNoz is running in the same host, for other configurations please check the troubleshooting guide.

  • Now if the application starts successfully the logs will be visible on SigNoz UI.