open-telemetry / open-telemetry/opentelemetry-ruby-contrib
Sinatra instrumentation throws errors when using multiple Sinatra app classes
@kaylareopelle is already working on this.
Since Jul 23, 2026.
- Dominant language
- Ruby
- Stars
- 137
- Forks
- 258
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 30
Description
Description of the bug
If you build a Sinatra app that uses other Sinatra apps as middleware (a documented pattern for dividing endpoints into multiple classes), the default OpenTelemetry instrumentation throws errors every time an endpoint is called.
See "Using Sinatra as Middleware" here: https://sinatrarb.com/intro.html
Share details about your runtime
Operating system details: MacOS, Tahoe 26.5.1
RUBY_ENGINE: "ruby"
RUBY_VERSION: "3.3.4"
RUBY_DESCRIPTION: "ruby 3.3.4 (2024-07-09 revision be1089c8ec) [arm64-darwin23]"
Share a simplified reproduction if possible
MCVE here: https://github.com/isaaclyman/opentelemetry-instrumentation-sinatra-detach-error-mcve
- Install Sinatra and OpenTelemetry
- Set up the OpenTelemetry SDK with
use_all - Create two classes that inherit from
Sinatra::Base, as described in "Using Sinatra as Middleware" - Add a basic endpoint to the first class
- Have the second class
usethe first one - Send a request to the endpoint
You see the following in the application console:
W, [...] WARN -- : Calling finish on an ended Span.
E, [...] ERROR -- : OpenTelemetry error: calls to detach should match corresponding calls to attach.
Additionally, the generated trace has a missing parent span.
The problem disappears if you have only one class that inherits from Sinatra::Base and don't use any other classes as middleware.
It also disappears if you pass install_rack: false as an option to OpenTelemetry::Instrumentation::Sinatra, but then traces are not produced.
Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more in our end user docs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.