ddtrace 1.13.1 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'json'
5
+ require 'rbconfig'
6
+ require_relative '../../core/diagnostics/environment_logger'
7
+
8
+ module Datadog
9
+ module Tracing
10
+ module Diagnostics
11
+ # Collects and logs Tracing diagnostic and error information
12
+ module EnvironmentLogger
13
+ extend Core::Diagnostics::EnvironmentLogging
14
+
15
+ def self.collect_and_log!(responses: nil)
16
+ log_once! do
17
+ env_data = EnvironmentCollector.collect_config!
18
+ log_configuration!('TRACING', env_data.to_json)
19
+
20
+ if responses
21
+ err_data = EnvironmentCollector.collect_errors!(responses)
22
+ err_data.reject! { |_, v| v.nil? } # Remove empty values from hash output
23
+ log_error!('TRACING', 'Agent Error', err_data.to_json) unless err_data.empty?
24
+ end
25
+ end
26
+ rescue => e
27
+ logger.warn("Failed to collect tracing environment information: #{e} Location: #{Array(e.backtrace).first}")
28
+ end
29
+ end
30
+
31
+ # Collects environment information for Tracing diagnostic logging
32
+ module EnvironmentCollector
33
+ class << self
34
+ def collect_config!
35
+ {
36
+ enabled: enabled,
37
+ agent_url: agent_url,
38
+ analytics_enabled: analytics_enabled,
39
+ sample_rate: sample_rate,
40
+ sampling_rules: sampling_rules,
41
+ integrations_loaded: integrations_loaded,
42
+ partial_flushing_enabled: partial_flushing_enabled,
43
+ priority_sampling_enabled: priority_sampling_enabled,
44
+ **instrumented_integrations_settings
45
+ }
46
+ end
47
+
48
+ def collect_errors!(responses)
49
+ {
50
+ agent_error: agent_error(responses)
51
+ }
52
+ end
53
+
54
+ # @return [Boolean, nil]
55
+ def enabled
56
+ !!Datadog.configuration.tracing.enabled
57
+ end
58
+
59
+ # @return [String, nil] target agent URL for trace flushing
60
+ def agent_url
61
+ # Retrieve the effect agent URL, regardless of how it was configured
62
+ transport = Tracing.send(:tracer).writer.transport
63
+
64
+ # return `nil` with IO transport
65
+ return unless transport.respond_to?(:client)
66
+
67
+ adapter = transport.client.api.adapter
68
+ adapter.url
69
+ end
70
+
71
+ # Error returned by Datadog agent during a tracer flush attempt
72
+ # @return [String] concatenated list of transport errors
73
+ def agent_error(responses)
74
+ error_responses = responses.reject(&:ok?)
75
+
76
+ return nil if error_responses.empty?
77
+
78
+ error_responses.map(&:inspect).join(',')
79
+ end
80
+
81
+ # @return [Boolean, nil] analytics enabled in configuration
82
+ def analytics_enabled
83
+ !!Datadog.configuration.tracing.analytics.enabled
84
+ end
85
+
86
+ # @return [Numeric, nil] tracer sample rate configured
87
+ def sample_rate
88
+ sampler = Datadog.configuration.tracing.sampler
89
+ return nil unless sampler
90
+
91
+ sampler.sample_rate(nil) rescue nil
92
+ end
93
+
94
+ # DEV: We currently only support SimpleRule instances.
95
+ # DEV: These are the most commonly used rules.
96
+ # DEV: We should expand support for other rules in the future,
97
+ # DEV: although it is tricky to serialize arbitrary rules.
98
+ #
99
+ # @return [Hash, nil] sample rules configured
100
+ def sampling_rules
101
+ sampler = Datadog.configuration.tracing.sampler
102
+ return nil unless sampler.is_a?(Tracing::Sampling::PrioritySampler) &&
103
+ sampler.priority_sampler.is_a?(Tracing::Sampling::RuleSampler)
104
+
105
+ sampler.priority_sampler.rules.map do |rule|
106
+ next unless rule.is_a?(Tracing::Sampling::SimpleRule)
107
+
108
+ {
109
+ name: rule.matcher.name,
110
+ service: rule.matcher.service,
111
+ sample_rate: rule.sampler.sample_rate(nil)
112
+ }
113
+ end.compact
114
+ end
115
+
116
+ # Concatenated list of integrations activated, with their gem version.
117
+ # Example: "rails@6.0.3,rack@2.2.3"
118
+ #
119
+ # @return [String, nil]
120
+ def integrations_loaded
121
+ integrations = instrumented_integrations
122
+ return if integrations.empty?
123
+
124
+ integrations.map { |name, integration| "#{name}@#{integration.class.version}" }.join(',')
125
+ end
126
+
127
+ # @return [Boolean, nil] partial flushing enabled in configuration
128
+ def partial_flushing_enabled
129
+ !!Datadog.configuration.tracing.partial_flush.enabled
130
+ end
131
+
132
+ # @return [Boolean, nil] priority sampling enabled in configuration
133
+ def priority_sampling_enabled
134
+ !!Datadog.configuration.tracing.priority_sampling
135
+ end
136
+
137
+ private
138
+
139
+ def instrumented_integrations
140
+ Datadog.configuration.tracing.instrumented_integrations
141
+ end
142
+
143
+ # Capture all active integration settings into "integrationName_settingName: value" entries.
144
+ def instrumented_integrations_settings
145
+ instrumented_integrations.flat_map do |name, integration|
146
+ integration.configuration.to_h.flat_map do |setting, value|
147
+ next [] if setting == :tracer # Skip internal Ruby objects
148
+
149
+ # Convert value to a string to avoid custom #to_json
150
+ # handlers possibly causing errors.
151
+ [[:"integration_#{name}_#{setting}", value.to_s]]
152
+ end
153
+ end.to_h
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+ end
@@ -57,7 +57,7 @@ module Datadog
57
57
  end
