Module: Datadog::Tracing::Contrib::Stripe::Request

Defined in:
lib/datadog/tracing/contrib/stripe/request.rb

Overview

Defines instrumentation for Stripe requests

Class Method Summary collapse

Class Method Details

.configurationObject



60
61
62
# File 'lib/datadog/tracing/contrib/stripe/request.rb', line 60

def configuration
  Datadog.configuration.tracing[:stripe]
end

.finish_span(event) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/datadog/tracing/contrib/stripe/request.rb', line 22

def finish_span(event)
  span = event.user_data[:datadog_span]
  # If no active span, return.
  return nil if span.nil?

  begin
    tag_span(span, event)
  ensure
    # Finish the span
    span.finish
  end
end

.start_span(event) ⇒ Object



15
16
17
18
19
20
# File 'lib/datadog/tracing/contrib/stripe/request.rb', line 15

def start_span(event)
  # Start a trace
  Tracing.trace(Ext::SPAN_REQUEST).tap do |span|
    event.user_data[:datadog_span] = span
  end
end

.tag_span(span, event) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/datadog/tracing/contrib/stripe/request.rb', line 35

def tag_span(span, event)
  # dependent upon stripe/stripe-ruby#1168
  span.resource = "stripe.#{event.object_name}" if event.respond_to?(:object_name) && event.object_name

  span.span_type = Ext::SPAN_TYPE_REQUEST
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)

  # Set analytics sample rate
  if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
    Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
  end

  # Measure service stats
  Contrib::Analytics.set_measured(span)

  span.set_tag(Ext::TAG_REQUEST_ID, event.request_id)
  span.set_tag(Ext::TAG_REQUEST_HTTP_STATUS, event.http_status.to_s)
  span.set_tag(Ext::TAG_REQUEST_METHOD, event.method)
  span.set_tag(Ext::TAG_REQUEST_PATH, event.path)
  span.set_tag(Ext::TAG_REQUEST_NUM_RETRIES, event.num_retries.to_s)
rescue StandardError => e
  Datadog.logger.debug(e.message)
end