Module: Datadog::Tracing::Diagnostics::EnvironmentCollector

Defined in:
lib/datadog/tracing/diagnostics/environment_logger.rb

Overview

Collects environment information for Tracing diagnostic logging

Class Method Summary collapse

Class Method Details

.agent_error(responses) ⇒ String

Error returned by Datadog agent during a tracer flush attempt

Returns:

  • (String)

    concatenated list of transport errors



73
74
75
76
77
78
79
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 73

def agent_error(responses)
  error_responses = responses.reject(&:ok?)

  return nil if error_responses.empty?

  error_responses.map(&:inspect).join(',')
end

.agent_urlString?

Returns target agent URL for trace flushing.

Returns:

  • (String, nil)

    target agent URL for trace flushing



60
61
62
63
64
65
66
67
68
69
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 60

def agent_url
  # Retrieve the effect agent URL, regardless of how it was configured
  transport = Tracing.send(:tracer).writer.transport

  # return `nil` with IO transport
  return unless transport.respond_to?(:client)

  adapter = transport.client.api.adapter
  adapter.url
end

.analytics_enabledBoolean?

Returns analytics enabled in configuration.

Returns:

  • (Boolean, nil)

    analytics enabled in configuration



82
83
84
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 82

def analytics_enabled
  !!Datadog.configuration.tracing.analytics.enabled
end

.collect_config!Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 34

def collect_config!
  {
    enabled: enabled,
    agent_url: agent_url,
    analytics_enabled: analytics_enabled,
    sample_rate: sample_rate,
    sampling_rules: sampling_rules,
    integrations_loaded: integrations_loaded,
    partial_flushing_enabled: partial_flushing_enabled,
    priority_sampling_enabled: priority_sampling_enabled,
    **instrumented_integrations_settings
  }
end

.collect_errors!(responses) ⇒ Object



48
49
50
51
52
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 48

def collect_errors!(responses)
  {
    agent_error: agent_error(responses)
  }
end

.enabledBoolean?

Returns:

  • (Boolean, nil)


55
56
57
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 55

def enabled
  !!Datadog.configuration.tracing.enabled
end

.integrations_loadedString?

Concatenated list of integrations activated, with their gem version. Example: “[email protected],[email protected]

Returns:

  • (String, nil)


120
121
122
123
124
125
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 120

def integrations_loaded
  integrations = instrumented_integrations
  return if integrations.empty?

  integrations.map { |name, integration| "#{name}@#{integration.class.version}" }.join(',')
end

.partial_flushing_enabledBoolean?

Returns partial flushing enabled in configuration.

Returns:

  • (Boolean, nil)

    partial flushing enabled in configuration



128
129
130
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 128

def partial_flushing_enabled
  !!Datadog.configuration.tracing.partial_flush.enabled
end

.priority_sampling_enabledBoolean?

Returns priority sampling enabled in configuration.

Returns:

  • (Boolean, nil)

    priority sampling enabled in configuration



133
134
135
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 133

def priority_sampling_enabled
  !!Datadog.configuration.tracing.priority_sampling
end

.sample_rateNumeric?

Returns tracer sample rate configured.

Returns:

  • (Numeric, nil)

    tracer sample rate configured



87
88
89
90
91
92
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 87

def sample_rate
  sampler = Datadog.configuration.tracing.sampler
  return nil unless sampler

  sampler.sample_rate(nil) rescue nil
end

.sampling_rulesHash?

DEV: We currently only support SimpleRule instances. DEV: These are the most commonly used rules. DEV: We should expand support for other rules in the future, DEV: although it is tricky to serialize arbitrary rules.

Returns:

  • (Hash, nil)

    sample rules configured



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/datadog/tracing/diagnostics/environment_logger.rb', line 100

def sampling_rules
  sampler = Datadog.configuration.tracing.sampler
  return nil unless sampler.is_a?(Tracing::Sampling::PrioritySampler) &&
    sampler.priority_sampler.is_a?(Tracing::Sampling::RuleSampler)

  sampler.priority_sampler.rules.map do |rule|
    next unless rule.is_a?(Tracing::Sampling::SimpleRule)

    {
      name: rule.matcher.name,
      service: rule.matcher.service,
      sample_rate: rule.sampler.sample_rate(nil)
    }
  end.compact
end