-
Notifications
You must be signed in to change notification settings - Fork 375
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
Patch Sinatra only once #3515
base: master
Are you sure you want to change the base?
Patch Sinatra only once #3515
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,10 @@ def configure(&block) | |
# Reconfigure core settings | ||
super(&block) | ||
|
||
# Configuration should be considered RO past this point: | ||
# - Patcher's `patch` must not modify configuration. | ||
# - use Integration's `subconfigure` instead | ||
|
||
Comment on lines
+66
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering about calling
|
||
# Activate integrations | ||
configuration = self.configuration.tracing | ||
|
||
|
@@ -158,7 +162,7 @@ def instrument(integration_name, options = {}, &block) | |
unless integration.nil? || !integration.default_configuration.enabled | ||
configuration_name = options[:describes] || :default | ||
filtered_options = options.reject { |k, _v| k == :describes } | ||
integration.configure(configuration_name, filtered_options, &block) | ||
integration.configure(configuration_name, filtered_options, self, &block) | ||
instrumented_integrations[integration_name] = integration | ||
|
||
# Add to activation list | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,14 @@ def new_configuration | |
Configuration::Settings.new | ||
end | ||
|
||
def subconfigure(tracing, sinatra) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lousy name, I considered merely There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. Indeed in this case we do Technically this is really a callback within the Functionally this is about setting up dependencies, so it may go beyond just e.g I'll need to apply similar changes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good points. I like the |
||
tracing.instrument( | ||
:rack, | ||
service_name: sinatra.service_name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should deprecate setting the rack E.g. instead suggest customers configure a top-level service name instead, or if they really want to, they can configure a service name in rack directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not so much about passing a manually configured service name as much as when that Same for Rails where it's the application name as a default. Cue autoinstrumentation as well. Tangentially there may be a conundrum to resolve here in such default cases: ordering may matter when there's both Sinatra and Rails in the same app, as both would set their service name and one would win. But that's a problem for another day. |
||
distributed_tracing: sinatra.distributed_tracing, | ||
) | ||
Comment on lines
+35
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most probably:
|
||
end | ||
|
||
def patcher | ||
Patcher | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,6 @@ module Datadog | |
module Tracing | ||
module Contrib | ||
module Sinatra | ||
# Set tracer configuration at a late enough time | ||
module TracerSetupPatch | ||
ONLY_ONCE_PER_APP = Hash.new { |h, key| h[key] = Core::Utils::OnlyOnce.new } | ||
|
||
def setup_middleware(*args, &block) | ||
super.tap do | ||
ONLY_ONCE_PER_APP[self].run do | ||
Contrib::Sinatra::Framework.setup | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Hook into builder before the middleware list gets frozen | ||
module DefaultMiddlewarePatch | ||
ONLY_ONCE_PER_APP = Hash.new { |h, key| h[key] = Core::Utils::OnlyOnce.new } | ||
|
@@ -53,7 +40,6 @@ def patch | |
register_tracer | ||
|
||
patch_default_middlewares | ||
setup_tracer | ||
end | ||
|
||
def register_tracer | ||
Comment on lines
-56
to
45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⬇️ Don't forget to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, removed. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
tracing_configuration
ortracing_instrumentation
instead maybe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's a bit ambiguous. Since this is a
Configuration::Settings
object and the other name here isconfig
I went withtracing_config
.