SigNoz Cloud - This page is relevant for SigNoz Cloud editions.
Self-Host - This page is relevant for self-hosted SigNoz editions.

Tomcat OpenTelemetry Instrumentation

This guide shows how to instrument your Apache Tomcat application server with OpenTelemetry and send traces to SigNoz. Tomcat uses setenv.sh (Linux/Mac) or setenv.bat (Windows) to configure JVM options, making it straightforward to attach the OpenTelemetry Java agent.

Prerequisites

  • Java 8 or higher
  • Apache Tomcat installed and running
  • A SigNoz Cloud account or self-hosted SigNoz instance

Send traces to SigNoz

Step 1. Download the OpenTelemetry Java agent to your Tomcat directory

wget -P /opt/tomcat/lib/ https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar

Replace /opt/tomcat with your actual $CATALINA_HOME path if different.

Step 2. Create setenv.sh in Tomcat's bin folder

Create a file at $CATALINA_HOME/bin/setenv.sh with the following contents:

$CATALINA_HOME/bin/setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/opt/tomcat/lib/opentelemetry-javaagent.jar"
export OTEL_RESOURCE_ATTRIBUTES="service.name=<service-name>"
export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.<region>.signoz.cloud:443"
export OTEL_EXPORTER_OTLP_HEADERS="signoz-ingestion-key=<your-ingestion-key>"

Make the script executable:

chmod +x $CATALINA_HOME/bin/setenv.sh

Replace the following:

  • <region>: Your SigNoz Cloud region (us, eu, or in). See endpoints.
  • <your-ingestion-key>: Your SigNoz ingestion key.
  • <service-name>: A descriptive name for your service (e.g., tomcat-app).

Step 3. Restart Tomcat

$CATALINA_HOME/bin/shutdown.sh
$CATALINA_HOME/bin/startup.sh

Or if using systemd:

sudo systemctl restart tomcat

Validate

With your Tomcat application running, verify traces are being sent to SigNoz:

  1. Make a few requests to your deployed web applications.
  2. In SigNoz, open the Services tab and click Refresh. Your service should appear.
  3. Go to the Traces tab to see your application's traces.

Troubleshooting

Traces not showing up in SigNoz?

Check that setenv.sh/setenv.bat is being loaded:

Add a debug line to your setenv script:

echo "setenv.sh is being loaded" >> /tmp/tomcat-debug.log

Then restart Tomcat and check if the log file was created.

Verify the agent is attached:

Check your Tomcat logs (catalina.out) for OpenTelemetry startup messages:

[otel.javaagent] opentelemetry-javaagent - version: X.X.X

Enable debug logging:

Add to your setenv.sh:

export OTEL_LOG_LEVEL=debug

Look for span output in Tomcat's logs. If spans appear locally but not in SigNoz, check your endpoint URL and ingestion key.

Test connectivity:

curl -v https://ingest.<region>.signoz.cloud:443/v1/traces

Agent not attaching?

Check file permissions:

ls -la /opt/tomcat/lib/opentelemetry-javaagent.jar

The Tomcat user must have read access to the agent JAR.

Verify CATALINA_HOME:

echo $CATALINA_HOME

Make sure your setenv.sh is in the correct bin directory.

setenv.sh not found or not executed?

On some Linux distributions, Tomcat may be configured differently. Check:

  • The file is named exactly setenv.sh (case-sensitive)
  • The file is in $CATALINA_HOME/bin/ or $CATALINA_BASE/bin/
  • The file has execute permissions: chmod +x setenv.sh

Configuring the agent (Optional)

What can you configure?

The Java agent auto-instruments most libraries out of the box. Configuration lets you fine-tune what gets captured and how traces are exported.

Why configure?

  • Reduce noise — Disable instrumentation for internal health checks or chatty libraries
  • Control costs — Sample a percentage of traces instead of capturing everything
  • Add context — Tag traces with environment, version, or team info for easier filtering

Common options

Add these to your CATALINA_OPTS in setenv.sh:

Disable specific instrumentations:

export CATALINA_OPTS="$CATALINA_OPTS -Dotel.instrumentation.jdbc-datasource.enabled=false"

Sample traces:

export OTEL_TRACES_SAMPLER=parentbased_traceidratio
export OTEL_TRACES_SAMPLER_ARG=0.1  # Sample 10% of traces

Add resource attributes:

export OTEL_RESOURCE_ATTRIBUTES="service.name=my-tomcat-app,deployment.environment=production,service.version=1.2.3"

See the full configuration reference for all available options.

Next steps

Last updated: January 3, 2026

Edit on GitHub

Was this page helpful?