ddtrace 1.8.0 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -1
  3. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +10 -10
  4. data/ext/ddtrace_profiling_native_extension/collectors_stack.c +32 -32
  5. data/ext/ddtrace_profiling_native_extension/collectors_stack.h +2 -2
  6. data/ext/ddtrace_profiling_native_extension/http_transport.c +50 -49
  7. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +5 -1
  8. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +34 -12
  9. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +10 -0
  10. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +32 -32
  11. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +4 -4
  12. data/lib/datadog/appsec/assets/waf_rules/recommended.json +75 -8
  13. data/lib/datadog/appsec/assets/waf_rules/risky.json +1 -1
  14. data/lib/datadog/appsec/assets/waf_rules/strict.json +1 -1
  15. data/lib/datadog/appsec/assets.rb +1 -1
  16. data/lib/datadog/appsec/configuration/settings.rb +35 -22
  17. data/lib/datadog/appsec/configuration.rb +4 -2
  18. data/lib/datadog/appsec/contrib/auto_instrument.rb +1 -1
  19. data/lib/datadog/appsec/contrib/configuration/settings.rb +1 -1
  20. data/lib/datadog/appsec/contrib/integration.rb +1 -1
  21. data/lib/datadog/appsec/contrib/patcher.rb +1 -1
  22. data/lib/datadog/appsec/contrib/rack/configuration/settings.rb +1 -1
  23. data/lib/datadog/appsec/contrib/rack/ext.rb +1 -1
  24. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +1 -1
  25. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +1 -1
  26. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +1 -1
  27. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +1 -1
  28. data/lib/datadog/appsec/contrib/rack/request.rb +1 -1
  29. data/lib/datadog/appsec/contrib/rack/response.rb +1 -1
  30. data/lib/datadog/appsec/contrib/rails/configuration/settings.rb +1 -1
  31. data/lib/datadog/appsec/contrib/rails/ext.rb +1 -1
  32. data/lib/datadog/appsec/contrib/rails/framework.rb +1 -1
  33. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +1 -1
  34. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +1 -1
  35. data/lib/datadog/appsec/contrib/rails/request.rb +1 -1
  36. data/lib/datadog/appsec/contrib/rails/request_middleware.rb +1 -1
  37. data/lib/datadog/appsec/contrib/sinatra/configuration/settings.rb +1 -1
  38. data/lib/datadog/appsec/contrib/sinatra/ext.rb +1 -1
  39. data/lib/datadog/appsec/contrib/sinatra/framework.rb +1 -1
  40. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +1 -1
  41. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +1 -1
  42. data/lib/datadog/appsec/contrib/sinatra/request_middleware.rb +1 -1
  43. data/lib/datadog/appsec/event.rb +1 -1
  44. data/lib/datadog/appsec/extensions.rb +36 -26
  45. data/lib/datadog/appsec/instrumentation/gateway.rb +3 -3
  46. data/lib/datadog/appsec/processor.rb +15 -19
  47. data/lib/datadog/appsec/rate_limiter.rb +1 -1
  48. data/lib/datadog/appsec/reactive/address_hash.rb +1 -1
  49. data/lib/datadog/appsec/reactive/engine.rb +1 -1
  50. data/lib/datadog/appsec/reactive/operation.rb +2 -2
  51. data/lib/datadog/appsec/reactive/subscriber.rb +1 -1
  52. data/lib/datadog/appsec/response.rb +18 -9
  53. data/lib/datadog/appsec/utils/http/media_range.rb +201 -0
  54. data/lib/datadog/appsec/utils/http/media_type.rb +87 -0
  55. data/lib/datadog/appsec/utils/http.rb +9 -0
  56. data/lib/datadog/appsec/utils.rb +7 -0
  57. data/lib/datadog/appsec.rb +1 -1
  58. data/lib/datadog/ci/ext/environment.rb +57 -13
  59. data/lib/datadog/core/configuration/agent_settings_resolver.rb +2 -2
  60. data/lib/datadog/core/configuration/base.rb +3 -0
  61. data/lib/datadog/core/configuration/ext.rb +8 -0
  62. data/lib/datadog/core/configuration/option_definition.rb +11 -2
  63. data/lib/datadog/core/configuration/settings.rb +6 -4
  64. data/lib/datadog/core/diagnostics/environment_logger.rb +4 -3
  65. data/lib/datadog/core/metrics/client.rb +3 -2
  66. data/lib/datadog/core/metrics/ext.rb +0 -2
  67. data/lib/datadog/core/telemetry/collector.rb +1 -0
  68. data/lib/datadog/kit/appsec/events.rb +75 -0
  69. data/lib/datadog/kit/enable_core_dumps.rb +1 -0
  70. data/lib/datadog/kit/identity.rb +8 -7
  71. data/lib/datadog/opentelemetry/api/context.rb +187 -0
  72. data/lib/datadog/opentelemetry/api/trace/span.rb +15 -0
  73. data/lib/datadog/opentelemetry/sdk/configurator.rb +38 -0
  74. data/lib/datadog/opentelemetry/sdk/id_generator.rb +27 -0
  75. data/lib/datadog/opentelemetry/sdk/propagator.rb +91 -0
  76. data/lib/datadog/opentelemetry/sdk/span_processor.rb +92 -0
  77. data/lib/datadog/opentelemetry.rb +48 -0
  78. data/lib/datadog/tracing/configuration/ext.rb +1 -2
  79. data/lib/datadog/tracing/contrib/http/configuration/settings.rb +5 -0
  80. data/lib/datadog/tracing/contrib/http/distributed/fetcher.rb +10 -3
  81. data/lib/datadog/tracing/contrib/http/ext.rb +1 -0
  82. data/lib/datadog/tracing/contrib/http/instrumentation.rb +3 -6
  83. data/lib/datadog/tracing/contrib/httpclient/configuration/settings.rb +5 -0
  84. data/lib/datadog/tracing/contrib/httpclient/ext.rb +1 -0
  85. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +3 -4
  86. data/lib/datadog/tracing/contrib/httprb/configuration/settings.rb +5 -0
  87. data/lib/datadog/tracing/contrib/httprb/ext.rb +1 -0
  88. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +3 -4
  89. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +44 -31
  90. data/lib/datadog/tracing/contrib/stripe/configuration/settings.rb +33 -0
  91. data/lib/datadog/tracing/contrib/stripe/ext.rb +26 -0
  92. data/lib/datadog/tracing/contrib/stripe/integration.rb +43 -0
  93. data/lib/datadog/tracing/contrib/stripe/patcher.rb +29 -0
  94. data/lib/datadog/tracing/contrib/stripe/request.rb +67 -0
  95. data/lib/datadog/tracing/contrib.rb +1 -0
  96. data/lib/datadog/tracing/distributed/trace_context.rb +16 -7
  97. data/lib/datadog/tracing/metadata/tagging.rb +6 -0
  98. data/lib/datadog/tracing/trace_digest.rb +17 -7
  99. data/lib/datadog/tracing/trace_operation.rb +8 -0
  100. data/lib/ddtrace/version.rb +1 -1
  101. metadata +23 -6
@@ -0,0 +1,201 @@
1
+ # typed: ignore
2
+
3
+ require_relative 'media_type'
4
+
5
+ module Datadog
6
+ module AppSec
7
+ module Utils
8
+ module HTTP
9
+ # Implementation of media range for content negotiation
10
+ class MediaRange
11
+ class ParseError < ::StandardError
12
+ end
13
+
14
+ WILDCARD = '*'.freeze
15
+ WILDCARD_RE = ::Regexp.escape(WILDCARD)
16
+
17
+ # See: https://www.rfc-editor.org/rfc/rfc7230#section-3.2.6
18
+ TOKEN_RE = /[-#$%&'*+.^_`|~A-Za-z0-9]+/.freeze
19
+
20
+ # See: https://www.rfc-editor.org/rfc/rfc7231#section-3.1.1.1
21
+ PARAMETER_RE = %r{ # rubocop:disable Style/RegexpLiteral
22
+ (?:
23
+ (?<parameter_name>#{TOKEN_RE})
24
+ =
25
+ (?:
26
+ (?<parameter_value>#{TOKEN_RE})
27
+ |
28
+ "(?<parameter_value>[^"]+)"
29
+ )
30
+ )
31
+ }ix.freeze
32
+
33
+ # See: https://www.rfc-editor.org/rfc/rfc7231#section-5.3.2
34
+ ACCEPT_EXT_RE = %r{ # rubocop:disable Style/RegexpLiteral
35
+ (?:
36
+ (?<ext_name>#{TOKEN_RE})
37
+ =
38
+ (?:
39
+ (?<ext_value>#{TOKEN_RE})
40
+ |
41
+ "(?<ext_value>[^"]+)"
42
+ )
43
+ )
44
+ }ix.freeze
45
+
46
+ # See: https://www.rfc-editor.org/rfc/rfc7231#section-5.3.1
47
+ QVALUE_RE = %r{ # rubocop:disable Style/RegexpLiteral
48
+ 0(?:\.\d{1,3})?
49
+ |
50
+ 1(?:\.0{1,3})?
51
+ }ix.freeze
52
+
53
+ # See: https://www.rfc-editor.org/rfc/rfc7231#section-5.3.2
54
+ MEDIA_RANGE_RE = %r{
55
+ \A
56
+ (?:
57
+ (?<type>#{WILDCARD_RE})/(?<subtype>#{WILDCARD_RE})
58
+ |
59
+ (?<type>#{TOKEN_RE})/(?<subtype>#{WILDCARD_RE})
60
+ |
61
+ (?<type>#{TOKEN_RE})/(?<subtype>#{TOKEN_RE})
62
+ )
63
+ (?<parameters>
64
+ (?:
65
+ \s*;\s*
66
+ (?!q=)
67
+ #{PARAMETER_RE}
68
+ )*
69
+ )
70
+ (?<accept_params>
71
+ (?<weight>
72
+ \s*;\s*
73
+ (?:q=
74
+ (?<quality>
75
+ #{QVALUE_RE}
76
+ )
77
+ )
78
+ )
79
+ (?<accept_exts>
80
+ (?<accept_ext>
81
+ (?:
82
+ \s*;\s*
83
+ (?!q=)
84
+ #{ACCEPT_EXT_RE}
85
+ )*
86
+ )
87
+ )
88
+ )?
89
+ \Z
90
+ }ix.freeze
91
+
92
+ attr_reader :type, :subtype, :quality, :parameters, :accept_ext
93
+
94
+ def initialize(media_range) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
95
+ media_range_match = MEDIA_RANGE_RE.match(media_range)
96
+
97
+ raise ParseError, media_range.inspect if media_range_match.nil?
98
+
99
+ @type = (media_range_match['type'] || WILDCARD).downcase
100
+ @subtype = (media_range_match['subtype'] || WILDCARD).downcase
101
+ @quality = (media_range_match['quality'] || 1.0).to_f
102
+ @parameters = {}
103
+ @accept_ext = {}
104
+
105
+ parameters = media_range_match['parameters']
106
+
107
+ return if parameters.nil?
108
+
109
+ parameters.split(';').map(&:strip).each do |parameter|
110
+ parameter_match = PARAMETER_RE.match(parameter)
111
+
112
+ next if parameter_match.nil?
113
+
114
+ parameter_name = parameter_match['parameter_name']
115
+ parameter_value = parameter_match['parameter_value']
116
+
117
+ next if parameter_name.nil? || parameter_value.nil?
118
+
119
+ @parameters[parameter_name.downcase] = parameter_value.downcase
120
+ end
121
+
122
+ accept_exts = media_range_match['accept_exts']
123
+
124
+ return if accept_exts.nil?
125
+
126
+ accept_exts.split(';').map(&:strip).each do |ext|
127
+ ext_match = ACCEPT_EXT_RE.match(ext)
128
+
129
+ next if ext_match.nil?
130
+
131
+ ext_name = ext_match['ext_name']
132
+ ext_value = ext_match['ext_value']
133
+
134
+ next if ext_name.nil? || ext_value.nil?
135
+
136
+ @accept_ext[ext_name.downcase] = ext_value.downcase
137
+ end
138
+ end
139
+
140
+ # Compare two MediaRange for ordering
141
+ def <=>(other)
142
+ unless (q = quality <=> other.quality) == 0 || q.nil?
143
+ return q
144
+ end
145
+
146
+ if (s = specificity <=> other.specificity) != 0
147
+ return s
148
+ end
149
+
150
+ unless wildcard?(:type)
151
+ if wildcard?(:subtype) && !other.wildcard?(:subtype)
152
+ return -1
153
+ elsif !wildcard?(:subtype) && other.wildcard?(:subtype)
154
+ return 1
155
+ end
156
+ end
157
+
158
+ if wildcard?(:type) && !other.wildcard?(:type)
159
+ return -1
160
+ elsif !wildcard?(:type) && other.wildcard?(:type)
161
+ return 1
162
+ end
163
+
164
+ 0
165
+ end
166
+
167
+ # Compare with a MediaType for match
168
+ #
169
+ # returns true if the MediaType is accepted by this MediaRange
170
+ def ===(other)
171
+ return self === MediaType.new(other) if other.is_a?(::String)
172
+
173
+ type == other.type && subtype == other.subtype && other.parameters.all? { |k, v| parameters[k] == v } ||
174
+ type == other.type && wildcard?(:subtype) ||
175
+ wildcard?(:type) && wildcard?(:subtype)
176
+ end
177
+
178
+ def specificity
179
+ @parameters.count
180
+ end
181
+
182
+ def wildcard?(field = nil)
183
+ return wildcard?(:type) || wildcard?(:subtype) if field.nil?
184
+
185
+ instance_variable_get(:"@#{field}") == WILDCARD
186
+ end
187
+
188
+ def to_s
189
+ s = "#{@type}/#{@subtype}"
190
+
191
+ s << ';' << @parameters.map { |k, v| "#{k}=#{v}" }.join(';') if @parameters.count > 0
192
+ s << ";q=#{@quality}" if @quality < 1.0
193
+ s << ';' << @accept_ext.map { |k, v| "#{k}=#{v}" }.join(';') if @accept_ext.count > 0
194
+
195
+ s
196
+ end
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,87 @@
1
+ # typed: ignore
2
+
3
+ module Datadog
4
+ module AppSec
5
+ module Utils
6
+ module HTTP
7
+ # Implementation of media type for content negotiation
8
+ #
9
+ # See:
10
+ # - https://www.rfc-editor.org/rfc/rfc7231#section-5.3.1
11
+ # - https://www.rfc-editor.org/rfc/rfc7231#section-5.3.2
12
+ class MediaType
13
+ class ParseError < ::StandardError
14
+ end
15
+
16
+ WILDCARD = '*'.freeze
17
+
18
+ # See: https://www.rfc-editor.org/rfc/rfc7230#section-3.2.6
19
+ TOKEN_RE = /[-#$%&'*+.^_`|~A-Za-z0-9]+/.freeze
20
+
21
+ # See: https://www.rfc-editor.org/rfc/rfc7231#section-3.1.1.1
22
+ PARAMETER_RE = %r{ # rubocop:disable Style/RegexpLiteral
23
+ (?:
24
+ (?<parameter_name>#{TOKEN_RE})
25
+ =
26
+ (?:
27
+ (?<parameter_value>#{TOKEN_RE})
28
+ |
29
+ "(?<parameter_value>[^"]+)"
30
+ )
31
+ )
32
+ }ix.freeze
33
+
34
+ # See: https://www.rfc-editor.org/rfc/rfc7231#section-3.1.1.1
35
+ MEDIA_TYPE_RE = %r{
36
+ \A
37
+ (?<type>#{TOKEN_RE})/(?<subtype>#{TOKEN_RE})
38
+ (?<parameters>
39
+ (?:
40
+ \s*;\s*
41
+ #{PARAMETER_RE}
42
+ )*
43
+ )
44
+ \Z
45
+ }ix.freeze
46
+
47
+ attr_reader :type, :subtype, :parameters
48
+
49
+ def initialize(media_type)
50
+ media_type_match = MEDIA_TYPE_RE.match(media_type)
51
+
52
+ raise ParseError, media_type.inspect if media_type_match.nil?
53
+
54
+ @type = (media_type_match['type'] || WILDCARD).downcase
55
+ @subtype = (media_type_match['subtype'] || WILDCARD).downcase
56
+ @parameters = {}
57
+
58
+ parameters = media_type_match['parameters']
59
+
60
+ return if parameters.nil?
61
+
62
+ parameters.split(';').map(&:strip).each do |parameter|
63
+ parameter_match = PARAMETER_RE.match(parameter)
64
+
65
+ next if parameter_match.nil?
66
+
67
+ parameter_name = parameter_match['parameter_name']
68
+ parameter_value = parameter_match['parameter_value']
69
+
70
+ next if parameter_name.nil? || parameter_value.nil?
71
+
72
+ @parameters[parameter_name.downcase] = parameter_value.downcase
73
+ end
74
+ end
75
+
76
+ def to_s
77
+ s = "#{@type}/#{@subtype}"
78
+
79
+ s << ';' << @parameters.map { |k, v| "#{k}=#{v}" }.join(';') if @parameters.count > 0
80
+
81
+ s
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,9 @@
1
+ module Datadog
2
+ module AppSec
3
+ module Utils
4
+ # HTTP utilities
5
+ module HTTP
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ module Datadog
2
+ module AppSec
3
+ # Utilities for AppSec
4
+ module Utils
5
+ end
6
+ end
7
+ end
@@ -1,4 +1,4 @@
1
- # typed: false
1
+ # typed: ignore
2
2
 
3
3
  require_relative 'appsec/configuration'
4
4
  require_relative 'appsec/extensions'
@@ -5,6 +5,7 @@
5
5
  require_relative '../../core/git/ext'
6
6
 
7
7
  require 'open3'
8
+ require 'json'
8
9
 
9
10
  module Datadog
10
11
  module CI
@@ -22,11 +23,13 @@ module Datadog
22
23
  TAG_PROVIDER_NAME = 'ci.provider.name'
23
24
  TAG_STAGE_NAME = 'ci.stage.name'
24
25
  TAG_WORKSPACE_PATH = 'ci.workspace_path'
26
+ TAG_CI_ENV_VARS = '_dd.ci.env_vars'
25
27
 
26
28
  PROVIDERS = [
27
29
  ['APPVEYOR', :extract_appveyor],
28
30
  ['TF_BUILD', :extract_azure_pipelines],
29
31
  ['BITBUCKET_COMMIT', :extract_bitbucket],
32
+ ['BUDDY', :extract_buddy],
30
33
  ['BUILDKITE', :extract_buildkite],
31
34
  ['CIRCLECI', :extract_circle_ci],
32
35
  ['GITHUB_SHA', :extract_github_actions],
@@ -43,7 +46,6 @@ module Datadog
43
46
  # Extract metadata from CI provider environment variables
44
47
  _, extractor = PROVIDERS.find { |provider_env_var, _| env.key?(provider_env_var) }
45
48
  tags = extractor ? public_send(extractor, env).reject { |_, v| v.nil? || v.strip.empty? } : {}
46
- tags.delete(Core::Git::Ext::TAG_BRANCH) unless tags[Core::Git::Ext::TAG_TAG].nil?
47
49
 
48
50
  # If user defined metadata is defined, overwrite
49
51
  tags.merge!(extract_user_defined_git(env))
@@ -126,16 +128,12 @@ module Datadog
126
128
  if build_id &&
127
129
  (team_foundation_server_uri = env['SYSTEM_TEAMFOUNDATIONSERVERURI']) &&
128
130
  (team_project_id = env['SYSTEM_TEAMPROJECTID'])
129
-
130
131
  pipeline_url = "#{team_foundation_server_uri}#{team_project_id}/_build/results?buildId=#{build_id}"
131
-
132
132
  job_url = "#{pipeline_url}&view=logs&j=#{env['SYSTEM_JOBID']}&t=#{env['SYSTEM_TASKINSTANCEID']}"
133
133
  end
134
134
 
135
135
  branch, tag = branch_or_tag(
136
- env['SYSTEM_PULLREQUEST_SOURCEBRANCH'] ||
137
- env['BUILD_SOURCEBRANCH'] ||
138
- env['BUILD_SOURCEBRANCHNAME']
136
+ env['SYSTEM_PULLREQUEST_SOURCEBRANCH'] || env['BUILD_SOURCEBRANCH'] || env['BUILD_SOURCEBRANCHNAME']
139
137
  )
140
138
 
141
139
  {
@@ -156,7 +154,12 @@ module Datadog
156
154
  Core::Git::Ext::TAG_TAG => tag,
157
155
  Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['BUILD_REQUESTEDFORID'],
158
156
  Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['BUILD_REQUESTEDFOREMAIL'],
159
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE']
157
+ Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE'],
158
+ TAG_CI_ENV_VARS => {
159
+ 'SYSTEM_TEAMPROJECTID' => env['SYSTEM_TEAMPROJECTID'],
160
+ 'BUILD_BUILDID' => env['BUILD_BUILDID'],
161
+ 'SYSTEM_JOBID' => env['SYSTEM_JOBID']
162
+ }.to_json
160
163
  }
161
164
  end
162
165
 
@@ -181,6 +184,24 @@ module Datadog
181
184
  }
182
185
  end
183
186
 
187
+ def extract_buddy(env)
188
+ {
189
+ TAG_PROVIDER_NAME => 'buddy',
190
+ TAG_PIPELINE_ID => "#{env['BUDDY_PIPELINE_ID']}/#{env['BUDDY_EXECUTION_ID']}",
191
+ TAG_PIPELINE_NAME => env['BUDDY_PIPELINE_NAME'],
192
+ TAG_PIPELINE_NUMBER => env['BUDDY_EXECUTION_ID'],
193
+ TAG_PIPELINE_URL => env['BUDDY_EXECUTION_URL'],
194
+ TAG_WORKSPACE_PATH => env['CI_WORKSPACE_PATH'],
195
+ Core::Git::Ext::TAG_REPOSITORY_URL => env['BUDDY_SCM_URL'],
196
+ Core::Git::Ext::TAG_COMMIT_SHA => env['BUDDY_EXECUTION_REVISION'],
197
+ Core::Git::Ext::TAG_BRANCH => env['BUDDY_EXECUTION_BRANCH'],
198
+ Core::Git::Ext::TAG_TAG => env['BUDDY_EXECUTION_TAG'],
199
+ Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUDDY_EXECUTION_REVISION_MESSAGE'],
200
+ Core::Git::Ext::TAG_COMMIT_COMMITTER_NAME => env['BUDDY_EXECUTION_REVISION_COMMITTER_NAME'],
201
+ Core::Git::Ext::TAG_COMMIT_COMMITTER_EMAIL => env['BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL'],
202
+ }
203
+ end
204
+
184
205
  def extract_buildkite(env)
185
206
  {
186
207
  Core::Git::Ext::TAG_BRANCH => env['BUILDKITE_BRANCH'],
@@ -196,7 +217,11 @@ module Datadog
196
217
  TAG_WORKSPACE_PATH => env['BUILDKITE_BUILD_CHECKOUT_PATH'],
197
218
  Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['BUILDKITE_BUILD_AUTHOR'],
198
219
  Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['BUILDKITE_BUILD_AUTHOR_EMAIL'],
199
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILDKITE_MESSAGE']
220
+ Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILDKITE_MESSAGE'],
221
+ TAG_CI_ENV_VARS => {
222
+ 'BUILDKITE_BUILD_ID' => env['BUILDKITE_BUILD_ID'],
223
+ 'BUILDKITE_JOB_ID' => env['BUILDKITE_JOB_ID']
224
+ }.to_json
200
225
  }
201
226
  end
202
227
 
@@ -215,7 +240,11 @@ module Datadog
215
240
  TAG_WORKSPACE_PATH => env['CIRCLE_WORKING_DIRECTORY'],
216
241
  Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['BUILD_REQUESTEDFORID'],
217
242
  Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['BUILD_REQUESTEDFOREMAIL'],
218
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE']
243
+ Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE'],
244
+ TAG_CI_ENV_VARS => {
245
+ 'CIRCLE_WORKFLOW_ID' => env['CIRCLE_WORKFLOW_ID'],
246
+ 'CIRCLE_BUILD_NUM' => env['CIRCLE_BUILD_NUM']
247
+ }.to_json
219
248
  }
220
249
  end
221
250
 
@@ -233,6 +262,7 @@ module Datadog
233
262
  Core::Git::Ext::TAG_REPOSITORY_URL => "#{env['GITHUB_SERVER_URL']}/#{env['GITHUB_REPOSITORY']}.git",
234
263
  Core::Git::Ext::TAG_TAG => tag,
235
264
  TAG_JOB_URL => "#{env['GITHUB_SERVER_URL']}/#{env['GITHUB_REPOSITORY']}/commit/#{env['GITHUB_SHA']}/checks",
265
+ TAG_JOB_NAME => env['GITHUB_JOB'],
236
266
  TAG_PIPELINE_ID => env['GITHUB_RUN_ID'],
237
267
  TAG_PIPELINE_NAME => env['GITHUB_WORKFLOW'],
238
268
  TAG_PIPELINE_NUMBER => env['GITHUB_RUN_NUMBER'],
@@ -241,7 +271,13 @@ module Datadog
241
271
  TAG_WORKSPACE_PATH => env['GITHUB_WORKSPACE'],
242
272
  Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['BUILD_REQUESTEDFORID'],
243
273
  Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['BUILD_REQUESTEDFOREMAIL'],
244
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE']
274
+ Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE'],
275
+ TAG_CI_ENV_VARS => {
276
+ 'GITHUB_SERVER_URL' => env['GITHUB_SERVER_URL'],
277
+ 'GITHUB_REPOSITORY' => env['GITHUB_REPOSITORY'],
278
+ 'GITHUB_RUN_ID' => env['GITHUB_RUN_ID'],
279
+ 'GITHUB_RUN_ATTEMPT' => env['GITHUB_RUN_ATTEMPT'],
280
+ }.reject { |_k, v| v.nil? }.to_json
245
281
  }
246
282
  end
247
283
 
@@ -266,7 +302,12 @@ module Datadog
266
302
  TAG_PIPELINE_URL => (url.gsub(%r{/-/pipelines/}, '/pipelines/') if url),
267
303
  TAG_PROVIDER_NAME => 'gitlab',
268
304
  TAG_WORKSPACE_PATH => env['CI_PROJECT_DIR'],
269
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['CI_COMMIT_MESSAGE']
305
+ Core::Git::Ext::TAG_COMMIT_MESSAGE => env['CI_COMMIT_MESSAGE'],
306
+ TAG_CI_ENV_VARS => {
307
+ 'CI_PROJECT_URL' => env['CI_PROJECT_URL'],
308
+ 'CI_PIPELINE_ID' => env['CI_PIPELINE_ID'],
309
+ 'CI_JOB_ID' => env['CI_JOB_ID']
310
+ }.to_json
270
311
  }
271
312
  end
272
313
 
@@ -290,7 +331,10 @@ module Datadog
290
331
  TAG_WORKSPACE_PATH => env['WORKSPACE'],
291
332
  Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['BUILD_REQUESTEDFORID'],
292
333
  Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['BUILD_REQUESTEDFOREMAIL'],
293
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE']
334
+ Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE'],
335
+ TAG_CI_ENV_VARS => {
336
+ 'DD_CUSTOM_TRACE_ID' => env['DD_CUSTOM_TRACE_ID']
337
+ }.to_json
294
338
  }
295
339
  end
296
340
 
@@ -303,7 +347,7 @@ module Datadog
303
347
  TAG_PIPELINE_ID => env['BUILD_ID'],
304
348
  TAG_PIPELINE_NUMBER => env['BUILD_NUMBER'],
305
349
  TAG_PIPELINE_URL => (
306
- env['SERVER_URL'] && env['BUILD_ID'] ? "#{env['SERVER_URL']}/viewLog.html?buildId=#{env['SERVER_URL']}" : nil
350
+ env['SERVER_URL'] && env['BUILD_ID'] ? "#{env['SERVER_URL']}/viewLog.html?buildId=#{env['BUILD_ID']}" : nil
307
351
  ),
308
352
  Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['BUILD_REQUESTEDFORID'],
309
353
  Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['BUILD_REQUESTEDFOREMAIL'],
@@ -138,8 +138,8 @@ module Datadog
138
138
  value: parsed_url && parsed_url.hostname
139
139
  ),
140
140
  DetectedConfiguration.new(
141
- friendly_name: "#{Datadog::Tracing::Configuration::Ext::Transport::ENV_DEFAULT_HOST} environment variable",
142
- value: ENV[Datadog::Tracing::Configuration::Ext::Transport::ENV_DEFAULT_HOST]
141
+ friendly_name: "#{Datadog::Core::Configuration::Ext::Transport::ENV_DEFAULT_HOST} environment variable",
142
+ value: ENV[Datadog::Core::Configuration::Ext::Transport::ENV_DEFAULT_HOST]
143
143
  )
144
144
  )
145
145
  end
@@ -32,10 +32,13 @@ module Datadog
32
32
  option(name) do |o|
33
33
  o.default { settings_class.new }
34
34
  o.lazy
35
+
35
36
  o.resetter do |value|
36
37
  value.reset! if value.respond_to?(:reset!)
37
38
  value
38
39
  end
40
+
41
+ o.type settings_class
39
42
  end
40
43
  end
41
44
 
@@ -12,6 +12,14 @@ module Datadog
12
12
  ENV_HEALTH_METRICS_ENABLED = 'DD_HEALTH_METRICS_ENABLED'.freeze
13
13
  ENV_STARTUP_LOGS_ENABLED = 'DD_TRACE_STARTUP_LOGS'.freeze
14
14
  end
15
+
16
+ module Metrics
17
+ ENV_DEFAULT_PORT = 'DD_METRIC_AGENT_PORT'.freeze
18
+ end
19
+
20
+ module Transport
21
+ ENV_DEFAULT_HOST = 'DD_AGENT_HOST'.freeze
22
+ end
15
23
  end
16
24
  end
17
25
  end
@@ -17,7 +17,8 @@ module Datadog
17
17
  :name,
18
18
  :on_set,
19
19
  :resetter,
20
- :setter
20
+ :setter,
21
+ :type
21
22
 
22
23
  def initialize(name, meta = {}, &block)
23
24
  @default = meta[:default]
@@ -28,6 +29,7 @@ module Datadog
28
29
  @on_set = meta[:on_set]
29
30
  @resetter = meta[:resetter]
30
31
  @setter = meta[:setter] || block || IDENTITY
32
+ @type = meta[:type]
31
33
  end
32
34
 
33
35
  # Creates a new Option, bound to the context provided.
@@ -51,6 +53,7 @@ module Datadog
51
53
  @on_set = nil
52
54
  @resetter = nil
53
55
  @setter = OptionDefinition::IDENTITY
56
+ @type = nil
54
57
 
55
58
  # If options were supplied, apply them.
56
59
  apply_options!(options)
@@ -91,6 +94,10 @@ module Datadog
91
94
  @setter = block
92
95
  end
93
96
 
97
+ def type(value = nil)
98
+ @type = value
99
+ end
100
+
94
101
  # For applying options for OptionDefinition
95
102
  def apply_options!(options = {})
96
103
  return if options.nil? || options.empty?
@@ -102,6 +109,7 @@ module Datadog
102
109
  on_set(&options[:on_set]) if options.key?(:on_set)
103
110
  resetter(&options[:resetter]) if options.key?(:resetter)
104
111
  setter(&options[:setter]) if options.key?(:setter)
112
+ type(&options[:type]) if options.key?(:type)
105
113
  end
106
114
 
107
115
  def to_definition
@@ -116,7 +124,8 @@ module Datadog
116
124
  lazy: @lazy,
117
125
  on_set: @on_set,
118
126
  resetter: @resetter,
119
- setter: @setter
127
+ setter: @setter,
128
+ type: @type
120
129
  }
121
130
  end
122
131
  end
@@ -20,10 +20,6 @@ module Datadog
20
20
  class Settings
21
21
  include Base
22
22
 
23
- # TODO: Tracing should manage its own settings.
24
- # Keep this extension here for now to keep things working.
25
- extend Datadog::Tracing::Configuration::Settings
26
-
27
23
  # @!visibility private
28
24
  def initialize(*_)
29
25
  super
@@ -214,6 +210,8 @@ module Datadog
214
210
 
215
211
  # Controls the maximum number of frames for each thread sampled. Can be tuned to avoid omitted frames in the
216
212
  # produced profiles. Increasing this may increase the overhead of profiling.
213
+ #
214
+ # @default `DD_PROFILING_MAX_FRAMES` environment variable, otherwise 400
217
215
  option :max_frames do |o|
218
216
  o.default { env_to_int(Profiling::Ext::ENV_MAX_FRAMES, 400) }
219
217
  o.lazy
@@ -437,6 +435,10 @@ module Datadog
437
435
  o.lazy
438
436
  end
439
437
  end
438
+
439
+ # TODO: Tracing should manage its own settings.
440
+ # Keep this extension here for now to keep things working.
441
+ extend Datadog::Tracing::Configuration::Settings
440
442
  end
441
443
  # rubocop:enable Metrics/BlockLength
442
444
  end
@@ -221,9 +221,9 @@ module Datadog
221
221
  !!Datadog.configuration.diagnostics.health_metrics.enabled
222
222
  end
223
223
 
224
- # TODO: Populate when profiling is implemented
225
- # def profiling_enabled
226
- # end
224
+ def profiling_enabled
225
+ !!Datadog.configuration.profiling.enabled
226
+ end
227
227
 
228
228
  # TODO: Populate when automatic log correlation is implemented
229
229
  # def logs_correlation_enabled
@@ -254,6 +254,7 @@ module Datadog
254
254
  partial_flushing_enabled: partial_flushing_enabled,
255
255
  priority_sampling_enabled: priority_sampling_enabled,
256
256
  health_metrics_enabled: health_metrics_enabled,
257
+ profiling_enabled: profiling_enabled,
257
258
  **instrumented_integrations_settings
258
259
  }
259
260
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative '../utils/time'
4
4
  require_relative '../utils/only_once'
5
+ require_relative '../configuration/ext'
5
6
 
6
7
  require_relative 'ext'
7
8
  require_relative 'options'
@@ -50,11 +51,11 @@ module Datadog
50
51
  end
51
52
 
52
53
  def default_hostname
53
- ENV.fetch(Ext::ENV_DEFAULT_HOST, Ext::DEFAULT_HOST)
54
+ ENV.fetch(Configuration::Ext::Transport::ENV_DEFAULT_HOST, Ext::DEFAULT_HOST)
54
55
  end
55
56
 
56
57
  def default_port
57
- ENV.fetch(Ext::ENV_DEFAULT_PORT, Ext::DEFAULT_PORT).to_i
58
+ ENV.fetch(Configuration::Ext::Metrics::ENV_DEFAULT_PORT, Ext::DEFAULT_PORT).to_i
58
59
  end
59
60
 
60
61
  def default_statsd_client
@@ -7,8 +7,6 @@ module Datadog
7
7
  module Ext
8
8
  DEFAULT_HOST = '127.0.0.1'.freeze
9
9
  DEFAULT_PORT = 8125
10
- ENV_DEFAULT_HOST = 'DD_AGENT_HOST'.freeze
11
- ENV_DEFAULT_PORT = 'DD_METRIC_AGENT_PORT'.freeze
12
10
 
13
11
  TAG_LANG = 'language'.freeze
14
12
  TAG_LANG_INTERPRETER = 'language-interpreter'.freeze
@@ -135,6 +135,7 @@ module Datadog
135
135
  format_configuration_value(configuration.tracing.writer_options[:flush_interval])
136
136
  options['logger.instance'] = configuration.logger.instance.class.to_s
137
137
  options['appsec.enabled'] = configuration.dig('appsec', 'enabled') if configuration.respond_to?('appsec')
138
+ options['tracing.opentelemetry.enabled'] = !defined?(Datadog::OpenTelemetry::LOADED).nil?
138
139
  compact_hash(options)
139
140
  end
140
141