Module: SignalFx::Lambda::Tracing
- Defined in:
- lib/signalfx/lambda/tracing.rb,
lib/signalfx/lambda/tracing/extractors.rb
Defined Under Namespace
Classes: B3CodecCommon, B3RackCodec, B3TextMapCodec, Error
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.reporter ⇒ Object
Returns the value of attribute reporter.
12
13
14
|
# File 'lib/signalfx/lambda/tracing.rb', line 12
def reporter
@reporter
end
|
.tracer ⇒ Object
Returns the value of attribute tracer.
12
13
14
|
# File 'lib/signalfx/lambda/tracing.rb', line 12
def tracer
@tracer
end
|
Class Method Details
.get_ingest_url ⇒ Object
82
83
84
85
86
|
# File 'lib/signalfx/lambda/tracing.rb', line 82
def get_ingest_url
return ENV['SIGNALFX_TRACING_URL'] if ENV.key? 'SIGNALFX_TRACING_URL'
return ENV['SIGNALFX_ENDPOINT_URL'] + '/v1/trace' if ENV.key? 'SIGNALFX_ENDPOINT_URL'
return 'https://ingest.signalfx.com/v1/trace'
end
|
.init_tracer(event) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/signalfx/lambda/tracing.rb', line 51
def init_tracer(event)
access_token = ENV['SIGNALFX_ACCESS_TOKEN']
ingest_url = get_ingest_url
service_name = ENV['SIGNALFX_SERVICE_NAME'] || event.function_name
@span_prefix = ENV['SIGNALFX_SPAN_PREFIX'] || 'lambda_ruby_'
= { }
['X-SF-Token'] = access_token if !access_token.empty?
encoder = Jaeger::Client::Encoders::ThriftEncoder.new(service_name: service_name)
sender = Jaeger::Client::HttpSender.new(url: ingest_url, headers: , encoder: encoder, logger: Logger.new(STDOUT))
@reporter = Jaeger::Client::Reporters::RemoteReporter.new(sender: sender, flush_interval: 100)
injectors = {
OpenTracing::FORMAT_TEXT_MAP => [Jaeger::Client::Injectors::B3RackCodec]
}
= {
OpenTracing::FORMAT_TEXT_MAP => [SignalFx::Lambda::Tracing::B3TextMapCodec]
}
OpenTracing.global_tracer = Jaeger::Client.build(
service_name: service_name,
reporter: @reporter,
injectors: injectors,
extractors:
)
@tracer = OpenTracing.global_tracer
end
|
.register_handler(&handler) ⇒ Object
47
48
49
|
# File 'lib/signalfx/lambda/tracing.rb', line 47
def register_handler(&handler)
@handler = handler
end
|
.wrap_function(event:, context:, &block) ⇒ Object
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
|
# File 'lib/signalfx/lambda/tracing.rb', line 14
def wrap_function(event:, context:, &block)
init_tracer(event) if !@tracer
tags = SignalFx::Lambda.fields
tags['component'] = SignalFx::Lambda::COMPONENT
tags['span.kind'] = 'server'
scope = OpenTracing.start_active_span("#{@span_prefix}#{context.function_name}",
tags: tags)
response = yield event: event, context: context
scope.span.set_tag("http.status_code", response[:statusCode]) if response[:statusCode]
response
rescue => error
if scope
scope.span.set_tag("error", true)
scope.span.log_kv(key: "message", value: error.message)
end
raise
ensure
scope.close if scope
@reporter.flush
end
|
.wrapped_handler(event:, context:) ⇒ Object
43
44
45
|
# File 'lib/signalfx/lambda/tracing.rb', line 43
def wrapped_handler(event:, context:)
wrap_function(event, context, &@handler)
end
|