Skip to content

Commit

Permalink
Refactored: :datadog_rack_request_span to 'datadog_rack_request_span'…
Browse files Browse the repository at this point in the history
… in Rack.
  • Loading branch information
delner committed Mar 7, 2018
1 parent b784857 commit fcc3f2d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/ddtrace/contrib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def self.endpoint_run(name, start, finish, id, payload)
span.resource = resource

# set the request span resource if it's a `rack.request` span
request_span = payload[:env][:datadog_rack_request_span]
request_span = payload[:env][Datadog::Contrib::Rack::TraceMiddleware::RACK_REQUEST_SPAN]
if !request_span.nil? && request_span.name == 'rack.request'
request_span.resource = resource
end
Expand Down
7 changes: 6 additions & 1 deletion lib/ddtrace/contrib/rack/middlewares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module Rack
# application. If request tags are not set by the app, they will be set using
# information available at the Rack level.
class TraceMiddleware
RACK_REQUEST_SPAN = 'datadog.rack_request_span'.freeze

def initialize(app)
@app = app
end
Expand All @@ -35,7 +37,10 @@ def call(env)
# start a new request span and attach it to the current Rack environment;
# we must ensure that the span `resource` is set later
request_span = tracer.trace('rack.request', trace_options)
env[:datadog_rack_request_span] = request_span
env[RACK_REQUEST_SPAN] = request_span

# For backwards compatibility; remove later.
env[:datadog_rack_request_span] = env[RACK_REQUEST_SPAN]

# Copy the original env, before the rest of the stack executes.
# Values may change; we want values before that happens.
Expand Down
6 changes: 3 additions & 3 deletions test/contrib/rack/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def app
run(proc do |env|
# this should be considered a web framework that can alter
# the request span after routing / controller processing
request_span = env[:datadog_rack_request_span]
request_span = env[Datadog::Contrib::Rack::TraceMiddleware::RACK_REQUEST_SPAN]
request_span.resource = 'GET /app/'
request_span.set_tag('http.method', 'GET_V2')
request_span.set_tag('http.status_code', 201)
Expand All @@ -54,7 +54,7 @@ def app
run(proc do |env|
# this should be considered a web framework that can alter
# the request span after routing / controller processing
request_span = env[:datadog_rack_request_span]
request_span = env[Datadog::Contrib::Rack::TraceMiddleware::RACK_REQUEST_SPAN]
request_span.status = 1
request_span.set_tag('error.stack', 'Handled exception')

Expand All @@ -66,7 +66,7 @@ def app
run(proc do |env|
# this should be considered a web framework that can alter
# the request span after routing / controller processing
request_span = env[:datadog_rack_request_span]
request_span = env[Datadog::Contrib::Rack::TraceMiddleware::RACK_REQUEST_SPAN]
request_span.set_tag('error.stack', 'Handled exception')

[500, { 'Content-Type' => 'text/html' }, 'OK']
Expand Down

0 comments on commit fcc3f2d

Please sign in to comment.