Skip to content

Commit

Permalink
Merge pull request #3367 from DataDog/after_request
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc authored Jan 10, 2024
2 parents dede2de + 9c3d405 commit 5872b4e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 56 deletions.
16 changes: 0 additions & 16 deletions lib/datadog/tracing/contrib/http/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ def self.included(base)
base.prepend(InstanceMethods)
end

# Span hook invoked after request is completed.
def self.after_request(&block)
if block
# Set hook
@after_request = block
else
# Get hook
@after_request ||= nil
end
end

# InstanceMethods - implementing instrumentation
module InstanceMethods
include Contrib::HttpAnnotationHelper
Expand Down Expand Up @@ -59,11 +48,6 @@ def request(req, body = nil, &block)
# Add additional response specific tags to the span.
annotate_span_with_response!(span, response, request_options)

# Invoke hook, if set.
unless Contrib::HTTP::Instrumentation.after_request.nil?
Contrib::HTTP::Instrumentation.after_request.call(span, self, req, response)
end

response
end
end
Expand Down
1 change: 0 additions & 1 deletion sig/datadog/tracing/contrib/http/instrumentation.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Datadog
module HTTP
module Instrumentation
def self.included: (untyped base) -> untyped
def self.after_request: () ?{ () -> untyped } -> untyped
module InstanceMethods
include Contrib::HttpAnnotationHelper
def request: (untyped req, ?untyped? body) ?{ () -> untyped } -> untyped
Expand Down
39 changes: 0 additions & 39 deletions spec/datadog/tracing/contrib/http/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,45 +142,6 @@
it_behaves_like 'environment service name', 'DD_TRACE_NET_HTTP_SERVICE_NAME'
it_behaves_like 'configured peer service span', 'DD_TRACE_NET_HTTP_PEER_SERVICE'
it_behaves_like 'schema version span'

context 'when configured with #after_request hook' do
before { Datadog::Tracing::Contrib::HTTP::Instrumentation.after_request(&callback) }

after { Datadog::Tracing::Contrib::HTTP::Instrumentation.instance_variable_set(:@after_request, nil) }

context 'which defines each parameter' do
let(:callback) do
proc do |span_op, http, request, response|
expect(span_op).to be_a_kind_of(Datadog::Tracing::SpanOperation)
expect(http).to be_a_kind_of(Net::HTTP)
expect(request).to be_a_kind_of(Net::HTTP::Get)
expect(response).to be_a_kind_of(Net::HTTPNotFound)
end
end

it { expect(response.code).to eq('404') }
end

context 'which changes the error status' do
let(:callback) do
proc do |span_op, _http, _request, response|
case response.code.to_i
when 400...599
if response.class.body_permitted? && !response.body.nil?
span_op.set_error([response.class, response.body[0...4095]])
end
end
end
end

it 'generates a trace modified by the hook' do
expect(response.code).to eq('404')
expect(span.status).to eq(1)
expect(span.get_tag('error.type')).to eq('Net::HTTPNotFound')
expect(span.get_tag('error.message')).to eq(body)
end
end
end
end
end

Expand Down

0 comments on commit 5872b4e

Please sign in to comment.