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

Add distributed_tracing option to Sinatra #325

Merged
merged 2 commits into from
Jan 24, 2018

Conversation

delner
Copy link
Contributor

@delner delner commented Jan 24, 2018

Currently Sinatra doesn't support distributed tracing out of the box. It required the user to configure Rack as a service first, e.g.:

Datadog.configure do |c|
  c.use :sinatra, resource_script_names: true, service_name: 'knowledge-api',
  c.use :rack, distributed_tracing: true
end

This pull request implements distributed_tracing as an option for Sinatra, so you only have to:

Datadog.configure do |c|
  c.use :sinatra, distributed_tracing: true
end

@delner delner added enhancement integrations Involves tracing integrations labels Jan 24, 2018
@delner delner added this to the 0.11.1 milestone Jan 24, 2018
@delner delner self-assigned this Jan 24, 2018
@delner delner requested a review from palazzem January 24, 2018 19:38
@delner delner force-pushed the delner/add_sinatra_distributed_tracing_option branch from a1b6180 to dedfa0e Compare January 24, 2018 19:54
@@ -83,6 +84,11 @@ def render(engine, data, *)

tracer = Datadog.configuration[:sinatra][:tracer]

if Datadog.configuration[:sinatra][:distributed_tracing]
context = HTTPPropagator.extract(request.env)
tracer.provider.context = context if context.trace_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that. Sinatra can play with the Rack integration, and if c.use :rack is activated, our Context should have already a Rack span. If we do this change without checking, we may lose data here. I don't know why we can't automatically activate the Rack patch like we did for Rails:

Datadog.configuration.use(
:rack,
tracer: tracer,
service_name: config[:service_name],
distributed_tracing: config[:distributed_tracing]
)

Anyway, since we didn't use the Rack integration under the hood, the approach that doesn't break anything is checking if we have spans before replacing the context. In that case, I would say to not do anything.

Side-effects:

  • if you're using Rack, Rack should activate distributed_tracing
  • if you're using something else on top of Sinatra, well it should be a supported framework to enable distributed tracing

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After our discussion, it's a matter of tradeoffs. Since Sinatra doesn't use Rack under the hood, we should keep this logic. The only problem with this approach, is that you may detach Sinatra and Rack traces, if you enable both and activate Sinatra distributed tracing.

The behavior is supported if you activate distributed_tracing only on Rack, that makes sense and is the lesser error prone approach. Let's keep it that way.

palazzem
palazzem previously approved these changes Jan 24, 2018
Copy link
Contributor

@palazzem palazzem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're not using Rack with Sinatra, the lesser error prone approach is this one. Good to go.

@@ -83,6 +84,11 @@ def render(engine, data, *)

tracer = Datadog.configuration[:sinatra][:tracer]

if Datadog.configuration[:sinatra][:distributed_tracing]
context = HTTPPropagator.extract(request.env)
tracer.provider.context = context if context.trace_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After our discussion, it's a matter of tradeoffs. Since Sinatra doesn't use Rack under the hood, we should keep this logic. The only problem with this approach, is that you may detach Sinatra and Rack traces, if you enable both and activate Sinatra distributed tracing.

The behavior is supported if you activate distributed_tracing only on Rack, that makes sense and is the lesser error prone approach. Let's keep it that way.

@delner
Copy link
Contributor Author

delner commented Jan 24, 2018

Discussed a possible issue when both Rack and Sinatra are activated together with @palazzem. If you activate Rack without distributed tracing, then activate Sinatra with distributed tracing, e.g.:

Datadog.configure do |c|
  c.use :rack
  c.use :sinatra, distributed_tracing: true
end

...then we could see dropped Rack spans, because Sinatra will override trace context with the trace info it receives from the request. This obviously isn't great, but it's a compromise that needs to be made because without a little aid from the configuration, it's very difficult to identify which integration is the "root" one handling inbound distributed tracing, and subsequently override trace contexts properly. The compromise made here is that we expect users who are configuring their application to apply the distributed_tracing: true option exclusively to the root most integration, where traces enter the application.

In the case of an application with both Rack and Sinatra, then it should look something like:

Datadog.configure do |c|
  c.use :rack, distributed_tracing: true
  c.use :sinatra
end

For applications with just Sinatra + distributed tracing, it would be:

Datadog.configure do |c|
  c.use :sinatra, distributed_tracing: true
end

@delner delner merged commit 77f52cc into master Jan 24, 2018
@delner delner deleted the delner/add_sinatra_distributed_tracing_option branch February 9, 2018 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants