datadog 2.0.0.beta1 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +181 -1
- data/ext/datadog_profiling_native_extension/NativeExtensionDesign.md +1 -1
- data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +40 -32
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +23 -12
- data/ext/datadog_profiling_native_extension/crashtracker.c +108 -0
- data/ext/datadog_profiling_native_extension/extconf.rb +9 -23
- data/ext/datadog_profiling_native_extension/heap_recorder.c +81 -4
- data/ext/datadog_profiling_native_extension/heap_recorder.h +12 -1
- data/ext/datadog_profiling_native_extension/http_transport.c +1 -94
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.c +86 -0
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.h +4 -0
- data/ext/datadog_profiling_native_extension/native_extension_helpers.rb +2 -12
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +25 -86
- data/ext/datadog_profiling_native_extension/profiling.c +2 -0
- data/ext/datadog_profiling_native_extension/ruby_helpers.h +3 -5
- data/ext/datadog_profiling_native_extension/stack_recorder.c +161 -62
- data/lib/datadog/appsec/contrib/devise/tracking.rb +8 -0
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +43 -13
- data/lib/datadog/appsec/event.rb +2 -2
- data/lib/datadog/core/configuration/components.rb +2 -1
- data/lib/datadog/core/configuration/option.rb +7 -5
- data/lib/datadog/core/configuration/settings.rb +34 -79
- data/lib/datadog/core/configuration.rb +20 -4
- data/lib/datadog/core/environment/platform.rb +7 -1
- data/lib/datadog/core/remote/client/capabilities.rb +2 -1
- data/lib/datadog/core/remote/client.rb +1 -5
- data/lib/datadog/core/remote/configuration/repository.rb +1 -1
- data/lib/datadog/core/remote/dispatcher.rb +3 -3
- data/lib/datadog/core/remote/transport/http/config.rb +5 -5
- data/lib/datadog/core/telemetry/client.rb +18 -10
- data/lib/datadog/core/telemetry/emitter.rb +9 -13
- data/lib/datadog/core/telemetry/event.rb +247 -57
- data/lib/datadog/core/telemetry/ext.rb +1 -0
- data/lib/datadog/core/telemetry/heartbeat.rb +1 -3
- data/lib/datadog/core/telemetry/http/ext.rb +4 -1
- data/lib/datadog/core/telemetry/http/response.rb +4 -0
- data/lib/datadog/core/telemetry/http/transport.rb +9 -4
- data/lib/datadog/core/telemetry/request.rb +59 -0
- data/lib/datadog/core/utils/base64.rb +22 -0
- data/lib/datadog/opentelemetry/sdk/span_processor.rb +19 -2
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +3 -17
- data/lib/datadog/profiling/collectors/code_provenance.rb +10 -4
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +25 -0
- data/lib/datadog/profiling/component.rb +49 -17
- data/lib/datadog/profiling/crashtracker.rb +91 -0
- data/lib/datadog/profiling/exporter.rb +6 -3
- data/lib/datadog/profiling/http_transport.rb +7 -11
- data/lib/datadog/profiling/load_native_extension.rb +14 -1
- data/lib/datadog/profiling/profiler.rb +9 -2
- data/lib/datadog/profiling/stack_recorder.rb +6 -2
- data/lib/datadog/profiling.rb +12 -0
- data/lib/datadog/tracing/component.rb +5 -1
- data/lib/datadog/tracing/configuration/dynamic.rb +39 -1
- data/lib/datadog/tracing/configuration/settings.rb +1 -0
- data/lib/datadog/tracing/contrib/action_pack/integration.rb +1 -1
- data/lib/datadog/tracing/contrib/action_view/integration.rb +1 -1
- data/lib/datadog/tracing/contrib/active_record/configuration/resolver.rb +1 -0
- data/lib/datadog/tracing/contrib/active_record/integration.rb +11 -1
- data/lib/datadog/tracing/contrib/active_support/integration.rb +1 -1
- data/lib/datadog/tracing/contrib/configuration/resolver.rb +43 -0
- data/lib/datadog/tracing/contrib/grape/endpoint.rb +43 -5
- data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +1 -1
- data/lib/datadog/tracing/correlation.rb +3 -4
- data/lib/datadog/tracing/remote.rb +5 -1
- data/lib/datadog/tracing/sampling/ext.rb +5 -1
- data/lib/datadog/tracing/sampling/matcher.rb +75 -26
- data/lib/datadog/tracing/sampling/rule.rb +27 -4
- data/lib/datadog/tracing/sampling/rule_sampler.rb +19 -1
- data/lib/datadog/tracing/sampling/span/matcher.rb +13 -41
- data/lib/datadog/tracing/span.rb +7 -2
- data/lib/datadog/tracing/span_link.rb +92 -0
- data/lib/datadog/tracing/span_operation.rb +6 -4
- data/lib/datadog/tracing/trace_operation.rb +12 -0
- data/lib/datadog/tracing/tracer.rb +4 -3
- data/lib/datadog/tracing/transport/serializable_trace.rb +3 -1
- data/lib/datadog/tracing/utils.rb +16 -0
- data/lib/datadog/version.rb +1 -1
- metadata +10 -31
- data/lib/datadog/core/telemetry/collector.rb +0 -248
- data/lib/datadog/core/telemetry/v1/app_event.rb +0 -59
- data/lib/datadog/core/telemetry/v1/application.rb +0 -94
- data/lib/datadog/core/telemetry/v1/configuration.rb +0 -27
- data/lib/datadog/core/telemetry/v1/dependency.rb +0 -45
- data/lib/datadog/core/telemetry/v1/host.rb +0 -59
- data/lib/datadog/core/telemetry/v1/install_signature.rb +0 -38
- data/lib/datadog/core/telemetry/v1/integration.rb +0 -66
- data/lib/datadog/core/telemetry/v1/product.rb +0 -36
- data/lib/datadog/core/telemetry/v1/telemetry_request.rb +0 -108
- data/lib/datadog/core/telemetry/v2/app_client_configuration_change.rb +0 -41
- data/lib/datadog/core/telemetry/v2/request.rb +0 -29
@@ -1,81 +1,271 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'collector'
|
4
|
-
require_relative 'v1/app_event'
|
5
|
-
require_relative 'v1/telemetry_request'
|
6
|
-
require_relative 'v2/app_client_configuration_change'
|
7
|
-
|
8
3
|
module Datadog
|
9
4
|
module Core
|
10
5
|
module Telemetry
|
11
|
-
# Class defining methods to construct a Telemetry event
|
12
6
|
class Event
|
13
|
-
|
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; end
|
13
|
+
|
14
|
+
# The JSON payload for the event.
|
15
|
+
# @param seq_id [Integer] The sequence ID for the event.
|
16
|
+
def payload(seq_id)
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Telemetry class for the 'app-started' event
|
22
|
+
class AppStarted < Base
|
23
|
+
def type
|
24
|
+
'app-started'
|
25
|
+
end
|
26
|
+
|
27
|
+
def payload(seq_id)
|
28
|
+
@seq_id = seq_id
|
29
|
+
{
|
30
|
+
products: products,
|
31
|
+
configuration: configuration,
|
32
|
+
install_signature: install_signature,
|
33
|
+
# DEV: Not implemented yet
|
34
|
+
# error: error, # Start-up errors
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def products
|
41
|
+
products = {
|
42
|
+
appsec: {
|
43
|
+
enabled: Datadog::AppSec.enabled?,
|
44
|
+
},
|
45
|
+
profiler: {
|
46
|
+
enabled: Datadog::Profiling.enabled?,
|
47
|
+
},
|
48
|
+
# DEV: Not implemented yet
|
49
|
+
# dynamic_instrumentation: {
|
50
|
+
# enabled: true,
|
51
|
+
# }
|
52
|
+
}
|
53
|
+
|
54
|
+
if (unsupported_reason = Datadog::Profiling.unsupported_reason)
|
55
|
+
products[:profiler][:error] = {
|
56
|
+
code: 1, # Error code. 0 if no error.
|
57
|
+
message: unsupported_reason,
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
products
|
62
|
+
end
|
63
|
+
|
64
|
+
TARGET_OPTIONS = %w[
|
65
|
+
logger.level
|
66
|
+
profiling.advanced.code_provenance_enabled
|
67
|
+
profiling.advanced.endpoint.collection.enabled
|
68
|
+
profiling.enabled
|
69
|
+
runtime_metrics.enabled
|
70
|
+
tracing.analytics.enabled
|
71
|
+
tracing.propagation_style_extract
|
72
|
+
tracing.propagation_style_inject
|
73
|
+
tracing.enabled
|
74
|
+
tracing.log_injection
|
75
|
+
tracing.partial_flush.enabled
|
76
|
+
tracing.partial_flush.min_spans_threshold
|
77
|
+
tracing.report_hostname
|
78
|
+
tracing.sampling.rate_limit
|
79
|
+
].freeze
|
80
|
+
|
81
|
+
# rubocop:disable Metrics/AbcSize
|
82
|
+
def configuration
|
83
|
+
config = Datadog.configuration
|
84
|
+
|
85
|
+
list = [
|
86
|
+
conf_value('DD_AGENT_HOST', config.agent.host),
|
87
|
+
conf_value('DD_AGENT_TRANSPORT', agent_transport(config)),
|
88
|
+
conf_value('DD_TRACE_SAMPLE_RATE', to_value(config.tracing.sampling.default_rate)),
|
89
|
+
conf_value(
|
90
|
+
'DD_TRACE_REMOVE_INTEGRATION_SERVICE_NAMES_ENABLED',
|
91
|
+
config.tracing.contrib.global_default_service_name.enabled
|
92
|
+
),
|
93
|
+
]
|
14
94
|
|
15
|
-
|
95
|
+
peer_service_mapping_str = ''
|
96
|
+
unless config.tracing.contrib.peer_service_mapping.empty?
|
97
|
+
peer_service_mapping = config.tracing.contrib.peer_service_mapping
|
98
|
+
peer_service_mapping_str = peer_service_mapping.map { |key, value| "#{key}:#{value}" }.join(',')
|
99
|
+
end
|
100
|
+
list << conf_value('DD_TRACE_PEER_SERVICE_MAPPING', peer_service_mapping_str)
|
16
101
|
|
17
|
-
|
18
|
-
|
102
|
+
# Whitelist of configuration options to send in additional payload object
|
103
|
+
TARGET_OPTIONS.each do |option|
|
104
|
+
split_option = option.split('.')
|
105
|
+
list << conf_value(option, to_value(config.dig(*split_option)))
|
106
|
+
end
|
107
|
+
|
108
|
+
# Add some more custom additional payload values here
|
109
|
+
list.push(
|
110
|
+
conf_value('tracing.auto_instrument.enabled', !defined?(Datadog::AutoInstrument::LOADED).nil?),
|
111
|
+
conf_value('tracing.writer_options.buffer_size', to_value(config.tracing.writer_options[:buffer_size])),
|
112
|
+
conf_value('tracing.writer_options.flush_interval', to_value(config.tracing.writer_options[:flush_interval])),
|
113
|
+
conf_value('tracing.opentelemetry.enabled', !defined?(Datadog::OpenTelemetry::LOADED).nil?),
|
114
|
+
)
|
115
|
+
list << conf_value('logger.instance', config.logger.instance.class.to_s) if config.logger.instance
|
116
|
+
list << conf_value('appsec.enabled', config.dig('appsec', 'enabled')) if config.respond_to?('appsec')
|
117
|
+
list << conf_value('ci.enabled', config.dig('ci', 'enabled')) if config.respond_to?('ci')
|
118
|
+
|
119
|
+
list.reject! { |entry| entry[:value].nil? }
|
120
|
+
list
|
121
|
+
end
|
122
|
+
# rubocop:enable Metrics/AbcSize
|
123
|
+
|
124
|
+
def agent_transport(config)
|
125
|
+
adapter = Core::Configuration::AgentSettingsResolver.call(config).adapter
|
126
|
+
if adapter == Datadog::Core::Transport::Ext::UnixSocket::ADAPTER
|
127
|
+
'UDS'
|
128
|
+
else
|
129
|
+
'TCP'
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def conf_value(name, value, origin = 'code')
|
134
|
+
{
|
135
|
+
name: name,
|
136
|
+
value: value,
|
137
|
+
origin: origin,
|
138
|
+
seq_id: @seq_id,
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
142
|
+
def to_value(value)
|
143
|
+
# TODO: Add float if telemetry starts accepting it
|
144
|
+
case value
|
145
|
+
when Integer, String, true, false, nil
|
146
|
+
value
|
147
|
+
else
|
148
|
+
value.to_s
|
149
|
+
end
|
150
|
+
end
|
19
151
|
|
20
|
-
|
21
|
-
|
152
|
+
def install_signature
|
153
|
+
config = Datadog.configuration
|
154
|
+
{
|
155
|
+
install_id: config.dig('telemetry', 'install_id'),
|
156
|
+
install_type: config.dig('telemetry', 'install_type'),
|
157
|
+
install_time: config.dig('telemetry', 'install_time'),
|
158
|
+
}
|
159
|
+
end
|
22
160
|
end
|
23
161
|
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
162
|
+
# Telemetry class for the 'app-dependencies-loaded' event
|
163
|
+
class AppDependenciesLoaded < Base
|
164
|
+
def type
|
165
|
+
'app-dependencies-loaded'
|
166
|
+
end
|
167
|
+
|
168
|
+
def payload(seq_id)
|
169
|
+
{ dependencies: dependencies }
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
|
174
|
+
def dependencies
|
175
|
+
Gem.loaded_specs.collect do |name, gem|
|
176
|
+
{
|
177
|
+
name: name,
|
178
|
+
version: gem.version.to_s,
|
179
|
+
# hash: nil,
|
180
|
+
}
|
181
|
+
end
|
182
|
+
end
|
39
183
|
end
|
40
184
|
|
41
|
-
|
185
|
+
# Telemetry class for the 'app-integrations-change' event
|
186
|
+
class AppIntegrationsChange < Base
|
187
|
+
def type
|
188
|
+
'app-integrations-change'
|
189
|
+
end
|
42
190
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
191
|
+
def payload(seq_id)
|
192
|
+
{ integrations: integrations }
|
193
|
+
end
|
194
|
+
|
195
|
+
private
|
196
|
+
|
197
|
+
def integrations
|
198
|
+
instrumented_integrations = Datadog.configuration.tracing.instrumented_integrations
|
199
|
+
Datadog.registry.map do |integration|
|
200
|
+
is_instrumented = instrumented_integrations.include?(integration.name)
|
201
|
+
|
202
|
+
is_enabled = is_instrumented ? !!integration.klass.patcher.patch_successful : false
|
203
|
+
|
204
|
+
version = integration.klass.class.version ? integration.klass.class.version.to_s : nil
|
205
|
+
|
206
|
+
res = {
|
207
|
+
name: integration.name.to_s,
|
208
|
+
enabled: is_enabled,
|
209
|
+
version: version,
|
210
|
+
compatible: integration.klass.class.compatible?,
|
211
|
+
error: (patch_error(integration) if is_instrumented && !is_enabled),
|
212
|
+
# TODO: Track if integration is instrumented by manual configuration or by auto instrumentation
|
213
|
+
# auto_enabled: is_enabled && ???,
|
214
|
+
}
|
215
|
+
res.reject! { |_, v| v.nil? }
|
216
|
+
res
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def patch_error(integration)
|
221
|
+
patch_error_result = integration.klass.patcher.patch_error_result
|
222
|
+
return patch_error_result.compact.to_s if patch_error_result
|
223
|
+
|
224
|
+
# If no error occurred during patching, but integration is still not instrumented
|
225
|
+
"Available?: #{integration.klass.class.available?}" \
|
226
|
+
", Loaded? #{integration.klass.class.loaded?}" \
|
227
|
+
", Compatible? #{integration.klass.class.compatible?}" \
|
228
|
+
", Patchable? #{integration.klass.class.patchable?}"
|
55
229
|
end
|
56
230
|
end
|
57
231
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
232
|
+
# Telemetry class for the 'app-client-configuration-change' event
|
233
|
+
class AppClientConfigurationChange < Base
|
234
|
+
def type
|
235
|
+
'app-client-configuration-change'
|
236
|
+
end
|
237
|
+
|
238
|
+
def initialize(changes, origin)
|
239
|
+
super()
|
240
|
+
@changes = changes
|
241
|
+
@origin = origin
|
242
|
+
end
|
243
|
+
|
244
|
+
def payload(seq_id)
|
245
|
+
{
|
246
|
+
configuration: @changes.map do |name, value|
|
247
|
+
{
|
248
|
+
name: name,
|
249
|
+
value: value,
|
250
|
+
origin: @origin,
|
251
|
+
}
|
252
|
+
end
|
253
|
+
}
|
254
|
+
end
|
66
255
|
end
|
67
256
|
|
68
|
-
|
69
|
-
|
257
|
+
# Telemetry class for the 'app-heartbeat' event
|
258
|
+
class AppHeartbeat < Base
|
259
|
+
def type
|
260
|
+
'app-heartbeat'
|
261
|
+
end
|
70
262
|
end
|
71
263
|
|
72
|
-
#
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
def app_client_configuration_change(data)
|
78
|
-
Telemetry::V2::AppClientConfigurationChange.new(data[:changes], origin: data[:origin])
|
264
|
+
# Telemetry class for the 'app-closing' event
|
265
|
+
class AppClosing < Base
|
266
|
+
def type
|
267
|
+
'app-closing'
|
268
|
+
end
|
79
269
|
end
|
80
270
|
end
|
81
271
|
end
|
@@ -6,6 +6,7 @@ module Datadog
|
|
6
6
|
module Ext
|
7
7
|
ENV_ENABLED = 'DD_INSTRUMENTATION_TELEMETRY_ENABLED'
|
8
8
|
ENV_HEARTBEAT_INTERVAL = 'DD_TELEMETRY_HEARTBEAT_INTERVAL'
|
9
|
+
ENV_DEPENDENCY_COLLECTION = 'DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED'
|
9
10
|
ENV_INSTALL_ID = 'DD_INSTRUMENTATION_INSTALL_ID'
|
10
11
|
ENV_INSTALL_TYPE = 'DD_INSTRUMENTATION_INSTALL_TYPE'
|
11
12
|
ENV_INSTALL_TIME = 'DD_INSTRUMENTATION_INSTALL_TIME'
|
@@ -10,9 +10,12 @@ module Datadog
|
|
10
10
|
HEADER_CONTENT_LENGTH = 'Content-Length'
|
11
11
|
HEADER_DD_TELEMETRY_API_VERSION = 'DD-Telemetry-API-Version'
|
12
12
|
HEADER_DD_TELEMETRY_REQUEST_TYPE = 'DD-Telemetry-Request-Type'
|
13
|
+
HEADER_TELEMETRY_DEBUG_ENABLED = 'DD-Telemetry-Debug-Enabled'
|
14
|
+
HEADER_CLIENT_LIBRARY_LANGUAGE = 'DD-Client-Library-Language'
|
15
|
+
HEADER_CLIENT_LIBRARY_VERSION = 'DD-Client-Library-Version'
|
13
16
|
|
14
17
|
CONTENT_TYPE_APPLICATION_JSON = 'application/json'
|
15
|
-
API_VERSION = '
|
18
|
+
API_VERSION = 'v2'
|
16
19
|
|
17
20
|
AGENT_ENDPOINT = '/telemetry/proxy/api/v2/apmtelemetry'
|
18
21
|
end
|
@@ -39,10 +39,15 @@ module Datadog
|
|
39
39
|
|
40
40
|
def headers(request_type:, api_version: Http::Ext::API_VERSION)
|
41
41
|
{
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
Core::Transport::Ext::HTTP::HEADER_DD_INTERNAL_UNTRACED_REQUEST => '1',
|
43
|
+
Ext::HEADER_CONTENT_TYPE => Http::Ext::CONTENT_TYPE_APPLICATION_JSON,
|
44
|
+
Ext::HEADER_DD_TELEMETRY_API_VERSION => api_version,
|
45
|
+
Ext::HEADER_DD_TELEMETRY_REQUEST_TYPE => request_type,
|
46
|
+
Ext::HEADER_CLIENT_LIBRARY_LANGUAGE => Core::Environment::Ext::LANG,
|
47
|
+
Ext::HEADER_CLIENT_LIBRARY_VERSION => Core::Environment::Identity.gem_datadog_version_semver2,
|
48
|
+
|
49
|
+
# Enable debug mode for telemetry
|
50
|
+
# HEADER_TELEMETRY_DEBUG_ENABLED => 'true',
|
46
51
|
}
|
47
52
|
end
|
48
53
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../environment/platform'
|
4
|
+
require_relative '../utils/hash'
|
5
|
+
|
6
|
+
module Datadog
|
7
|
+
module Core
|
8
|
+
module Telemetry
|
9
|
+
# Module defining methods for collecting metadata for telemetry
|
10
|
+
module Request
|
11
|
+
class << self
|
12
|
+
using Core::Utils::Hash::Refinement
|
13
|
+
|
14
|
+
def build_payload(event, seq_id)
|
15
|
+
hash = {
|
16
|
+
api_version: Http::Ext::API_VERSION,
|
17
|
+
application: application,
|
18
|
+
debug: false,
|
19
|
+
host: host,
|
20
|
+
payload: event.payload(seq_id),
|
21
|
+
request_type: event.type,
|
22
|
+
runtime_id: Core::Environment::Identity.id,
|
23
|
+
seq_id: seq_id,
|
24
|
+
tracer_time: Time.now.to_i,
|
25
|
+
}
|
26
|
+
hash.compact!
|
27
|
+
hash
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def application
|
33
|
+
config = Datadog.configuration
|
34
|
+
{
|
35
|
+
env: config.env,
|
36
|
+
language_name: Core::Environment::Ext::LANG,
|
37
|
+
language_version: Core::Environment::Ext::LANG_VERSION,
|
38
|
+
runtime_name: Core::Environment::Ext::RUBY_ENGINE,
|
39
|
+
runtime_version: Core::Environment::Ext::ENGINE_VERSION,
|
40
|
+
service_name: config.service,
|
41
|
+
service_version: config.version,
|
42
|
+
tracer_version: Core::Environment::Identity.gem_datadog_version_semver2
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def host
|
47
|
+
{
|
48
|
+
architecture: Core::Environment::Platform.architecture,
|
49
|
+
hostname: Core::Environment::Platform.hostname,
|
50
|
+
kernel_name: Core::Environment::Platform.kernel_name,
|
51
|
+
kernel_release: Core::Environment::Platform.kernel_release,
|
52
|
+
kernel_version: Core::Environment::Platform.kernel_version
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Core
|
5
|
+
module Utils
|
6
|
+
# Helper methods for encoding and decoding base64
|
7
|
+
module Base64
|
8
|
+
def self.encode64(bin)
|
9
|
+
[bin].pack('m')
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.strict_encode64(bin)
|
13
|
+
[bin].pack('m0')
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.strict_decode64(str)
|
17
|
+
str.unpack1('m0')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'trace/span'
|
4
|
+
require_relative '../../tracing/span_link'
|
5
|
+
require_relative '../../tracing/trace_digest'
|
4
6
|
|
5
7
|
module Datadog
|
6
8
|
module OpenTelemetry
|
@@ -87,6 +89,21 @@ module Datadog
|
|
87
89
|
datadog_span.set_error([nil, span.status.description]) unless span.status.ok?
|
88
90
|
datadog_span.set_tags(span.attributes)
|
89
91
|
|
92
|
+
unless span.links.nil?
|
93
|
+
datadog_span.links = span.links.map do |link|
|
94
|
+
Datadog::Tracing::SpanLink.new(
|
95
|
+
Datadog::Tracing::TraceDigest.new(
|
96
|
+
trace_id: link.span_context.hex_trace_id.to_i(16),
|
97
|
+
span_id: link.span_context.hex_span_id.to_i(16),
|
98
|
+
trace_sampling_priority: (link.span_context.trace_flags&.sampled? ? 1 : 0),
|
99
|
+
trace_state: link.span_context.tracestate&.to_s,
|
100
|
+
span_remote: link.span_context.remote?,
|
101
|
+
),
|
102
|
+
attributes: link.attributes
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
90
107
|
datadog_span
|
91
108
|
end
|
92
109
|
|
@@ -115,11 +132,11 @@ module Datadog
|
|
115
132
|
|
116
133
|
# DEV: There's no `flat_map!`; we have to split it into two operations
|
117
134
|
attributes = attributes.map do |key, value|
|
118
|
-
Datadog::
|
135
|
+
Datadog::Tracing::Utils.serialize_attribute(key, value)
|
119
136
|
end
|
120
137
|
attributes.flatten!(1)
|
121
138
|
|
122
|
-
kwargs[:tags] = attributes
|
139
|
+
kwargs[:tags] = attributes.to_h
|
123
140
|
|
124
141
|
[name, kwargs]
|
125
142
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'datadog/tracing/utils'
|
4
|
+
|
3
5
|
module Datadog
|
4
6
|
module OpenTelemetry
|
5
7
|
module Trace
|
@@ -36,22 +38,6 @@ module Datadog
|
|
36
38
|
span.set_error(status.description) if status && status.code == ::OpenTelemetry::Trace::Status::ERROR
|
37
39
|
end
|
38
40
|
|
39
|
-
# Serialize values into Datadog span tags and metrics.
|
40
|
-
# Notably, arrays are exploded into many keys, each with
|
41
|
-
# a numeric suffix representing the array index, for example:
|
42
|
-
# `'foo' => ['a','b']` becomes `'foo.0' => 'a', 'foo.1' => 'b'`
|
43
|
-
def self.serialize_attribute(key, value)
|
44
|
-
if value.is_a?(Array)
|
45
|
-
value.flat_map.with_index do |v, idx|
|
46
|
-
serialize_attribute("#{key}.#{idx}", v)
|
47
|
-
end
|
48
|
-
elsif value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
49
|
-
[[key, value.to_s]]
|
50
|
-
else
|
51
|
-
[[key, value]]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
41
|
# Create a meaningful Datadog operation name from the OpenTelemetry
|
56
42
|
# semantic convention for span kind and span attributes.
|
57
43
|
# @see https://opentelemetry.io/docs/specs/semconv/general/trace/
|
@@ -123,7 +109,7 @@ module Datadog
|
|
123
109
|
span.name = rich_name.downcase
|
124
110
|
end
|
125
111
|
|
126
|
-
|
112
|
+
Tracing::Utils.serialize_attribute(key, @attributes[key]).each do |new_key, value|
|
127
113
|
override_datadog_values(span, new_key, value)
|
128
114
|
|
129
115
|
# When an attribute is used to override a Datadog Span property,
|
@@ -97,14 +97,20 @@ module Datadog
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
|
100
|
+
# Represents metadata we have for a ruby gem
|
101
|
+
class Library
|
102
|
+
attr_reader :kind, :name, :version, :path
|
103
|
+
|
101
104
|
def initialize(kind:, name:, version:, path:)
|
102
|
-
|
105
|
+
@kind = kind.freeze
|
106
|
+
@name = name.dup.freeze
|
107
|
+
@version = version.to_s.dup.freeze
|
108
|
+
@path = path.dup.freeze
|
103
109
|
freeze
|
104
110
|
end
|
105
111
|
|
106
|
-
def to_json(
|
107
|
-
{ kind: kind, name: name, version: version, paths: [path] }.to_json(
|
112
|
+
def to_json(arg = nil)
|
113
|
+
{ kind: @kind, name: @name, version: @version, paths: [@path] }.to_json(arg)
|
108
114
|
end
|
109
115
|
end
|
110
116
|
end
|
@@ -24,6 +24,7 @@ module Datadog
|
|
24
24
|
# **NOTE**: This should only be used for testing; disabling the dynamic sampling rate will increase the
|
25
25
|
# profiler overhead!
|
26
26
|
dynamic_sampling_rate_enabled: true,
|
27
|
+
skip_idle_samples_for_testing: false,
|
27
28
|
idle_sampling_helper: IdleSamplingHelper.new
|
28
29
|
)
|
29
30
|
unless dynamic_sampling_rate_enabled
|
@@ -41,11 +42,14 @@ module Datadog
|
|
41
42
|
dynamic_sampling_rate_enabled,
|
42
43
|
dynamic_sampling_rate_overhead_target_percentage,
|
43
44
|
allocation_profiling_enabled,
|
45
|
+
skip_idle_samples_for_testing,
|
44
46
|
)
|
45
47
|
@worker_thread = nil
|
46
48
|
@failure_exception = nil
|
47
49
|
@start_stop_mutex = Mutex.new
|
48
50
|
@idle_sampling_helper = idle_sampling_helper
|
51
|
+
@wait_until_running_mutex = Mutex.new
|
52
|
+
@wait_until_running_condition = ConditionVariable.new
|
49
53
|
end
|
50
54
|
|
51
55
|
def start(on_failure_proc: nil)
|
@@ -108,6 +112,27 @@ module Datadog
|
|
108
112
|
self.class._native_stats_reset_not_thread_safe(self)
|
109
113
|
stats
|
110
114
|
end
|
115
|
+
|
116
|
+
# Useful for testing, to e.g. make sure the profiler is running before we start running some code we want to observe
|
117
|
+
def wait_until_running(timeout_seconds: 5)
|
118
|
+
@wait_until_running_mutex.synchronize do
|
119
|
+
return true if self.class._native_is_running?(self)
|
120
|
+
|
121
|
+
@wait_until_running_condition.wait(@wait_until_running_mutex, timeout_seconds)
|
122
|
+
|
123
|
+
if self.class._native_is_running?(self)
|
124
|
+
true
|
125
|
+
else
|
126
|
+
raise "Timeout waiting for #{self.class.name} to start (waited for #{timeout_seconds} seconds)"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def signal_running
|
134
|
+
@wait_until_running_mutex.synchronize { @wait_until_running_condition.broadcast }
|
135
|
+
end
|
111
136
|
end
|
112
137
|
end
|
113
138
|
end
|