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

Do not log Lambda runtime segments #39

Merged
merged 1 commit into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions lib/aws-xray-sdk/facets/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ def initialize(*options)
super(*options)
end

# HTTP requests to AWS Lambda Ruby Runtime will begin with the
# value set in ENV['AWS_LAMBDA_RUNTIME_API']
def lambda_runtime_request?(req)
ENV['AWS_LAMBDA_RUNTIME_API'] &&
req.uri &&
req.uri.to_s.start_with?('http://'+ENV['AWS_LAMBDA_RUNTIME_API']+'/')
# HTTP requests to AWS Lambda Ruby Runtime will have the address and port
# matching the value set in ENV['AWS_LAMBDA_RUNTIME_API']
def lambda_runtime_request?
ENV['AWS_LAMBDA_RUNTIME_API'] == "#{address}:#{port}"
end

def xray_sampling_request?(req)
Expand All @@ -34,7 +32,7 @@ def xray_sampling_request?(req)

def request(req, body = nil, &block)
# Do not trace requests to xray or aws lambda runtime
if xray_sampling_request?(req) || lambda_runtime_request?(req)
if xray_sampling_request?(req) || lambda_runtime_request?
return super
end

Expand Down
30 changes: 30 additions & 0 deletions test/aws-xray-sdk/tc_facet_net_http.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require_relative '../test_helper'
require 'aws-xray-sdk/facets/net_http'

class TestFacetNetHttp < Minitest::Test

def setup
ENV['AWS_LAMBDA_RUNTIME_API'] = 'localhost:3000'
end

def teardown
ENV.delete('AWS_LAMBDA_RUNTIME_API')
end

def test_lambda_runtime_request_true
http = Net::HTTP.new('localhost',3000)
assert http.lambda_runtime_request?
end

def test_lambda_runtime_request_false
http = Net::HTTP.new('www.example.com',3000)
refute http.lambda_runtime_request?
end

def test_lambda_runtime_request_nil_env
ENV.delete('AWS_LAMBDA_RUNTIME_API')
refute ENV['AWS_LAMBDA_RUNTIME_API']
http = Net::HTTP.new('www.example.com',3000)
refute http.lambda_runtime_request?
end
end