58
58
  end
59
59
 
60
- # TODO: Register `Datadog::Core::Diagnostics::EnvironmentLogger.log!`
60
+ # TODO: Register `Datadog::Tracing::Diagnostics::EnvironmentLogger.collect_and_log!`
61
61
  # TODO: as a flush_completed subscriber when the `TraceWriter`
62
62
  # TODO: instantiation code is implemented.
63
63
  def flush_completed
@@ -3,8 +3,8 @@
3
3
  module DDTrace
4
4
  module VERSION
5
5
  MAJOR = 1
6
- MINOR = 13
7
- PATCH = 1
6
+ MINOR = 14
7
+ PATCH = 0
8
8
  PRE = nil
9
9
  BUILD = nil
10
10
  # PRE and BUILD above are modified for dev gems during gem build GHA workflow
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddtrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.1
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Datadog, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-14 00:00:00.000000000 Z
11
+ date: 2023-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack
@@ -379,6 +379,7 @@ files:
379
379
  - lib/datadog/profiling/collectors/stack.rb
380
380
  - lib/datadog/profiling/collectors/thread_context.rb
381
381
  - lib/datadog/profiling/component.rb
382
+ - lib/datadog/profiling/diagnostics/environment_logger.rb
382
383
  - lib/datadog/profiling/encoding/profile.rb
383
384
  - lib/datadog/profiling/event.rb
384
385
  - lib/datadog/profiling/events/stack.rb
@@ -801,6 +802,7 @@ files:
801
802
  - lib/datadog/tracing/contrib/utils/quantization/hash.rb
802
803
  - lib/datadog/tracing/contrib/utils/quantization/http.rb
803
804
  - lib/datadog/tracing/correlation.rb
805
+ - lib/datadog/tracing/diagnostics/environment_logger.rb
804
806
  - lib/datadog/tracing/diagnostics/ext.rb
805
807
  - lib/datadog/tracing/diagnostics/health.rb
806
808
  - lib/datadog/tracing/distributed/b3_multi.rb
@@ -911,7 +913,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
911
913
  - !ruby/object:Gem::Version
912
914
  version: 2.0.0
913
915
  requirements: []
914
- rubygems_version: 3.4.10
916
+ rubygems_version: 3.4.5
915
917
  signing_key:
916
918
  specification_version: 4
917
919
  summary: Datadog tracing code for your Ruby applications