Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NoMethodError in sinatra integration when Tracer middleware is missing #1644

Merged

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Aug 11, 2021

This fixes a regression introduced in version 0.52.0 by #1628.

When a Sinatra modular application being traced is missing the Datadog::Contrib::Sinatra::Tracer middleware (as documented in https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#sinatra), no Sinatra request span is ever created (only a route span).

Because we didn't properly account for this in #datadog_span, the following NoMethodError was triggered:

NoMethodError: undefined method `[]' for nil:NilClass
  dd-trace-rb/lib/ddtrace/contrib/sinatra/env.rb:13:in `datadog_span'
  dd-trace-rb/lib/ddtrace/contrib/sinatra/tracer.rb:122:in `block in route_eval'
  dd-trace-rb/lib/ddtrace/tracer.rb:283:in `trace'
  dd-trace-rb/lib/ddtrace/contrib/sinatra/tracer.rb:105:in `route_eval'
  ruby-2.7.4/gems/sinatra-2.1.0/lib/sinatra/base.rb:1013:in `block (2 levels) in route!'

I suspect this is the same issue as was reported in #1643.

Because this configuration is actually not desirable -- spans reported will be missing crucial request information, as discussed in #1643 -- I've also added a warning to hopefully steer users in the right direction.

…ssing

This fixes a regression introduced in version 0.52.0 by #1628.

When a Sinatra modular application being traced is missing the
`Datadog::Contrib::Sinatra::Tracer` middleware
(as documented in
<https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#sinatra>),
no Sinatra request span is ever created (only a route span).

Because we didn't properly account for this in `#datadog_span`, the
following `NoMethodError` was triggered:

```
NoMethodError: undefined method `[]' for nil:NilClass
  dd-trace-rb/lib/ddtrace/contrib/sinatra/env.rb:13:in `datadog_span'
  dd-trace-rb/lib/ddtrace/contrib/sinatra/tracer.rb:122:in `block in route_eval'
  dd-trace-rb/lib/ddtrace/tracer.rb:283:in `trace'
  dd-trace-rb/lib/ddtrace/contrib/sinatra/tracer.rb:105:in `route_eval'
  ruby-2.7.4/gems/sinatra-2.1.0/lib/sinatra/base.rb:1013:in `block (2 levels) in route!'
```

I suspect this is the same issue as was reported in #1643.

Because this configuration is actually not desirable -- spans reported
will be missing crucial request information, as discussed in #1643 --
I've also added a warning to hopefully steer users in the right
direction.
@ivoanjo ivoanjo requested a review from a team August 11, 2021 11:23
@ivoanjo ivoanjo added the bug Involves a bug label Aug 11, 2021
@ivoanjo ivoanjo self-assigned this Aug 11, 2021
@ivoanjo ivoanjo merged commit 3802175 into master Aug 12, 2021
@ivoanjo ivoanjo deleted the ivoanjo/fix-nomethoderror-on-sinatra-without-middleware branch August 12, 2021 07:48
@github-actions github-actions bot added this to the 0.53.0 milestone Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants