datadog 2.16.0 → 2.17.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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -1
  3. data/ext/datadog_profiling_native_extension/encoded_profile.c +22 -12
  4. data/ext/datadog_profiling_native_extension/encoded_profile.h +1 -0
  5. data/ext/datadog_profiling_native_extension/http_transport.c +45 -72
  6. data/ext/datadog_profiling_native_extension/stack_recorder.c +4 -5
  7. data/ext/libdatadog_api/crashtracker.c +10 -3
  8. data/ext/libdatadog_api/macos_development.md +3 -3
  9. data/ext/libdatadog_extconf_helpers.rb +1 -1
  10. data/lib/datadog/appsec/api_security/lru_cache.rb +49 -0
  11. data/lib/datadog/appsec/api_security.rb +9 -0
  12. data/lib/datadog/core/buffer/random.rb +18 -2
  13. data/lib/datadog/core/configuration/agent_settings_resolver.rb +5 -5
  14. data/lib/datadog/core/configuration/components.rb +29 -20
  15. data/lib/datadog/core/configuration/components_state.rb +23 -0
  16. data/lib/datadog/core/configuration/option.rb +18 -18
  17. data/lib/datadog/core/configuration/option_definition.rb +4 -4
  18. data/lib/datadog/core/configuration/options.rb +1 -1
  19. data/lib/datadog/core/configuration/settings.rb +10 -10
  20. data/lib/datadog/core/configuration.rb +16 -16
  21. data/lib/datadog/core/crashtracking/component.rb +2 -1
  22. data/lib/datadog/core/encoding.rb +1 -1
  23. data/lib/datadog/core/environment/cgroup.rb +10 -12
  24. data/lib/datadog/core/environment/container.rb +38 -40
  25. data/lib/datadog/core/environment/ext.rb +6 -6
  26. data/lib/datadog/core/environment/identity.rb +3 -3
  27. data/lib/datadog/core/environment/platform.rb +3 -3
  28. data/lib/datadog/core/error.rb +11 -9
  29. data/lib/datadog/core/logger.rb +2 -2
  30. data/lib/datadog/core/metrics/client.rb +12 -14
  31. data/lib/datadog/core/metrics/logging.rb +5 -5
  32. data/lib/datadog/core/rate_limiter.rb +4 -2
  33. data/lib/datadog/core/remote/client.rb +32 -31
  34. data/lib/datadog/core/remote/component.rb +3 -3
  35. data/lib/datadog/core/remote/configuration/digest.rb +7 -7
  36. data/lib/datadog/core/remote/configuration/path.rb +1 -1
  37. data/lib/datadog/core/remote/transport/http/client.rb +1 -1
  38. data/lib/datadog/core/remote/transport/http/config.rb +21 -5
  39. data/lib/datadog/core/remote/transport/http/negotiation.rb +1 -1
  40. data/lib/datadog/core/runtime/metrics.rb +3 -3
  41. data/lib/datadog/core/telemetry/component.rb +39 -24
  42. data/lib/datadog/core/telemetry/emitter.rb +7 -1
  43. data/lib/datadog/core/telemetry/event/app_client_configuration_change.rb +65 -0
  44. data/lib/datadog/core/telemetry/event/app_closing.rb +18 -0
  45. data/lib/datadog/core/telemetry/event/app_dependencies_loaded.rb +33 -0
  46. data/lib/datadog/core/telemetry/event/app_heartbeat.rb +18 -0
  47. data/lib/datadog/core/telemetry/event/app_integrations_change.rb +58 -0
  48. data/lib/datadog/core/telemetry/event/app_started.rb +179 -0
  49. data/lib/datadog/core/telemetry/event/base.rb +40 -0
  50. data/lib/datadog/core/telemetry/event/distributions.rb +18 -0
  51. data/lib/datadog/core/telemetry/event/generate_metrics.rb +43 -0
  52. data/lib/datadog/core/telemetry/event/log.rb +76 -0
  53. data/lib/datadog/core/telemetry/event/message_batch.rb +42 -0
  54. data/lib/datadog/core/telemetry/event/synth_app_client_configuration_change.rb +43 -0
  55. data/lib/datadog/core/telemetry/event.rb +17 -475
  56. data/lib/datadog/core/telemetry/logger.rb +1 -1
  57. data/lib/datadog/core/telemetry/metric.rb +3 -3
  58. data/lib/datadog/core/telemetry/transport/http/telemetry.rb +2 -2
  59. data/lib/datadog/core/telemetry/transport/telemetry.rb +0 -1
  60. data/lib/datadog/core/telemetry/worker.rb +48 -27
  61. data/lib/datadog/core/transport/http/adapters/test.rb +2 -1
  62. data/lib/datadog/core/transport/http/builder.rb +13 -13
  63. data/lib/datadog/core/utils/at_fork_monkey_patch.rb +6 -6
  64. data/lib/datadog/core/utils/duration.rb +32 -32
  65. data/lib/datadog/core/utils/forking.rb +2 -2
  66. data/lib/datadog/core/utils/network.rb +6 -6
  67. data/lib/datadog/core/utils/only_once_successful.rb +16 -5
  68. data/lib/datadog/core/utils/time.rb +10 -2
  69. data/lib/datadog/core/utils/truncation.rb +21 -0
  70. data/lib/datadog/core/vendor/multipart-post/multipart/post/composite_read_io.rb +1 -1
  71. data/lib/datadog/core/vendor/multipart-post/multipart/post/multipartable.rb +8 -8
  72. data/lib/datadog/core/vendor/multipart-post/multipart/post/parts.rb +7 -7
  73. data/lib/datadog/core/worker.rb +1 -1
  74. data/lib/datadog/core/workers/async.rb +9 -10
  75. data/lib/datadog/error_tracking/component.rb +2 -2
  76. data/lib/datadog/profiling/collectors/code_provenance.rb +1 -1
  77. data/lib/datadog/profiling/ext.rb +0 -1
  78. data/lib/datadog/profiling/flush.rb +1 -1
  79. data/lib/datadog/profiling/http_transport.rb +1 -6
  80. data/lib/datadog/profiling/scheduler.rb +8 -1
  81. data/lib/datadog/profiling/tag_builder.rb +1 -5
  82. data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +4 -1
  83. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +33 -0
  84. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +4 -0
  85. data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +2 -4
  86. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +10 -0
  87. data/lib/datadog/tracing/contrib/aws/parsed_context.rb +5 -1
  88. data/lib/datadog/tracing/contrib/http/instrumentation.rb +1 -5
  89. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +1 -5
  90. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +1 -5
  91. data/lib/datadog/tracing/contrib/patcher.rb +5 -2
  92. data/lib/datadog/tracing/contrib/support.rb +28 -0
  93. data/lib/datadog/tracing/metadata/errors.rb +4 -4
  94. data/lib/datadog/version.rb +1 -1
  95. metadata +23 -6
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Datadog
6
+ module Core
7
+ module Telemetry
8
+ module Event
9
+ # Telemetry class for the 'app-integrations-change' event
10
+ class AppIntegrationsChange < Base
11
+ def type
12
+ 'app-integrations-change'
13
+ end
14
+
15
+ def payload
16
+ {integrations: integrations}
17
+ end
18
+
19
+ private
20
+
21
+ def integrations
22
+ instrumented_integrations = Datadog.configuration.tracing.instrumented_integrations
23
+ Datadog.registry.map do |integration|
24
+ is_instrumented = instrumented_integrations.include?(integration.name)
25
+
26
+ is_enabled = is_instrumented && integration.klass.patcher.patch_successful
27
+
28
+ version = integration.klass.class.version&.to_s
29
+
30
+ res = {
31
+ name: integration.name.to_s,
32
+ enabled: is_enabled,
33
+ version: version,
34
+ compatible: integration.klass.class.compatible?,
35
+ error: (patch_error(integration) if is_instrumented && !is_enabled),
36
+ # TODO: Track if integration is instrumented by manual configuration or by auto instrumentation
37
+ # auto_enabled: is_enabled && ???,
38
+ }
39
+ res.reject! { |_, v| v.nil? }
40
+ res
41
+ end
42
+ end
43
+
44
+ def patch_error(integration)
45
+ patch_error_result = integration.klass.patcher.patch_error_result
46
+ return patch_error_result.compact.to_s if patch_error_result
47
+
48
+ # If no error occurred during patching, but integration is still not instrumented
49
+ "Available?: #{integration.klass.class.available?}" \
50
+ ", Loaded? #{integration.klass.class.loaded?}" \
51
+ ", Compatible? #{integration.klass.class.compatible?}" \
52
+ ", Patchable? #{integration.klass.class.patchable?}"
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,179 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Datadog
6
+ module Core
7
+ module Telemetry
8
+ module Event
9
+ # Telemetry class for the 'app-started' event
10
+ class AppStarted < Base
11
+ def type
12
+ 'app-started'
13
+ end
14
+
15
+ def payload
16
+ {
17
+ products: products,
18
+ configuration: configuration,
19
+ install_signature: install_signature,
20
+ # DEV: Not implemented yet
21
+ # error: error, # Start-up errors
22
+ }
23
+ end
24
+
25
+ private
26
+
27
+ def products
28
+ # @type var products: Hash[Symbol, Hash[Symbol, Object]]
29
+ products = {
30
+ appsec: {
31
+ enabled: Datadog::AppSec.enabled?,
32
+ },
33
+ profiler: {
34
+ enabled: Datadog::Profiling.enabled?,
35
+ },
36
+ dynamic_instrumentation: {
37
+ enabled: defined?(Datadog::DI) && Datadog::DI.respond_to?(:enabled?) && Datadog::DI.enabled?,
38
+ }
39
+ }
40
+
41
+ if (unsupported_reason = Datadog::Profiling.unsupported_reason)
42
+ products[:profiler][:error] = {
43
+ code: 1, # Error code. 0 if no error.
44
+ message: unsupported_reason,
45
+ }
46
+ end
47
+
48
+ products
49
+ end
50
+
51
+ TARGET_OPTIONS = %w[
52
+ dynamic_instrumentation.enabled
53
+ logger.level
54
+ profiling.advanced.code_provenance_enabled
55
+ profiling.advanced.endpoint.collection.enabled
56
+ profiling.enabled
57
+ runtime_metrics.enabled
58
+ tracing.analytics.enabled
59
+ tracing.propagation_style_extract
60
+ tracing.propagation_style_inject
61
+ tracing.enabled
62
+ tracing.log_injection
63
+ tracing.partial_flush.enabled
64
+ tracing.partial_flush.min_spans_threshold
65
+ tracing.report_hostname
66
+ tracing.sampling.rate_limit
67
+ ].freeze
68
+
69
+ # standard:disable Metrics/AbcSize
70
+ # standard:disable Metrics/MethodLength
71
+ def configuration
72
+ config = Datadog.configuration
73
+ seq_id = Event.configuration_sequence.next
74
+
75
+ list = [
76
+ conf_value('DD_GIT_REPOSITORY_URL', Core::Environment::Git.git_repository_url, seq_id, 'env_var'),
77
+ conf_value('DD_GIT_COMMIT_SHA', Core::Environment::Git.git_commit_sha, seq_id, 'env_var'),
78
+
79
+ conf_value('DD_AGENT_HOST', config.agent.host, seq_id),
80
+ conf_value('DD_AGENT_TRANSPORT', agent_transport(config), seq_id),
81
+ conf_value('DD_TRACE_SAMPLE_RATE', to_value(config.tracing.sampling.default_rate), seq_id),
82
+ conf_value(
83
+ 'DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED',
84
+ config.tracing.contrib.global_default_service_name.enabled,
85
+ seq_id
86
+ ),
87
+ conf_value(
88
+ 'DD_TRACE_PEER_SERVICE_DEFAULTS_ENABLED',
89
+ config.tracing.contrib.peer_service_defaults,
90
+ seq_id
91
+ ),
92
+ ]
93
+
94
+ peer_service_mapping_str = ''
95
+ unless config.tracing.contrib.peer_service_mapping.empty?
96
+ peer_service_mapping = config.tracing.contrib.peer_service_mapping
97
+ peer_service_mapping_str = peer_service_mapping.map { |key, value| "#{key}:#{value}" }.join(',')
98
+ end
99
+ list << conf_value('DD_TRACE_PEER_SERVICE_MAPPING', peer_service_mapping_str, seq_id)
100
+
101
+ # Whitelist of configuration options to send in additional payload object
102
+ TARGET_OPTIONS.each do |option|
103
+ split_option = option.split('.')
104
+ list << conf_value(option, to_value(config.dig(*split_option)), seq_id)
105
+ end
106
+
107
+ # Add some more custom additional payload values here
108
+ list.push(
109
+ conf_value('tracing.auto_instrument.enabled', !defined?(Datadog::AutoInstrument::LOADED).nil?, seq_id),
110
+ conf_value(
111
+ 'tracing.writer_options.buffer_size',
112
+ to_value(config.tracing.writer_options[:buffer_size]),
113
+ seq_id
114
+ ),
115
+ conf_value(
116
+ 'tracing.writer_options.flush_interval',
117
+ to_value(config.tracing.writer_options[:flush_interval]),
118
+ seq_id
119
+ ),
120
+ conf_value(
121
+ 'tracing.opentelemetry.enabled',
122
+ !defined?(Datadog::OpenTelemetry::LOADED).nil?,
123
+ seq_id
124
+ ),
125
+ )
126
+ list << conf_value('logger.instance', config.logger.instance.class.to_s, seq_id) if config.logger.instance
127
+ if config.respond_to?('appsec')
128
+ list << conf_value('appsec.enabled', config.dig('appsec', 'enabled'), seq_id)
129
+ list << conf_value('appsec.sca_enabled', config.dig('appsec', 'sca_enabled'), seq_id)
130
+ end
131
+ list << conf_value('ci.enabled', config.dig('ci', 'enabled'), seq_id) if config.respond_to?('ci')
132
+
133
+ list.reject! { |entry| entry[:value].nil? }
134
+ list
135
+ end
136
+ # standard:enable Metrics/AbcSize
137
+ # standard:enable Metrics/MethodLength
138
+
139
+ def agent_transport(config)
140
+ adapter = Core::Configuration::AgentSettingsResolver.call(config).adapter
141
+ if adapter == Datadog::Core::Transport::Ext::UnixSocket::ADAPTER
142
+ 'UDS'
143
+ else
144
+ 'TCP'
145
+ end
146
+ end
147
+
148
+ def conf_value(name, value, seq_id, origin = 'code')
149
+ {
150
+ name: name,
151
+ value: value,
152
+ origin: origin,
153
+ seq_id: seq_id,
154
+ }
155
+ end
156
+
157
+ def to_value(value)
158
+ # TODO: Add float if telemetry starts accepting it
159
+ case value
160
+ when Integer, String, true, false, nil
161
+ value
162
+ else
163
+ value.to_s
164
+ end
165
+ end
166
+
167
+ def install_signature
168
+ config = Datadog.configuration
169
+ {
170
+ install_id: config.dig('telemetry', 'install_id'),
171
+ install_type: config.dig('telemetry', 'install_type'),
172
+ install_time: config.dig('telemetry', 'install_time'),
173
+ }
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module Core
5
+ module Telemetry
6
+ module Event
7
+ # Base class for all Telemetry V2 events.
8
+ class Base
9
+ # The type of the event.
10
+ # It must be one of the stings defined in the Telemetry V2
11
+ # specification for event names.
12
+ def type
13
+ raise NotImplementedError, 'Must be implemented by subclass'
14
+ end
15
+
16
+ # The JSON payload for the event.
17
+ def payload
18
+ {}
19
+ end
20
+
21
+ # Override equality to allow for deduplication
22
+ # The basic implementation is to check if the other object is an instance of the same class.
23
+ # This works for events that have no attributes.
24
+ # For events with attributes, you should override this method to compare the attributes.
25
+ def ==(other)
26
+ other.is_a?(self.class)
27
+ end
28
+
29
+ # @see #==
30
+ alias_method :eql?, :==
31
+
32
+ # @see #==
33
+ def hash
34
+ self.class.hash
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'generate_metrics'
4
+
5
+ module Datadog
6
+ module Core
7
+ module Telemetry
8
+ module Event
9
+ # Telemetry class for the 'distributions' event
10
+ class Distributions < GenerateMetrics
11
+ def type
12
+ 'distributions'
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Datadog
6
+ module Core
7
+ module Telemetry
8
+ module Event
9
+ # Telemetry class for the 'generate-metrics' event
10
+ class GenerateMetrics < Base
11
+ attr_reader :namespace, :metric_series
12
+
13
+ def type
14
+ 'generate-metrics'
15
+ end
16
+
17
+ def initialize(namespace, metric_series)
18
+ super()
19
+ @namespace = namespace
20
+ @metric_series = metric_series
21
+ end
22
+
23
+ def payload
24
+ {
25
+ namespace: @namespace,
26
+ series: @metric_series.map(&:to_h)
27
+ }
28
+ end
29
+
30
+ def ==(other)
31
+ other.is_a?(GenerateMetrics) && other.namespace == @namespace && other.metric_series == @metric_series
32
+ end
33
+
34
+ alias_method :eql?, :==
35
+
36
+ def hash
37
+ [self.class, @namespace, @metric_series].hash
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Datadog
6
+ module Core
7
+ module Telemetry
8
+ module Event
9
+ # Telemetry class for the 'logs' event.
10
+ # Logs with the same content are deduplicated at flush time.
11
+ class Log < Base
12
+ LEVELS = {
13
+ error: 'ERROR',
14
+ warn: 'WARN',
15
+ }.freeze
16
+
17
+ LEVELS_STRING = LEVELS.values.freeze
18
+
19
+ attr_reader :message, :level, :stack_trace, :count
20
+
21
+ def type
22
+ 'logs'
23
+ end
24
+
25
+ # @param message [String] the log message
26
+ # @param level [Symbol, String] the log level. Either :error, :warn, 'ERROR', or 'WARN'.
27
+ # @param stack_trace [String, nil] the stack trace
28
+ # @param count [Integer] the number of times the log was emitted. Used for deduplication.
29
+ def initialize(message:, level:, stack_trace: nil, count: 1)
30
+ super()
31
+ @message = message
32
+ @stack_trace = stack_trace
33
+
34
+ if level.is_a?(String) && LEVELS_STRING.include?(level)
35
+ # String level is used during object copy for deduplication
36
+ @level = level
37
+ elsif level.is_a?(Symbol)
38
+ # Symbol level is used by the regular log emitter user
39
+ @level = LEVELS.fetch(level) { |k| raise ArgumentError, "Invalid log level :#{k}" }
40
+ else
41
+ raise ArgumentError, "Invalid log level #{level}"
42
+ end
43
+
44
+ @count = count
45
+ end
46
+
47
+ def payload
48
+ {
49
+ logs: [
50
+ {
51
+ message: @message,
52
+ level: @level,
53
+ stack_trace: @stack_trace,
54
+ count: @count,
55
+ }.compact
56
+ ]
57
+ }
58
+ end
59
+
60
+ # override equality to allow for deduplication
61
+ def ==(other)
62
+ other.is_a?(Log) &&
63
+ other.message == @message &&
64
+ other.level == @level && other.stack_trace == @stack_trace && other.count == @count
65
+ end
66
+
67
+ alias_method :eql?, :==
68
+
69
+ def hash
70
+ [self.class, @message, @level, @stack_trace, @count].hash
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datadog
4
+ module Core
5
+ module Telemetry
6
+ module Event
7
+ # Telemetry class for the 'message-batch' event.
8
+ class MessageBatch < Base
9
+ attr_reader :events
10
+
11
+ def type
12
+ 'message-batch'
13
+ end
14
+
15
+ def initialize(events)
16
+ super()
17
+ @events = events
18
+ end
19
+
20
+ def payload
21
+ @events.map do |event|
22
+ {
23
+ request_type: event.type,
24
+ payload: event.payload,
25
+ }
26
+ end
27
+ end
28
+
29
+ def ==(other)
30
+ other.is_a?(MessageBatch) && other.events == @events
31
+ end
32
+
33
+ alias_method :eql?, :==
34
+
35
+ def hash
36
+ [self.class, @events].hash
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Datadog
6
+ module Core
7
+ module Telemetry
8
+ module Event
9
+ # app-client-configuration-change event emitted instead of
10
+ # app-started event for telemetry startups other than the initial
11
+ # one in a process.
12
+ #
13
+ # dd-trace-rb generally creates a new component tree whenever
14
+ # the tracer is reconfigured via Datadog.configure (with some
15
+ # components potentially reused, if their configuration has not
16
+ # changed). Telemetry system tests on the other hand expect there
17
+ # to be one "tracer" per process, and do not permit multiple
18
+ # app-started events to be emitted.
19
+ #
20
+ # To resolve this conflict, we replace second and onward app-started
21
+ # events with app-client-configuration-change events.
22
+ # To avoid diffing configuration, we send all parameters that are
23
+ # sent in app-started event.
24
+ #
25
+ # It's a "quick fix" on top of a not-so-quick fix that omitted
26
+ # second and subsequent app-started (and app-closing) events in the
27
+ # first place, and only works with the existing hackery of app-started
28
+ # and app-closing events.
29
+ class SynthAppClientConfigurationChange < AppStarted
30
+ def type
31
+ 'app-client-configuration-change'
32
+ end
33
+
34
+ def payload
35
+ {
36
+ configuration: configuration,
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end