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

[integration] add support for AWS #179

Merged
merged 2 commits into from
Sep 20, 2017
Merged

[integration] add support for AWS #179

merged 2 commits into from
Sep 20, 2017

Conversation

p-lambert
Copy link
Member

@p-lambert p-lambert commented Aug 24, 2017

Overview

Adds the AWS integration that traces all interactions (e.g. API calls) with AWS services (S3, ElastiCache etc.). To use it simply:

require 'aws-sdk'
require 'ddtrace'

Datadog::Monkey.patch_module(:aws)  # explicitly patch it

Aws::S3::Client.new.list_buckets  # this call is traced

@p-lambert p-lambert force-pushed the pedro/aws-contrib branch 3 times, most recently from 3963cc2 to 09b7c3e Compare August 25, 2017 14:04
@palazzem palazzem self-requested a review August 28, 2017 08:38
@palazzem palazzem added integrations Involves tracing integrations do-not-merge/WIP Not ready for merge labels Aug 28, 2017
@palazzem palazzem added this to the 0.9.0 milestone Aug 28, 2017
@palazzem palazzem changed the title [WIP] Add support for AWS [integartion] add support for AWS Aug 28, 2017
@palazzem palazzem changed the title [integartion] add support for AWS [integration] add support for AWS Aug 28, 2017
@p-lambert p-lambert force-pushed the pedro/aws-contrib branch 9 times, most recently from 04b7cfe to 94444ac Compare August 29, 2017 03:24
@palazzem
Copy link
Contributor

Minor failing because of:

  1) Failure:
MonkeyTest#test_patch_module [/home/ubuntu/dd-trace-rb/test/monkey_test.rb:26]:
Expected: false
  Actual: nil

We have tests to ensure the default of Monkey.patch_all, so probably you need to add this integration to the list.

@p-lambert p-lambert force-pushed the pedro/aws-contrib branch 3 times, most recently from 243fe8d to 54ed5b7 Compare August 30, 2017 17:39
@p-lambert p-lambert removed the do-not-merge/WIP Not ready for merge label Aug 30, 2017
Copy link
Contributor

@palazzem palazzem left a 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
Copy link
Contributor

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?:

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)
Copy link
Contributor

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?

Copy link
Member Author

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:

def test_resource
assert_equal('s3.list_buckets', @context.resource)
end

Copy link
Member Author

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!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


def add_pin
Pin.new(SERVICE, app_type: Ext::AppTypes::WEB).tap do |pin|
pin.onto(::Aws)
Copy link
Contributor

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.

Copy link
Member Author

@p-lambert p-lambert Sep 11, 2017

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!

Copy link
Contributor

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 👍

@p-lambert p-lambert force-pushed the pedro/aws-contrib branch 3 times, most recently from 444c52d to 912490b Compare September 11, 2017 19:56
palazzem
palazzem previously approved these changes Sep 14, 2017
Copy link
Contributor

@palazzem palazzem left a 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
Copy link
Contributor

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!

@palazzem palazzem dismissed their stale review September 14, 2017 09:02

(forget to ask for docs)

@p-lambert p-lambert force-pushed the pedro/aws-contrib branch 3 times, most recently from 5d49a7e to a8c2f29 Compare September 19, 2017 20:07
palazzem
palazzem previously approved these changes Sep 20, 2017
def setup
# initializes the tracer and a stub client
@tracer = enable_tracer
@client = ::Aws::S3::Client.new(stub_responses: true)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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'))
Copy link
Contributor

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)
Copy link
Contributor

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

@palazzem palazzem merged commit 85c78dc into master Sep 20, 2017
@palazzem palazzem deleted the pedro/aws-contrib branch September 20, 2017 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants