Collecting Application Logs Using OTEL Java Agent
You can directly send your application logs to SigNoz using Java Agent provided by OpenTelemetry. In this documentation, we will run a sample Java application with the OpenTelemetry Java agent to send logs to SigNoz.
For collecting logs, download the Java agent from here.
To send logs from a Java application, you will need to add the agent and set the appropriate environment variables.
OTEL_LOGS_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.<region>.signoz.cloud:443" \
OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key=<SIGNOZ_INGESTION_KEY>" \
OTEL_RESOURCE_ATTRIBUTES=service.name=<app_name> \
java -javaagent:/path/opentelemetry-javaagent.jar -jar <myapp>.jar
- Replace
<SIGNOZ_INGESTION_KEY>
with your SigNoz Cloud ingestion key - Set the
<region>
to match your SigNoz Cloud region
Settings for Appender Instrumentation
You can use appender settings by passing them as arguments in the -D<property>=<value>
format.
Example:
-Dotel.instrumentation.logback-appender.experimental-log-attributes=true
Logback Configuration
System Property | Type | Default | Description |
---|---|---|---|
otel.instrumentation.logback-appender.experimental-log-attributes | Boolean | false | Capture experimental log attributes like thread.name and thread.id . |
otel.instrumentation.logback-appender.experimental.capture-code-attributes | Boolean | false | Capture source code attributes. May impact performance. |
otel.instrumentation.logback-appender.experimental.capture-marker-attribute | Boolean | false | Capture Logback markers as attributes. |
otel.instrumentation.logback-appender.experimental.capture-key-value-pair-attributes | Boolean | false | Capture Logback key-value pairs as attributes. |
otel.instrumentation.logback-appender.experimental.capture-logger-context-attributes | Boolean | false | Capture Logback logger context properties as attributes. |
otel.instrumentation.logback-appender.experimental.capture-mdc-attributes | String | NA | Comma-separated list of MDC attributes to capture. Use * to capture all attributes. |
Log4j Configuration
System Property | Type | Default | Description |
---|---|---|---|
otel.instrumentation.log4j-appender.experimental-log-attributes | Boolean | false | Capture experimental log attributes like thread.name and thread.id . |
otel.instrumentation.log4j-appender.experimental.capture-map-message-attributes | Boolean | false | Capture MapMessage attributes. |
otel.instrumentation.log4j-appender.experimental.capture-marker-attribute | Boolean | false | Capture Log4j markers as attributes. |
otel.instrumentation.log4j-appender.experimental.capture-mdc-attributes | String | NA | Comma-separated list of context data attributes to capture. Use * to capture all attributes. |
Example: Collecting Logs with OTEL Java Agent
- Clone the Spring PetClinic Repository:
git clone https://github.com/SigNoz/spring-petclinic
- Build the application:
./mvnw package
- Run the application:
OTEL_LOGS_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.{region}.signoz.cloud:443" \
OTEL_EXPORTER_OTLP_HEADERS=signoz-access-token=<SIGNOZ_INGESTION_KEY> \
OTEL_RESOURCE_ATTRIBUTES=service.name=myapp \
java -javaagent:/path/opentelemetry-javaagent.jar -jar target/*.jar
To enable settings like experimental log attributes, pass additional arguments:
OTEL_LOGS_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.{region}.signoz.cloud:443" \
OTEL_EXPORTER_OTLP_HEADERS=signoz-access-token=<SIGNOZ_INGESTION_KEY> \
OTEL_RESOURCE_ATTRIBUTES=service.name=myapp \
java -javaagent:/path/opentelemetry-javaagent.jar \
-Dotel.instrumentation.logback-appender.experimental-log-attributes=true \
-jar target/*.jar
- Access the application at
http://localhost:8090
. - Use the application to generate logs, which will be visible on the SigNoz UI.
For troubleshooting, check the troubleshooting guide.