-
Notifications
You must be signed in to change notification settings - Fork 369
/
instrumentation.rb
60 lines (51 loc) · 1.95 KB
/
instrumentation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/aws/ext'
require 'ddtrace/ext/integration'
module Datadog
module Contrib
module Aws
# A Seahorse::Client::Plugin that enables instrumentation for all AWS services
class Instrumentation < Seahorse::Client::Plugin
def add_handlers(handlers, _)
handlers.add(Handler, step: :validate)
end
end
# Generates Spans for all interactions with AWS
class Handler < Seahorse::Client::Handler
def call(context)
tracer.trace(Ext::SPAN_COMMAND) do |span|
@handler.call(context).tap do
annotate!(span, ParsedContext.new(context))
end
end
end
private
def annotate!(span, context)
span.service = configuration[:service_name]
span.span_type = Datadog::Ext::AppTypes::WEB
span.name = Ext::SPAN_COMMAND
span.resource = context.safely(:resource)
# Tag as an external peer service
span.set_tag(Datadog::Ext::Integration::TAG_PEER_SERVICE, span.service)
# Set analytics sample rate
if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
end
span.set_tag(Ext::TAG_AGENT, Ext::TAG_DEFAULT_AGENT)
span.set_tag(Ext::TAG_OPERATION, context.safely(:operation))
span.set_tag(Ext::TAG_REGION, context.safely(:region))
span.set_tag(Ext::TAG_PATH, context.safely(:path))
span.set_tag(Ext::TAG_HOST, context.safely(:host))
span.set_tag(Datadog::Ext::HTTP::METHOD, context.safely(:http_method))
span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, context.safely(:status_code))
end
def tracer
configuration[:tracer]
end
def configuration
Datadog.configuration[:aws]
end
end
end
end
end