-
Notifications
You must be signed in to change notification settings - Fork 377
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
[integration] add support for AWS #179
Conversation
3963cc2
to
09b7c3e
Compare
04b7cfe
to
94444ac
Compare
Minor failing because of:
We have tests to ensure the default of |
243fe8d
to
54ed5b7
Compare
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.
Thanks for the contribution! a small change and a question about the span.name
. Then we should be good here!
def call(context) | ||
pin = Datadog::Pin.get_from(::Aws) | ||
|
||
return @handler.call(context) unless pin && pin.tracer |
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.
we should check pin.enabled?
:
dd-trace-rb/lib/ddtrace/pin.rb
Lines 32 to 35 in 54ed5b7
def enabled? | |
return @tracer.enabled if @tracer | |
false | |
end |
def annotate!(span, pin, context) | ||
span.service = pin.service | ||
span.span_type = pin.app_type | ||
span.name = context.safely(:resource) |
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.
what kind of names do we have here? can we check that in our tests also so it's explicit what we're expecting?
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.
Basically I tried to mimmic the Python's client behavior here. The name will be something like service.action
. There is a test case for that already:
dd-trace-rb/test/contrib/aws/parsed_context_test.rb
Lines 12 to 14 in 54ed5b7
def test_resource | |
assert_equal('s3.list_buckets', @context.resource) | |
end |
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.
Whoops, just realized we don't have a explicit test for the name! Will add that!
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.
👍
lib/ddtrace/contrib/aws/patcher.rb
Outdated
|
||
def add_pin | ||
Pin.new(SERVICE, app_type: Ext::AppTypes::WEB).tap do |pin| | ||
pin.onto(::Aws) |
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.
assuming that each application uses only one initialized AWS client, setting the Pin
in the module ::Aws
is fine.
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.
Actually each service builds its own client dynamically, the first time the service constant (e.g. S3
) is referenced. If you think having a separated pin would be desirable, I could work on that, but I'll probably have to do some nasty hack around the inherited
hook of the base class or something like that. That would make the contribution a bit more brittle, because we wouldn't be sticking to their plugin API. Whatever you think it's best!
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.
I think that for a user AWS is the service. I prefer a simple approach and then extend it if it's needed. Especially if we should do a nasty hack, so good to me that way 👍
444c52d
to
912490b
Compare
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.
That's great! thank you so much for this integration!
@patched = false | ||
|
||
class << self | ||
def patch |
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.
@p-lambert cool! the code is fine, now we're only missing the documentation and the integration is ready. Feel free to ping me again to review the docs. Thank you!
5d49a7e
to
a8c2f29
Compare
585ccbc
to
a1cdee3
Compare
def setup | ||
# initializes the tracer and a stub client | ||
@tracer = enable_tracer | ||
@client = ::Aws::S3::Client.new(stub_responses: true) |
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.
@p-lambert let's initialize the client and tracer only in the setup
@client = ::Aws::S3::Client.new(stub_responses: true) | ||
end | ||
|
||
def test_pin_defaults |
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.
@p-lambert always test our pin defaults, so we know if we break defaults while changing how the integration works
assert_nil(pin.config) | ||
end | ||
|
||
def test_list_buckets |
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.
@p-lambert it's enough to have all the checks in one test since it should reproduce a real use case (i.e. a call to list_buckets
or a more complex scenario that reproduces/protects from a regression).
assert_equal('us-stubbed-1', aws_span.get_tag('aws.region')) | ||
assert_equal('/', aws_span.get_tag('path')) | ||
assert_equal('s3.us-stubbed-1.amazonaws.com', aws_span.get_tag('host')) | ||
assert_equal('GET', aws_span.get_tag('http.method')) |
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.
@p-lambert don't use our constants in tests; http.method
is what we're expecting, so if someone changes the constant value (breaking a lot of stuff), this test must break.
def test_list_buckets | ||
@client.list_buckets | ||
spans = @tracer.writer.spans | ||
assert_equal(1, spans.length) |
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.
@p-lambert always grab the spans
list and check how many spans are there. If you search only what you need, you will miss:
- double instrumentation (2 spans instead of one)
- conflicts in instrumentation (one integration triggers wrongly another one)
- wrong parenting if you're expecting 2+ spans
a1cdee3
to
7f47401
Compare
Overview
Adds the AWS integration that traces all interactions (e.g. API calls) with AWS services (S3, ElastiCache etc.). To use it simply: