Class: Instana::Serverless

Inherits:
Object
  • Object
show all
Defined in:
lib/instana/serverless.rb

Overview

Since:

  • 1.198.0

Instance Method Summary collapse

Constructor Details

#initialize(agent: ::Instana.agent, tracer: ::Instana.tracer, logger: ::Instana.logger) ⇒ Serverless

Returns a new instance of Serverless.

Since:

  • 1.198.0



20
21
22
23
24
# File 'lib/instana/serverless.rb', line 20

def initialize(agent: ::Instana.agent, tracer: ::Instana.tracer, logger: ::Instana.logger)
  @agent = agent
  @tracer = tracer
  @logger = logger
end

Instance Method Details

#wrap_aws(event, context, &block) ⇒ Object

Since:

  • 1.198.0



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
# File 'lib/instana/serverless.rb', line 26

def wrap_aws(event, context, &block)
  Thread.current[:instana_function_arn] = [context.invoked_function_arn, context.function_version].join(':')
  trigger, event_tags, span_context = trigger_from_event(event, context)

  tags = {
    lambda: {
      arn: context.invoked_function_arn,
      functionName: context.function_name,
      functionVersion: context.function_version,
      runtime: 'ruby',
      trigger: trigger
    }
  }

  if event_tags.key?(:http)
    tags = tags.merge(event_tags)
  else
    tags[:lambda] = tags[:lambda].merge(event_tags)
  end
  Trace.with_span(OpenTelemetry::Trace.non_recording_span(::Instana::SpanContext.new(trace_id: span_context[:trace_id], span_id: span_context[:span_id],
                                                                                     level: span_context[:level]))) do
    @tracer.in_span(:'aws.lambda.entry', attributes: tags, &block)
  end
ensure
  begin
    @agent.send_bundle
  rescue StandardError => e
    @logger.error(e.message)
  end
  Thread.current[:instana_function_arn] = nil
end