The instana gem provides Ruby metrics and traces (request, queue & cross-host) for Instana.
This gem requires Ruby 3.2 or greater. We actively test and maintain compatibility with Ruby versions 3.2, 3.3, 3.4, and 4.0 to ensure optimal performance and reliability. As part of our commitment to supporting the Ruby community, we continue to provide support for Ruby versions up to 1 year after their official End-of-Life (EOL) date, giving you ample time to plan and execute version upgrades.
Any and all feedback is welcome. Happy Ruby visibility.
The gem is available on Rubygems. To install, add this line to the end of your application's Gemfile:
gem 'instana'And then execute:
$ bundle
Or install it yourself as:
$ gem install instana
The instana gem is a zero configuration tool that will automatically collect key metrics and distributed traces from your Ruby processes. Just install and go.
Although the gem has no configuration required for out of the box metrics and tracing, components can be configured if needed. See our Configuration page.
This Ruby gem provides a simple API for tracing and also supports OpenTracing. See the Ruby Tracing SDK and OpenTracing pages for details.
The instana gem supports exporting traces via the OpenTelemetry Protocol (OTLP)
directly to the Instana agent's OTLP receiver, bypassing the native agent trace format.
OTLP export is opt-in β the gem behaves identically to previous versions when
INSTANA_TRACING_OTLP_ENABLED is not set.
When OTLP export is enabled:
- Spans are converted from Instana's internal format to OTLP protobuf
- The converted spans are sent via HTTP/protobuf to the agent's OTLP port (
4318) - The endpoint is auto-derived from the same host where the Instana agent was discovered
- The native agent reporting path (
/com.instana.plugin.ruby/traces) is replaced by OTLP
The only required change is setting one environment variable before starting your application:
INSTANA_TRACING_OTLP_ENABLED=true bundle exec rails serverExpected log output (with INSTANA_LOG_LEVEL=debug):
[Instana] Using OTLP Exporter to export result code: 0
Result code 0 = SUCCESS. No other configuration is needed β the endpoint is
automatically set to http://<agent-host>:4318/v1/traces.
opentelemetry-exporter-otlp is a runtime dependency of the instana gem and
is installed automatically. No additional gems are required.
Note: gRPC (
OTEL_EXPORTER_OTLP_PROTOCOL=grpc) is not supported. Onlyhttp/protobufis supported and tested.
| Variable | Type | Default | Description |
|---|---|---|---|
INSTANA_TRACING_OTLP_ENABLED |
Boolean | false |
Enables OTLP export. Valid values: true, 1, yes |
OTEL_EXPORTER_OTLP_ENDPOINT |
String (URL) | auto-derived from agent host | Base endpoint URL. /v1/traces is appended automatically. |
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT |
String (URL) | <OTEL_EXPORTER_OTLP_ENDPOINT>/v1/traces |
Fully-qualified trace endpoint. Used as-is; overrides OTEL_EXPORTER_OTLP_ENDPOINT. |
OTEL_EXPORTER_OTLP_PROTOCOL |
String | http/protobuf |
Transport protocol. Only http/protobuf is supported. |
OTEL_EXPORTER_OTLP_HEADERS |
String | β | Comma-separated key=value auth headers. e.g. api-key=secret,x-tenant-id=myorg |
OTEL_EXPORTER_OTLP_TIMEOUT |
Integer (ms) | 10000 |
Maximum time to wait for export completion. |
OTEL_EXPORTER_OTLP_COMPRESSION |
String | β | Compression algorithm. Valid value: gzip. |
OTEL_EXPORTER_OTLP_CERTIFICATE |
String (path) | β | Path to CA certificate file for TLS verification. |
OTEL_EXPORTER_OTLP_CLIENT_KEY |
String (path) | β | Path to client private key file for mutual TLS. |
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE |
String (path) | β | Path to client certificate file for mutual TLS. |
OTEL_EXPORTER_OTLP_INSECURE |
Boolean | false |
Disable TLS certificate verification. |
OTEL_SEMCONV_STABILITY_OPT_IN |
String | stable |
Semantic convention stability level. Valid values: stable, development. |
Endpoint precedence:
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT>OTEL_EXPORTER_OTLP_ENDPOINT> auto-derived from agent host
When INSTANA_CONFIG_PATH points to a YAML file, OTLP settings are placed under
the tracing.otlp key. YAML configuration takes precedence over environment variables.
Minimal example (config/instana.yml):
tracing:
otlp:
enabled: trueFull example:
tracing:
otlp:
enabled: true
endpoint: "http://localhost:4318/v1/traces"
protocol: "http/protobuf"
timeout: 10000
compression: "gzip"
headers:
x-instana-key: "YOUR_API_KEY"
x-tenant-id: "YOUR_TENANT"
certificate: "/path/to/ca-cert.pem"
client_key: "/path/to/client-key.pem"
client_certificate: "/path/to/client-cert.pem"
insecure: false
semconv_stability: "stable"Start the application:
INSTANA_CONFIG_PATH=config/instana.yml bundle exec rails serverSettings are resolved in this order (highest wins):
INSTANA_CONFIG_PATH YAML β Environment variables β Agent config β Defaults
This means a YAML file always wins over env vars. Agent-provided config (pushed via the Instana agent's discovery payload) is applied after env vars but can be overridden by YAML or env vars set at startup.
Server-side TLS (verify the collector's certificate):
INSTANA_TRACING_OTLP_ENABLED=true \
OTEL_EXPORTER_OTLP_ENDPOINT=https://your-collector:4318/v1/traces \
OTEL_EXPORTER_OTLP_CERTIFICATE=/path/to/ca-cert.pem \
bundle exec rails serverMutual TLS (client certificate authentication):
INSTANA_TRACING_OTLP_ENABLED=true \
OTEL_EXPORTER_OTLP_ENDPOINT=https://your-collector:4318/v1/traces \
OTEL_EXPORTER_OTLP_CERTIFICATE=/path/to/ca-cert.pem \
OTEL_EXPORTER_OTLP_CLIENT_KEY=/path/to/client-key.pem \
OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE=/path/to/client-cert.pem \
bundle exec rails serverOTLP export is not happening β spans go via the native path
OTLP is disabled by default. Check that INSTANA_TRACING_OTLP_ENABLED=true is set
in the process environment before the gem initialises (i.e. before require 'instana'
or Rails boot). Verify with:
INSTANA_LOG_LEVEL=debug bundle exec rails server
# Look for: "Using OTLP Exporter" vs "Using Instana Native Exporter"Failed to initialize OTLP exporter in the log
The exporter could not be constructed. Common causes:
OTEL_EXPORTER_OTLP_CERTIFICATEpath does not exist or is not readableOTEL_EXPORTER_OTLP_CLIENT_KEY/OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATEpath invalid- An unsupported protocol (e.g.
grpc) was set β onlyhttp/protobufis supported
The gem falls back to @otlp_exporter = nil and logs an ERROR line with the
exception message. Check that message for the root cause.
result code: 1 (FAILURE) β spans not arriving
The exporter initialised but the export request failed. Common causes:
- The Instana agent is not running or OTLP is not enabled on the agent side
OTEL_EXPORTER_OTLP_ENDPOINTpoints to a wrong host or portOTEL_EXPORTER_OTLP_ENDPOINTwas set to a base URL likehttp://host:4318without/v1/tracesβ this was a known bug fixed in v2.9.0 (the sensor now appends the path automatically)- A firewall is blocking port
4318
Verify the agent OTLP port is reachable:
curl -s -o /dev/null -w "%{http_code}" \
-X POST http://localhost:4318/v1/traces \
-H "Content-Type: application/x-protobuf"
# 200 or 415 = port open; "connection refused" = agent OTLP not enabledHTTP request path is empty exception (pre-v2.9.0)
If you are on a version earlier than 2.9.0 and pass a base URL to
OTEL_EXPORTER_OTLP_ENDPOINT (without /v1/traces), the opentelemetry-exporter-otlp
gem crashes with HTTP request path is empty. Upgrade to v2.9.0 or later, or use
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT with the full path instead.
You can find more documentation covering supported components and minimum versions in the Instana documentation portal.
Instana provides deep end user monitoring that links server side traces with browser events to give you a complete view from server to browser.
See the End User Monitoring page for more information.
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bundle exec rake console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in lib/instana/version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/instana/ruby-sensor.
Want to instrument other languages? See our Node.js, Go, Python repositories or many other supported technologies.