Module: Datadog::Tracing::Contrib::HTTP::CircuitBreaker

Included in:
Datadog::Tracing::Contrib::HTTP
Defined in:
lib/datadog/tracing/contrib/http/circuit_breaker.rb

Overview

HTTP integration circuit breaker behavior For avoiding recursive traces.

Instance Method Summary collapse

Instance Method Details

#internal_request?(request) ⇒ Boolean

We don’t want to trace our own call to the API (they use net/http) TODO: We don’t want this kind of soft-check on HTTP requests.

Remove this when transport implements its own "skip tracing" mechanism.

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/datadog/tracing/contrib/http/circuit_breaker.rb', line 26

def internal_request?(request)
  !!(request[Datadog::Core::Transport::Ext::HTTP::HEADER_META_TRACER_VERSION] ||
    request[Datadog::Core::Transport::Ext::HTTP::HEADER_DD_INTERNAL_UNTRACED_REQUEST])
end

#should_skip_distributed_tracing?(client_config) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/datadog/tracing/contrib/http/circuit_breaker.rb', line 31

def should_skip_distributed_tracing?(client_config)
  if Datadog.configuration.appsec.standalone.enabled
    # Skip distributed tracing so that we don't bill distributed traces in case of absence of
    # upstream ASM event (_dd.p.appsec:1) and no local security event (which sets _dd.p.appsec:1 locally).
    # If there is an ASM event, we still have to check if distributed tracing is enabled or not
    return true unless Tracing.active_trace

    return true if Tracing.active_trace.get_tag(Datadog::AppSec::Ext::TAG_DISTRIBUTED_APPSEC_EVENT) != '1'
  end

  return !client_config[:distributed_tracing] if client_config && client_config.key?(:distributed_tracing)

  !Datadog.configuration.tracing[:http][:distributed_tracing]
end

#should_skip_tracing?(request) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
# File 'lib/datadog/tracing/contrib/http/circuit_breaker.rb', line 12

def should_skip_tracing?(request)
  return true if internal_request?(request)

  # we don't want a "shotgun" effect with two nested traces for one
  # logical get, and request is likely to call itself recursively
  active = Tracing.active_span
  return true if active && (active.name == Ext::SPAN_REQUEST)

  false
end