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

[rails] add the TraceMiddleware immediately instead of relying in another initializer #208

Merged
merged 4 commits into from
Oct 6, 2017

Conversation

palazzem
Copy link
Contributor

Overview

In the previous implementation we used another initializer to delay the insert of Datadog::Contrib::Rack::TraceMiddleware. Unfortunately this doesn't work in some cases as reported in #121. The patch adds the TraceMiddleware immediately, right before the ExceptionMiddleware.

Users impact

The impact may be huge so we should do proper testing before merging this PR. Tests are not enough since the problem is how the application is initialized.

@palazzem palazzem added enhancement integrations Involves tracing integrations do-not-merge/WIP Not ready for merge labels Sep 30, 2017
@palazzem palazzem added this to the 0.9.0 milestone Sep 30, 2017
@@ -72,6 +72,7 @@ of the Datadog tracer, you can override the following defaults:
default_controller_service: 'rails-controller',
default_cache_service: 'rails-cache',
default_database_service: 'postgresql',
distributed_tracing_enabled: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we missed that in the doc; mostly the goal is to remember that with the current config version, you can enable distributed tracing from the settings. Not that great since we're planning to change that, but at least we have a reference for that.

@@ -36,11 +36,13 @@ def self.tracer
module Datadog
# Railtie class initializes
class Railtie < Rails::Railtie
# add instrumentation middlewares
options = {}
config.app_middleware.insert_before(0, Datadog::Contrib::Rack::TraceMiddleware, options)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change ensures that the middleware is here; with the previous approach, applications may ignore the initializer resulting in wrong traces

@@ -38,9 +38,9 @@ def initialize(app, options = {})
@options = options
end

def configure
def configure(reload = false)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

mostly a problem with the current concept of configuration; with the new Configuration it should be easy to update the Rack middleware configurations without reinitializing from scratch Rails from our tests. Consider that this reload parameter is here only for testing purposes (and it's not ideal).

@@ -58,7 +58,8 @@ def configure
# rubocop:disable Metrics/MethodLength
def call(env)
# configure the Rack middleware once
configure()
configure
clean_context
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can clean the context all the time; another PR makes this process safe even if the @tracer is not defined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reference: #209

@@ -178,4 +183,22 @@ class FullStackTest < ActionDispatch::IntegrationTest
assert_equal(request_span.get_tag('http.status_code'), '404')
assert_equal(request_span.status, 0)
end

test 'rails configuration enables distributed tracing' do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The change in the configure() method has been done to make this test. Mostly my intention was to be sure we can do distributed tracing using Rails settings. Since we may not need this test later (Rack will be configured separately maybe?), we may rollback the last change in the future.

@palazzem palazzem removed the do-not-merge/WIP Not ready for merge label Oct 2, 2017
@palazzem palazzem force-pushed the palazzem/rails-railtie branch 2 times, most recently from 5588ba1 to 88eca02 Compare October 2, 2017 06:54
@palazzem palazzem merged commit 7f0ed5f into master Oct 6, 2017
@palazzem palazzem deleted the palazzem/rails-railtie branch October 6, 2017 17:47
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