Skip to content

Commit

Permalink
Added: Deprecation warning for :datadog_rack_request_span.
Browse files Browse the repository at this point in the history
  • Loading branch information
delner committed Mar 7, 2018
1 parent fcc3f2d commit 651d184
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/ddtrace/contrib/rack/middlewares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def call(env)
# For backwards compatibility; remove later.
env[:datadog_rack_request_span] = env[RACK_REQUEST_SPAN]

# Add deprecation warnings
add_deprecation_warnings(env)

# Copy the original env, before the rest of the stack executes.
# Values may change; we want values before that happens.
original_env = env.dup
Expand Down Expand Up @@ -144,6 +147,31 @@ def get_request_id(headers, env)
headers ||= {}
headers['X-Request-Id'] || headers['X-Request-ID'] || env['HTTP_X_REQUEST_ID']
end

private

REQUEST_SPAN_DEPRECATION_WARNING = %(
Use of :datadog_rack_request_span in the Rack env is DEPRECATED.
If you need the Rack request span, try using `Datadog.tracer.active_span`.
This key will no longer be available in future versions.).freeze

def add_deprecation_warnings(env)
env.instance_eval do
def [](key)
if key == :datadog_rack_request_span
Datadog::Tracer.log.warn(REQUEST_SPAN_DEPRECATION_WARNING)
end
super
end

def []=(key, value)
if key == :datadog_rack_request_span
Datadog::Tracer.log.warn(REQUEST_SPAN_DEPRECATION_WARNING)
end
super
end
end
end
end
end
end
Expand Down

0 comments on commit 651d184

Please sign in to comment.