ddtrace 1.14.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +178 -2
  3. data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +3 -5
  4. data/ext/ddtrace_profiling_native_extension/clock_id.h +0 -3
  5. data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +0 -22
  6. data/ext/ddtrace_profiling_native_extension/clock_id_noop.c +0 -1
  7. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +41 -6
  8. data/ext/ddtrace_profiling_native_extension/collectors_idle_sampling_helper.c +3 -0
  9. data/ext/ddtrace_profiling_native_extension/collectors_stack.c +76 -24
  10. data/ext/ddtrace_profiling_native_extension/collectors_stack.h +1 -1
  11. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.c +207 -32
  12. data/ext/ddtrace_profiling_native_extension/collectors_thread_context.h +1 -1
  13. data/ext/ddtrace_profiling_native_extension/extconf.rb +8 -2
  14. data/ext/ddtrace_profiling_native_extension/http_transport.c +26 -10
  15. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.c +42 -0
  16. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +6 -0
  17. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +1 -16
  18. data/ext/ddtrace_profiling_native_extension/pid_controller.c +57 -0
  19. data/ext/ddtrace_profiling_native_extension/pid_controller.h +45 -0
  20. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +17 -12
  21. data/ext/ddtrace_profiling_native_extension/profiling.c +0 -2
  22. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +74 -37
  23. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +13 -3
  24. data/lib/datadog/appsec/assets/waf_rules/processors.json +92 -0
  25. data/lib/datadog/appsec/assets/waf_rules/recommended.json +698 -75
  26. data/lib/datadog/appsec/assets/waf_rules/scanners.json +114 -0
  27. data/lib/datadog/appsec/assets/waf_rules/strict.json +98 -8
  28. data/lib/datadog/appsec/assets.rb +8 -0
  29. data/lib/datadog/appsec/component.rb +9 -2
  30. data/lib/datadog/appsec/configuration/settings.rb +61 -2
  31. data/lib/datadog/appsec/contrib/rack/gateway/watcher.rb +8 -6
  32. data/lib/datadog/appsec/contrib/rack/reactive/request.rb +2 -7
  33. data/lib/datadog/appsec/contrib/rack/reactive/request_body.rb +2 -5
  34. data/lib/datadog/appsec/contrib/rack/reactive/response.rb +2 -5
  35. data/lib/datadog/appsec/contrib/rack/request_body_middleware.rb +3 -2
  36. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +23 -9
  37. data/lib/datadog/appsec/contrib/rails/gateway/watcher.rb +3 -2
  38. data/lib/datadog/appsec/contrib/rails/patcher.rb +9 -3
  39. data/lib/datadog/appsec/contrib/rails/reactive/action.rb +2 -5
  40. data/lib/datadog/appsec/contrib/sinatra/gateway/watcher.rb +6 -4
  41. data/lib/datadog/appsec/contrib/sinatra/patcher.rb +13 -7
  42. data/lib/datadog/appsec/contrib/sinatra/reactive/routed.rb +2 -5
  43. data/lib/datadog/appsec/event.rb +106 -50
  44. data/lib/datadog/appsec/monitor/gateway/watcher.rb +3 -3
  45. data/lib/datadog/appsec/monitor/reactive/set_user.rb +2 -5
  46. data/lib/datadog/appsec/processor/actions.rb +49 -0
  47. data/lib/datadog/appsec/processor/rule_merger.rb +22 -2
  48. data/lib/datadog/appsec/processor.rb +34 -6
  49. data/lib/datadog/appsec/remote.rb +4 -1
  50. data/lib/datadog/appsec/response.rb +82 -4
  51. data/lib/datadog/appsec/sample_rate.rb +21 -0
  52. data/lib/datadog/appsec.rb +2 -2
  53. data/lib/datadog/core/configuration/agent_settings_resolver.rb +29 -24
  54. data/lib/datadog/core/configuration/base.rb +1 -11
  55. data/lib/datadog/core/configuration/components.rb +7 -2
  56. data/lib/datadog/core/configuration/ext.rb +21 -0
  57. data/lib/datadog/core/configuration/option.rb +2 -4
  58. data/lib/datadog/core/configuration/option_definition.rb +17 -41
  59. data/lib/datadog/core/configuration/options.rb +5 -5
  60. data/lib/datadog/core/configuration/settings.rb +47 -45
  61. data/lib/datadog/core/environment/execution.rb +47 -9
  62. data/lib/datadog/core/environment/variable_helpers.rb +0 -69
  63. data/lib/datadog/core/error.rb +1 -0
  64. data/lib/datadog/core/git/ext.rb +2 -0
  65. data/lib/datadog/core/remote/client/capabilities.rb +1 -1
  66. data/lib/datadog/core/remote/component.rb +2 -2
  67. data/lib/datadog/core/remote/negotiation.rb +2 -2
  68. data/lib/datadog/core/remote/transport/config.rb +60 -0
  69. data/lib/datadog/core/remote/transport/http/api/instance.rb +39 -0
  70. data/lib/datadog/core/remote/transport/http/api/spec.rb +21 -0
  71. data/lib/datadog/core/remote/transport/http/api.rb +58 -0
  72. data/lib/datadog/core/remote/transport/http/builder.rb +219 -0
  73. data/lib/datadog/core/remote/transport/http/client.rb +48 -0
  74. data/lib/datadog/core/remote/transport/http/config.rb +280 -0
  75. data/lib/datadog/core/remote/transport/http/negotiation.rb +146 -0
  76. data/lib/datadog/core/remote/transport/http.rb +179 -0
  77. data/lib/datadog/core/{transport → remote/transport}/negotiation.rb +25 -23
  78. data/lib/datadog/core/telemetry/collector.rb +3 -2
  79. data/lib/datadog/core/telemetry/http/transport.rb +2 -1
  80. data/lib/datadog/core/transport/ext.rb +47 -0
  81. data/lib/datadog/core/transport/http/adapters/net.rb +168 -0
  82. data/lib/datadog/core/transport/http/adapters/registry.rb +29 -0
  83. data/lib/datadog/core/transport/http/adapters/test.rb +89 -0
  84. data/lib/datadog/core/transport/http/adapters/unix_socket.rb +83 -0
  85. data/lib/datadog/core/transport/http/api/endpoint.rb +31 -0
  86. data/lib/datadog/core/transport/http/api/fallbacks.rb +26 -0
  87. data/lib/datadog/core/transport/http/api/map.rb +18 -0
  88. data/lib/datadog/core/transport/http/env.rb +62 -0
  89. data/lib/datadog/core/transport/http/response.rb +60 -0
  90. data/lib/datadog/core/transport/parcel.rb +22 -0
  91. data/lib/datadog/core/transport/request.rb +17 -0
  92. data/lib/datadog/core/transport/response.rb +64 -0
  93. data/lib/datadog/core/workers/polling.rb +2 -2
  94. data/lib/datadog/opentelemetry/api/context.rb +10 -3
  95. data/lib/datadog/opentelemetry/sdk/propagator.rb +2 -1
  96. data/lib/datadog/opentelemetry/sdk/span_processor.rb +14 -2
  97. data/lib/datadog/opentelemetry/sdk/trace/span.rb +68 -0
  98. data/lib/datadog/opentelemetry/trace.rb +58 -0
  99. data/lib/datadog/opentelemetry.rb +1 -0
  100. data/lib/datadog/opentracer.rb +9 -0
  101. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +12 -18
  102. data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +1 -1
  103. data/lib/datadog/profiling/collectors/thread_context.rb +9 -1
  104. data/lib/datadog/profiling/component.rb +24 -99
  105. data/lib/datadog/profiling/ext.rb +0 -12
  106. data/lib/datadog/profiling/flush.rb +0 -3
  107. data/lib/datadog/profiling/http_transport.rb +6 -3
  108. data/lib/datadog/profiling/native_extension.rb +0 -21
  109. data/lib/datadog/profiling/profiler.rb +11 -12
  110. data/lib/datadog/profiling.rb +8 -81
  111. data/lib/datadog/tracing/component.rb +10 -4
  112. data/lib/datadog/tracing/configuration/agent_settings_resolver.rb +13 -0
  113. data/lib/datadog/tracing/configuration/ext.rb +4 -2
  114. data/lib/datadog/tracing/configuration/settings.rb +14 -7
  115. data/lib/datadog/tracing/contrib/action_pack/configuration/settings.rb +1 -1
  116. data/lib/datadog/tracing/contrib/active_job/configuration/settings.rb +1 -1
  117. data/lib/datadog/tracing/contrib/active_record/events/sql.rb +4 -0
  118. data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +104 -197
  119. data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +3 -0
  120. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +7 -0
  121. data/lib/datadog/tracing/contrib/configuration/settings.rb +1 -1
  122. data/lib/datadog/tracing/contrib/dalli/configuration/settings.rb +6 -0
  123. data/lib/datadog/tracing/contrib/dalli/ext.rb +7 -0
  124. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +9 -2
  125. data/lib/datadog/tracing/contrib/delayed_job/configuration/settings.rb +1 -1
  126. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +5 -0
  127. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +5 -0
  128. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +8 -0
  129. data/lib/datadog/tracing/contrib/excon/middleware.rb +5 -0
  130. data/lib/datadog/tracing/contrib/ext.rb +3 -0
  131. data/lib/datadog/tracing/contrib/faraday/configuration/settings.rb +1 -1
  132. data/lib/datadog/tracing/contrib/faraday/middleware.rb +5 -0
  133. data/lib/datadog/tracing/contrib/grpc/configuration/settings.rb +21 -1
  134. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +11 -1
  135. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +18 -0
  136. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor.rb +0 -4
  137. data/lib/datadog/tracing/contrib/http/circuit_breaker.rb +3 -3
  138. data/lib/datadog/tracing/contrib/http/instrumentation.rb +5 -0
  139. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +5 -0
  140. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +5 -0
  141. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +7 -0
  142. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +13 -3
  143. data/lib/datadog/tracing/contrib/opensearch/integration.rb +2 -2
  144. data/lib/datadog/tracing/contrib/opensearch/patcher.rb +7 -0
  145. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +5 -0
  146. data/lib/datadog/tracing/contrib/presto/instrumentation.rb +5 -0
  147. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +1 -1
  148. data/lib/datadog/tracing/contrib/que/configuration/settings.rb +1 -1
  149. data/lib/datadog/tracing/contrib/racecar/event.rb +5 -0
  150. data/lib/datadog/tracing/contrib/rack/header_tagging.rb +14 -4
  151. data/lib/datadog/tracing/contrib/rails/configuration/settings.rb +4 -4
  152. data/lib/datadog/tracing/contrib/rake/configuration/settings.rb +1 -1
  153. data/lib/datadog/tracing/contrib/redis/tags.rb +5 -0
  154. data/lib/datadog/tracing/contrib/resque/configuration/settings.rb +1 -1
  155. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +5 -0
  156. data/lib/datadog/tracing/contrib/sequel/utils.rb +5 -0
  157. data/lib/datadog/tracing/contrib/shoryuken/configuration/settings.rb +1 -1
  158. data/lib/datadog/tracing/contrib/sidekiq/configuration/settings.rb +1 -1
  159. data/lib/datadog/tracing/contrib/sneakers/configuration/settings.rb +1 -1
  160. data/lib/datadog/tracing/contrib/utils/quantization/http.rb +2 -2
  161. data/lib/datadog/tracing/distributed/propagation.rb +13 -33
  162. data/lib/datadog/tracing/metadata/tagging.rb +3 -3
  163. data/lib/datadog/tracing/sync_writer.rb +3 -3
  164. data/lib/datadog/tracing/tracer.rb +2 -0
  165. data/lib/datadog/{core → tracing}/transport/http/api/instance.rb +1 -1
  166. data/lib/datadog/{core → tracing}/transport/http/api/spec.rb +1 -1
  167. data/lib/datadog/tracing/transport/http/api.rb +43 -0
  168. data/lib/datadog/{core → tracing}/transport/http/builder.rb +13 -68
  169. data/lib/datadog/tracing/transport/http/client.rb +57 -0
  170. data/lib/datadog/tracing/transport/http/statistics.rb +47 -0
  171. data/lib/datadog/tracing/transport/http/traces.rb +152 -0
  172. data/lib/datadog/tracing/transport/http.rb +124 -0
  173. data/lib/datadog/tracing/transport/io/client.rb +89 -0
  174. data/lib/datadog/tracing/transport/io/response.rb +27 -0
  175. data/lib/datadog/tracing/transport/io/traces.rb +101 -0
  176. data/lib/datadog/tracing/transport/io.rb +30 -0
  177. data/lib/datadog/tracing/transport/serializable_trace.rb +126 -0
  178. data/lib/datadog/tracing/transport/statistics.rb +77 -0
  179. data/lib/datadog/tracing/transport/trace_formatter.rb +209 -0
  180. data/lib/datadog/tracing/transport/traces.rb +224 -0
  181. data/lib/datadog/tracing/workers/trace_writer.rb +5 -3
  182. data/lib/datadog/tracing/workers.rb +3 -2
  183. data/lib/datadog/tracing/writer.rb +5 -2
  184. data/lib/ddtrace/transport/ext.rb +17 -15
  185. data/lib/ddtrace/version.rb +1 -1
  186. data/lib/ddtrace.rb +1 -1
  187. metadata +72 -96
  188. data/lib/datadog/ci/configuration/components.rb +0 -32
  189. data/lib/datadog/ci/configuration/settings.rb +0 -51
  190. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +0 -35
  191. data/lib/datadog/ci/contrib/cucumber/ext.rb +0 -22
  192. data/lib/datadog/ci/contrib/cucumber/formatter.rb +0 -94
  193. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +0 -28
  194. data/lib/datadog/ci/contrib/cucumber/integration.rb +0 -47
  195. data/lib/datadog/ci/contrib/cucumber/patcher.rb +0 -27
  196. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +0 -35
  197. data/lib/datadog/ci/contrib/minitest/ext.rb +0 -21
  198. data/lib/datadog/ci/contrib/minitest/integration.rb +0 -49
  199. data/lib/datadog/ci/contrib/minitest/patcher.rb +0 -27
  200. data/lib/datadog/ci/contrib/minitest/test_helper.rb +0 -68
  201. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +0 -35
  202. data/lib/datadog/ci/contrib/rspec/example.rb +0 -68
  203. data/lib/datadog/ci/contrib/rspec/ext.rb +0 -21
  204. data/lib/datadog/ci/contrib/rspec/integration.rb +0 -48
  205. data/lib/datadog/ci/contrib/rspec/patcher.rb +0 -27
  206. data/lib/datadog/ci/ext/app_types.rb +0 -9
  207. data/lib/datadog/ci/ext/environment.rb +0 -575
  208. data/lib/datadog/ci/ext/settings.rb +0 -10
  209. data/lib/datadog/ci/ext/test.rb +0 -35
  210. data/lib/datadog/ci/extensions.rb +0 -19
  211. data/lib/datadog/ci/flush.rb +0 -38
  212. data/lib/datadog/ci/test.rb +0 -81
  213. data/lib/datadog/ci.rb +0 -21
  214. data/lib/datadog/core/configuration/dependency_resolver.rb +0 -28
  215. data/lib/datadog/core/configuration/option_definition_set.rb +0 -22
  216. data/lib/datadog/core/configuration/option_set.rb +0 -10
  217. data/lib/datadog/core/transport/config.rb +0 -58
  218. data/lib/datadog/core/transport/http/api.rb +0 -57
  219. data/lib/datadog/core/transport/http/client.rb +0 -45
  220. data/lib/datadog/core/transport/http/config.rb +0 -278
  221. data/lib/datadog/core/transport/http/negotiation.rb +0 -144
  222. data/lib/datadog/core/transport/http.rb +0 -169
  223. data/lib/datadog/core/utils/object_set.rb +0 -43
  224. data/lib/datadog/core/utils/string_table.rb +0 -47
  225. data/lib/datadog/profiling/backtrace_location.rb +0 -34
  226. data/lib/datadog/profiling/buffer.rb +0 -43
  227. data/lib/datadog/profiling/collectors/old_stack.rb +0 -301
  228. data/lib/datadog/profiling/encoding/profile.rb +0 -41
  229. data/lib/datadog/profiling/event.rb +0 -15
  230. data/lib/datadog/profiling/events/stack.rb +0 -82
  231. data/lib/datadog/profiling/old_recorder.rb +0 -107
  232. data/lib/datadog/profiling/pprof/builder.rb +0 -125
  233. data/lib/datadog/profiling/pprof/converter.rb +0 -102
  234. data/lib/datadog/profiling/pprof/message_set.rb +0 -16
  235. data/lib/datadog/profiling/pprof/payload.rb +0 -20
  236. data/lib/datadog/profiling/pprof/pprof.proto +0 -212
  237. data/lib/datadog/profiling/pprof/pprof_pb.rb +0 -81
  238. data/lib/datadog/profiling/pprof/stack_sample.rb +0 -139
  239. data/lib/datadog/profiling/pprof/string_table.rb +0 -12
  240. data/lib/datadog/profiling/pprof/template.rb +0 -118
  241. data/lib/datadog/profiling/trace_identifiers/ddtrace.rb +0 -43
  242. data/lib/datadog/profiling/trace_identifiers/helper.rb +0 -45
  243. data/lib/ddtrace/transport/http/adapters/net.rb +0 -168
  244. data/lib/ddtrace/transport/http/adapters/registry.rb +0 -27
  245. data/lib/ddtrace/transport/http/adapters/test.rb +0 -85
  246. data/lib/ddtrace/transport/http/adapters/unix_socket.rb +0 -77
  247. data/lib/ddtrace/transport/http/api/endpoint.rb +0 -29
  248. data/lib/ddtrace/transport/http/api/fallbacks.rb +0 -24
  249. data/lib/ddtrace/transport/http/api/instance.rb +0 -35
  250. data/lib/ddtrace/transport/http/api/map.rb +0 -16
  251. data/lib/ddtrace/transport/http/api/spec.rb +0 -17
  252. data/lib/ddtrace/transport/http/api.rb +0 -39
  253. data/lib/ddtrace/transport/http/builder.rb +0 -176
  254. data/lib/ddtrace/transport/http/client.rb +0 -52
  255. data/lib/ddtrace/transport/http/env.rb +0 -58
  256. data/lib/ddtrace/transport/http/response.rb +0 -58
  257. data/lib/ddtrace/transport/http/statistics.rb +0 -43
  258. data/lib/ddtrace/transport/http/traces.rb +0 -144
  259. data/lib/ddtrace/transport/http.rb +0 -117
  260. data/lib/ddtrace/transport/io/client.rb +0 -85
  261. data/lib/ddtrace/transport/io/response.rb +0 -25
  262. data/lib/ddtrace/transport/io/traces.rb +0 -99
  263. data/lib/ddtrace/transport/io.rb +0 -28
  264. data/lib/ddtrace/transport/parcel.rb +0 -20
  265. data/lib/ddtrace/transport/request.rb +0 -15
  266. data/lib/ddtrace/transport/response.rb +0 -60
  267. data/lib/ddtrace/transport/serializable_trace.rb +0 -122
  268. data/lib/ddtrace/transport/statistics.rb +0 -75
  269. data/lib/ddtrace/transport/trace_formatter.rb +0 -207
  270. data/lib/ddtrace/transport/traces.rb +0 -216
@@ -1,575 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../core/git/ext'
4
-
5
- require 'open3'
6
- require 'json'
7
-
8
- module Datadog
9
- module CI
10
- module Ext
11
- # Defines constants for CI tags
12
- module Environment
13
- TAG_JOB_NAME = 'ci.job.name'
14
- TAG_JOB_URL = 'ci.job.url'
15
- TAG_PIPELINE_ID = 'ci.pipeline.id'
16
- TAG_PIPELINE_NAME = 'ci.pipeline.name'
17
- TAG_PIPELINE_NUMBER = 'ci.pipeline.number'
18
- TAG_PIPELINE_URL = 'ci.pipeline.url'
19
- TAG_PROVIDER_NAME = 'ci.provider.name'
20
- TAG_STAGE_NAME = 'ci.stage.name'
21
- TAG_WORKSPACE_PATH = 'ci.workspace_path'
22
- TAG_NODE_LABELS = 'ci.node.labels'
23
- TAG_NODE_NAME = 'ci.node.name'
24
- TAG_CI_ENV_VARS = '_dd.ci.env_vars'
25
-
26
- PROVIDERS = [
27
- ['APPVEYOR', :extract_appveyor],
28
- ['TF_BUILD', :extract_azure_pipelines],
29
- ['BITBUCKET_COMMIT', :extract_bitbucket],
30
- ['BUDDY', :extract_buddy],
31
- ['BUILDKITE', :extract_buildkite],
32
- ['CIRCLECI', :extract_circle_ci],
33
- ['GITHUB_SHA', :extract_github_actions],
34
- ['GITLAB_CI', :extract_gitlab],
35
- ['JENKINS_URL', :extract_jenkins],
36
- ['TEAMCITY_VERSION', :extract_teamcity],
37
- ['TRAVIS', :extract_travis],
38
- ['BITRISE_BUILD_SLUG', :extract_bitrise],
39
- ['CF_BUILD_ID', :extract_codefresh]
40
- ].freeze
41
-
42
- module_function
43
-
44
- def tags(env)
45
- # Extract metadata from CI provider environment variables
46
- _, extractor = PROVIDERS.find { |provider_env_var, _| env.key?(provider_env_var) }
47
- tags = extractor ? public_send(extractor, env).reject { |_, v| v.nil? || v.strip.empty? } : {}
48
-
49
- # If user defined metadata is defined, overwrite
50
- tags.merge!(extract_user_defined_git(env))
51
- if !tags[Core::Git::Ext::TAG_BRANCH].nil? && tags[Core::Git::Ext::TAG_BRANCH].include?('tags/')
52
- tags[Core::Git::Ext::TAG_TAG] = tags[Core::Git::Ext::TAG_BRANCH]
53
- tags.delete(Core::Git::Ext::TAG_BRANCH)
54
- end
55
-
56
- # Normalize Git references
57
- tags[Core::Git::Ext::TAG_TAG] = normalize_ref(tags[Core::Git::Ext::TAG_TAG])
58
- tags[Core::Git::Ext::TAG_BRANCH] = normalize_ref(tags[Core::Git::Ext::TAG_BRANCH])
59
- tags[Core::Git::Ext::TAG_REPOSITORY_URL] = filter_sensitive_info(
60
- tags[Core::Git::Ext::TAG_REPOSITORY_URL]
61
- )
62
-
63
- # Expand ~
64
- workspace_path = tags[TAG_WORKSPACE_PATH]
65
- if !workspace_path.nil? && (workspace_path == '~' || workspace_path.start_with?('~/'))
66
- tags[TAG_WORKSPACE_PATH] = File.expand_path(workspace_path)
67
- end
68
-
69
- # Fill out tags from local git as fallback
70
- extract_local_git.each do |key, value|
71
- tags[key] ||= value
72
- end
73
-
74
- tags.reject { |_, v| v.nil? }
75
- end
76
-
77
- def normalize_ref(name)
78
- refs = %r{^refs/(heads/)?}
79
- origin = %r{^origin/}
80
- tags = %r{^tags/}
81
- name.gsub(refs, '').gsub(origin, '').gsub(tags, '') unless name.nil?
82
- end
83
-
84
- def filter_sensitive_info(url)
85
- url.gsub(%r{(https?://)[^/]*@}, '\1') unless url.nil?
86
- end
87
-
88
- # CI providers
89
-
90
- def extract_appveyor(env)
91
- url = "https://ci.appveyor.com/project/#{env['APPVEYOR_REPO_NAME']}/builds/#{env['APPVEYOR_BUILD_ID']}"
92
-
93
- if env['APPVEYOR_REPO_PROVIDER'] == 'github'
94
- repository = "https://github.com/#{env['APPVEYOR_REPO_NAME']}.git"
95
- commit = env['APPVEYOR_REPO_COMMIT']
96
- branch = (env['APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH'] || env['APPVEYOR_REPO_BRANCH'])
97
- tag = env['APPVEYOR_REPO_TAG_NAME']
98
- end
99
-
100
- commit_message = env['APPVEYOR_REPO_COMMIT_MESSAGE']
101
- if commit_message
102
- extended = env['APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED']
103
- commit_message = "#{commit_message}\n#{extended}" if extended
104
- end
105
-
106
- {
107
- TAG_PROVIDER_NAME => 'appveyor',
108
- Core::Git::Ext::TAG_REPOSITORY_URL => repository,
109
- Core::Git::Ext::TAG_COMMIT_SHA => commit,
110
- TAG_WORKSPACE_PATH => env['APPVEYOR_BUILD_FOLDER'],
111
- TAG_PIPELINE_ID => env['APPVEYOR_BUILD_ID'],
112
- TAG_PIPELINE_NAME => env['APPVEYOR_REPO_NAME'],
113
- TAG_PIPELINE_NUMBER => env['APPVEYOR_BUILD_NUMBER'],
114
- TAG_PIPELINE_URL => url,
115
- TAG_JOB_URL => url,
116
- Core::Git::Ext::TAG_BRANCH => branch,
117
- Core::Git::Ext::TAG_TAG => tag,
118
- Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['APPVEYOR_REPO_COMMIT_AUTHOR'],
119
- Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL'],
120
- Core::Git::Ext::TAG_COMMIT_MESSAGE => commit_message
121
- }
122
- end
123
-
124
- def extract_azure_pipelines(env)
125
- build_id = env['BUILD_BUILDID']
126
-
127
- if build_id &&
128
- (team_foundation_server_uri = env['SYSTEM_TEAMFOUNDATIONSERVERURI']) &&
129
- (team_project_id = env['SYSTEM_TEAMPROJECTID'])
130
- pipeline_url = "#{team_foundation_server_uri}#{team_project_id}/_build/results?buildId=#{build_id}"
131
- job_url = "#{pipeline_url}&view=logs&j=#{env['SYSTEM_JOBID']}&t=#{env['SYSTEM_TASKINSTANCEID']}"
132
- end
133
-
134
- branch, tag = branch_or_tag(
135
- env['SYSTEM_PULLREQUEST_SOURCEBRANCH'] || env['BUILD_SOURCEBRANCH'] || env['BUILD_SOURCEBRANCHNAME']
136
- )
137
-
138
- {
139
- TAG_PROVIDER_NAME => 'azurepipelines',
140
- TAG_WORKSPACE_PATH => env['BUILD_SOURCESDIRECTORY'],
141
- TAG_PIPELINE_ID => build_id,
142
- TAG_PIPELINE_NAME => env['BUILD_DEFINITIONNAME'],
143
- TAG_PIPELINE_NUMBER => build_id,
144
- TAG_PIPELINE_URL => pipeline_url,
145
- TAG_JOB_URL => job_url,
146
- TAG_STAGE_NAME => env['SYSTEM_STAGEDISPLAYNAME'],
147
- TAG_JOB_NAME => env['SYSTEM_JOBDISPLAYNAME'],
148
- Core::Git::Ext::TAG_REPOSITORY_URL =>
149
- env['SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI'] || env['BUILD_REPOSITORY_URI'],
150
- Core::Git::Ext::TAG_COMMIT_SHA => env['SYSTEM_PULLREQUEST_SOURCECOMMITID'] \
151
- || env['BUILD_SOURCEVERSION'],
152
- Core::Git::Ext::TAG_BRANCH => branch,
153
- Core::Git::Ext::TAG_TAG => tag,
154
- Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['BUILD_REQUESTEDFORID'],
155
- Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['BUILD_REQUESTEDFOREMAIL'],
156
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE'],
157
- TAG_CI_ENV_VARS => {
158
- 'SYSTEM_TEAMPROJECTID' => env['SYSTEM_TEAMPROJECTID'],
159
- 'BUILD_BUILDID' => env['BUILD_BUILDID'],
160
- 'SYSTEM_JOBID' => env['SYSTEM_JOBID']
161
- }.to_json
162
- }
163
- end
164
-
165
- def extract_bitbucket(env)
166
- url = "https://bitbucket.org/#{env['BITBUCKET_REPO_FULL_NAME']}/addon/pipelines/home#" \
167
- "!/results/#{env['BITBUCKET_BUILD_NUMBER']}"
168
- {
169
- Core::Git::Ext::TAG_BRANCH => env['BITBUCKET_BRANCH'],
170
- Core::Git::Ext::TAG_COMMIT_SHA => env['BITBUCKET_COMMIT'],
171
- Core::Git::Ext::TAG_REPOSITORY_URL => env['BITBUCKET_GIT_SSH_ORIGIN'],
172
- Core::Git::Ext::TAG_TAG => env['BITBUCKET_TAG'],
173
- TAG_JOB_URL => url,
174
- TAG_PIPELINE_ID => env['BITBUCKET_PIPELINE_UUID'] ? env['BITBUCKET_PIPELINE_UUID'].tr('{}', '') : nil,
175
- TAG_PIPELINE_NAME => env['BITBUCKET_REPO_FULL_NAME'],
176
- TAG_PIPELINE_NUMBER => env['BITBUCKET_BUILD_NUMBER'],
177
- TAG_PIPELINE_URL => url,
178
- TAG_PROVIDER_NAME => 'bitbucket',
179
- TAG_WORKSPACE_PATH => env['BITBUCKET_CLONE_DIR'],
180
- }
181
- end
182
-
183
- def extract_buddy(env)
184
- {
185
- TAG_PROVIDER_NAME => 'buddy',
186
- TAG_PIPELINE_ID => "#{env['BUDDY_PIPELINE_ID']}/#{env['BUDDY_EXECUTION_ID']}",
187
- TAG_PIPELINE_NAME => env['BUDDY_PIPELINE_NAME'],
188
- TAG_PIPELINE_NUMBER => env['BUDDY_EXECUTION_ID'],
189
- TAG_PIPELINE_URL => env['BUDDY_EXECUTION_URL'],
190
- TAG_WORKSPACE_PATH => env['CI_WORKSPACE_PATH'],
191
- Core::Git::Ext::TAG_REPOSITORY_URL => env['BUDDY_SCM_URL'],
192
- Core::Git::Ext::TAG_COMMIT_SHA => env['BUDDY_EXECUTION_REVISION'],
193
- Core::Git::Ext::TAG_BRANCH => env['BUDDY_EXECUTION_BRANCH'],
194
- Core::Git::Ext::TAG_TAG => env['BUDDY_EXECUTION_TAG'],
195
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUDDY_EXECUTION_REVISION_MESSAGE'],
196
- Core::Git::Ext::TAG_COMMIT_COMMITTER_NAME => env['BUDDY_EXECUTION_REVISION_COMMITTER_NAME'],
197
- Core::Git::Ext::TAG_COMMIT_COMMITTER_EMAIL => env['BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL'],
198
- }
199
- end
200
-
201
- def extract_buildkite(env)
202
- tags = {
203
- Core::Git::Ext::TAG_BRANCH => env['BUILDKITE_BRANCH'],
204
- Core::Git::Ext::TAG_COMMIT_SHA => env['BUILDKITE_COMMIT'],
205
- Core::Git::Ext::TAG_REPOSITORY_URL => env['BUILDKITE_REPO'],
206
- Core::Git::Ext::TAG_TAG => env['BUILDKITE_TAG'],
207
- TAG_PIPELINE_ID => env['BUILDKITE_BUILD_ID'],
208
- TAG_PIPELINE_NAME => env['BUILDKITE_PIPELINE_SLUG'],
209
- TAG_PIPELINE_NUMBER => env['BUILDKITE_BUILD_NUMBER'],
210
- TAG_PIPELINE_URL => env['BUILDKITE_BUILD_URL'],
211
- TAG_JOB_URL => "#{env['BUILDKITE_BUILD_URL']}##{env['BUILDKITE_JOB_ID']}",
212
- TAG_PROVIDER_NAME => 'buildkite',
213
- TAG_WORKSPACE_PATH => env['BUILDKITE_BUILD_CHECKOUT_PATH'],
214
- Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['BUILDKITE_BUILD_AUTHOR'],
215
- Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['BUILDKITE_BUILD_AUTHOR_EMAIL'],
216
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILDKITE_MESSAGE'],
217
- TAG_NODE_NAME => env['BUILDKITE_AGENT_ID'],
218
- TAG_CI_ENV_VARS => {
219
- 'BUILDKITE_BUILD_ID' => env['BUILDKITE_BUILD_ID'],
220
- 'BUILDKITE_JOB_ID' => env['BUILDKITE_JOB_ID']
221
- }.to_json
222
- }
223
-
224
- extra_tags = env
225
- .select { |key| key.start_with?('BUILDKITE_AGENT_META_DATA_') }
226
- .map { |key, value| "#{key.to_s.sub('BUILDKITE_AGENT_META_DATA_', '').downcase}:#{value}" }
227
- .sort_by(&:length)
228
-
229
- tags[TAG_NODE_LABELS] = extra_tags.to_json unless extra_tags.empty?
230
-
231
- tags
232
- end
233
-
234
- def extract_circle_ci(env)
235
- {
236
- Core::Git::Ext::TAG_BRANCH => env['CIRCLE_BRANCH'],
237
- Core::Git::Ext::TAG_COMMIT_SHA => env['CIRCLE_SHA1'],
238
- Core::Git::Ext::TAG_REPOSITORY_URL => env['CIRCLE_REPOSITORY_URL'],
239
- Core::Git::Ext::TAG_TAG => env['CIRCLE_TAG'],
240
- TAG_PIPELINE_ID => env['CIRCLE_WORKFLOW_ID'],
241
- TAG_PIPELINE_NAME => env['CIRCLE_PROJECT_REPONAME'],
242
- TAG_PIPELINE_URL => "https://app.circleci.com/pipelines/workflows/#{env['CIRCLE_WORKFLOW_ID']}",
243
- TAG_JOB_NAME => env['CIRCLE_JOB'],
244
- TAG_JOB_URL => env['CIRCLE_BUILD_URL'],
245
- TAG_PROVIDER_NAME => 'circleci',
246
- TAG_WORKSPACE_PATH => env['CIRCLE_WORKING_DIRECTORY'],
247
- Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['BUILD_REQUESTEDFORID'],
248
- Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['BUILD_REQUESTEDFOREMAIL'],
249
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BUILD_SOURCEVERSIONMESSAGE'],
250
- TAG_CI_ENV_VARS => {
251
- 'CIRCLE_WORKFLOW_ID' => env['CIRCLE_WORKFLOW_ID'],
252
- 'CIRCLE_BUILD_NUM' => env['CIRCLE_BUILD_NUM']
253
- }.to_json
254
- }
255
- end
256
-
257
- def extract_github_actions(env)
258
- ref = env['GITHUB_HEAD_REF']
259
- ref = env['GITHUB_REF'] if ref.nil? || ref.empty?
260
- branch, tag = branch_or_tag(ref)
261
-
262
- pipeline_url = "#{env['GITHUB_SERVER_URL']}/#{env['GITHUB_REPOSITORY']}/actions/runs/#{env['GITHUB_RUN_ID']}"
263
- pipeline_url = "#{pipeline_url}/attempts/#{env['GITHUB_RUN_ATTEMPT']}" if env['GITHUB_RUN_ATTEMPT']
264
-
265
- {
266
- Core::Git::Ext::TAG_BRANCH => branch,
267
- Core::Git::Ext::TAG_COMMIT_SHA => env['GITHUB_SHA'],
268
- Core::Git::Ext::TAG_REPOSITORY_URL => "#{env['GITHUB_SERVER_URL']}/#{env['GITHUB_REPOSITORY']}.git",
269
- Core::Git::Ext::TAG_TAG => tag,
270
- TAG_JOB_URL => "#{env['GITHUB_SERVER_URL']}/#{env['GITHUB_REPOSITORY']}/commit/#{env['GITHUB_SHA']}/checks",
271
- TAG_JOB_NAME => env['GITHUB_JOB'],
272
- TAG_PIPELINE_ID => env['GITHUB_RUN_ID'],
273
- TAG_PIPELINE_NAME => env['GITHUB_WORKFLOW'],
274
- TAG_PIPELINE_NUMBER => env['GITHUB_RUN_NUMBER'],
275
- TAG_PIPELINE_URL => pipeline_url,
276
- TAG_PROVIDER_NAME => 'github',
277
- TAG_WORKSPACE_PATH => env['GITHUB_WORKSPACE'],
278
- TAG_CI_ENV_VARS => {
279
- 'GITHUB_SERVER_URL' => env['GITHUB_SERVER_URL'],
280
- 'GITHUB_REPOSITORY' => env['GITHUB_REPOSITORY'],
281
- 'GITHUB_RUN_ID' => env['GITHUB_RUN_ID'],
282
- 'GITHUB_RUN_ATTEMPT' => env['GITHUB_RUN_ATTEMPT'],
283
- }.reject { |_k, v| v.nil? }.to_json
284
- }
285
- end
286
-
287
- def extract_gitlab(env)
288
- commit_author_name, commit_author_email = extract_name_email(env['CI_COMMIT_AUTHOR'])
289
-
290
- {
291
- Core::Git::Ext::TAG_BRANCH => env['CI_COMMIT_REF_NAME'],
292
- Core::Git::Ext::TAG_COMMIT_SHA => env['CI_COMMIT_SHA'],
293
- Core::Git::Ext::TAG_REPOSITORY_URL => env['CI_REPOSITORY_URL'],
294
- Core::Git::Ext::TAG_TAG => env['CI_COMMIT_TAG'],
295
- Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => commit_author_name,
296
- Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => commit_author_email,
297
- Core::Git::Ext::TAG_COMMIT_AUTHOR_DATE => env['CI_COMMIT_TIMESTAMP'],
298
- TAG_STAGE_NAME => env['CI_JOB_STAGE'],
299
- TAG_JOB_NAME => env['CI_JOB_NAME'],
300
- TAG_JOB_URL => env['CI_JOB_URL'],
301
- TAG_PIPELINE_ID => env['CI_PIPELINE_ID'],
302
- TAG_PIPELINE_NAME => env['CI_PROJECT_PATH'],
303
- TAG_PIPELINE_NUMBER => env['CI_PIPELINE_IID'],
304
- TAG_PIPELINE_URL => env['CI_PIPELINE_URL'],
305
- TAG_PROVIDER_NAME => 'gitlab',
306
- TAG_WORKSPACE_PATH => env['CI_PROJECT_DIR'],
307
- TAG_NODE_LABELS => env['CI_RUNNER_TAGS'],
308
- TAG_NODE_NAME => env['CI_RUNNER_ID'],
309
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['CI_COMMIT_MESSAGE'],
310
- TAG_CI_ENV_VARS => {
311
- 'CI_PROJECT_URL' => env['CI_PROJECT_URL'],
312
- 'CI_PIPELINE_ID' => env['CI_PIPELINE_ID'],
313
- 'CI_JOB_ID' => env['CI_JOB_ID']
314
- }.to_json
315
- }
316
- end
317
-
318
- def extract_jenkins(env)
319
- branch, tag = branch_or_tag(env['GIT_BRANCH'])
320
-
321
- if (name = env['JOB_NAME'])
322
- name = name.gsub("/#{normalize_ref(branch)}", '') if branch
323
- name = name.split('/').reject { |v| v.nil? || v.include?('=') }.join('/')
324
- end
325
-
326
- node_labels = env['NODE_LABELS'].split.to_json unless env['NODE_LABELS'].nil?
327
-
328
- {
329
- Core::Git::Ext::TAG_BRANCH => branch,
330
- Core::Git::Ext::TAG_COMMIT_SHA => env['GIT_COMMIT'],
331
- Core::Git::Ext::TAG_REPOSITORY_URL => env['GIT_URL'] || env['GIT_URL_1'],
332
- Core::Git::Ext::TAG_TAG => tag,
333
- TAG_PIPELINE_ID => env['BUILD_TAG'],
334
- TAG_PIPELINE_NAME => name,
335
- TAG_PIPELINE_NUMBER => env['BUILD_NUMBER'],
336
- TAG_PIPELINE_URL => env['BUILD_URL'],
337
- TAG_PROVIDER_NAME => 'jenkins',
338
- TAG_WORKSPACE_PATH => env['WORKSPACE'],
339
- TAG_NODE_LABELS => node_labels,
340
- TAG_NODE_NAME => env['NODE_NAME'],
341
- TAG_CI_ENV_VARS => {
342
- 'DD_CUSTOM_TRACE_ID' => env['DD_CUSTOM_TRACE_ID']
343
- }.to_json
344
- }
345
- end
346
-
347
- def extract_teamcity(env)
348
- {
349
- TAG_PROVIDER_NAME => 'teamcity',
350
- TAG_JOB_NAME => env['TEAMCITY_BUILDCONF_NAME'],
351
- TAG_JOB_URL => env['BUILD_URL'],
352
- }
353
- end
354
-
355
- def extract_travis(env)
356
- {
357
- Core::Git::Ext::TAG_BRANCH => (env['TRAVIS_PULL_REQUEST_BRANCH'] || env['TRAVIS_BRANCH']),
358
- Core::Git::Ext::TAG_COMMIT_SHA => env['TRAVIS_COMMIT'],
359
- Core::Git::Ext::TAG_REPOSITORY_URL => "https://github.com/#{env['TRAVIS_REPO_SLUG']}.git",
360
- Core::Git::Ext::TAG_TAG => env['TRAVIS_TAG'],
361
- TAG_JOB_URL => env['TRAVIS_JOB_WEB_URL'],
362
- TAG_PIPELINE_ID => env['TRAVIS_BUILD_ID'],
363
- TAG_PIPELINE_NAME => env['TRAVIS_REPO_SLUG'],
364
- TAG_PIPELINE_NUMBER => env['TRAVIS_BUILD_NUMBER'],
365
- TAG_PIPELINE_URL => env['TRAVIS_BUILD_WEB_URL'],
366
- TAG_PROVIDER_NAME => 'travisci',
367
- TAG_WORKSPACE_PATH => env['TRAVIS_BUILD_DIR'],
368
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['TRAVIS_COMMIT_MESSAGE']
369
- }
370
- end
371
-
372
- def extract_bitrise(env)
373
- commit = (
374
- env['BITRISE_GIT_COMMIT'] || env['GIT_CLONE_COMMIT_HASH']
375
- )
376
- branch = (
377
- env['BITRISEIO_GIT_BRANCH_DEST'] || env['BITRISE_GIT_BRANCH']
378
- )
379
- commiter_email = (
380
- env['GIT_CLONE_COMMIT_COMMITER_EMAIL'] || env['GIT_CLONE_COMMIT_COMMITER_NAME']
381
- )
382
-
383
- {
384
- TAG_PROVIDER_NAME => 'bitrise',
385
- TAG_PIPELINE_ID => env['BITRISE_BUILD_SLUG'],
386
- TAG_PIPELINE_NAME => env['BITRISE_TRIGGERED_WORKFLOW_ID'],
387
- TAG_PIPELINE_NUMBER => env['BITRISE_BUILD_NUMBER'],
388
- TAG_PIPELINE_URL => env['BITRISE_BUILD_URL'],
389
- TAG_WORKSPACE_PATH => env['BITRISE_SOURCE_DIR'],
390
- Core::Git::Ext::TAG_REPOSITORY_URL => env['GIT_REPOSITORY_URL'],
391
- Core::Git::Ext::TAG_COMMIT_SHA => commit,
392
- Core::Git::Ext::TAG_BRANCH => branch,
393
- Core::Git::Ext::TAG_TAG => env['BITRISE_GIT_TAG'],
394
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env['BITRISE_GIT_MESSAGE'],
395
- Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env['GIT_CLONE_COMMIT_AUTHOR_NAME'],
396
- Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env['GIT_CLONE_COMMIT_AUTHOR_EMAIL'],
397
- Core::Git::Ext::TAG_COMMIT_COMMITTER_NAME => env['GIT_CLONE_COMMIT_COMMITER_NAME'],
398
- Core::Git::Ext::TAG_COMMIT_COMMITTER_EMAIL => commiter_email
399
- }
400
- end
401
-
402
- def extract_codefresh(env)
403
- branch, tag = branch_or_tag(env['CF_BRANCH'])
404
-
405
- {
406
- TAG_PROVIDER_NAME => 'codefresh',
407
- TAG_PIPELINE_ID => env['CF_BUILD_ID'],
408
- TAG_PIPELINE_NAME => env['CF_PIPELINE_NAME'],
409
- TAG_PIPELINE_URL => env['CF_BUILD_URL'],
410
- TAG_JOB_NAME => env['CF_STEP_NAME'],
411
- Core::Git::Ext::TAG_BRANCH => branch,
412
- Core::Git::Ext::TAG_TAG => tag,
413
- TAG_CI_ENV_VARS => {
414
- 'CF_BUILD_ID' => env['CF_BUILD_ID'],
415
- }.to_json
416
- }
417
- end
418
-
419
- def extract_user_defined_git(env)
420
- {
421
- Core::Git::Ext::TAG_REPOSITORY_URL => env[Core::Git::Ext::ENV_REPOSITORY_URL],
422
- Core::Git::Ext::TAG_COMMIT_SHA => env[Core::Git::Ext::ENV_COMMIT_SHA],
423
- Core::Git::Ext::TAG_BRANCH => env[Core::Git::Ext::ENV_BRANCH],
424
- Core::Git::Ext::TAG_TAG => env[Core::Git::Ext::ENV_TAG],
425
- Core::Git::Ext::TAG_COMMIT_MESSAGE => env[Core::Git::Ext::ENV_COMMIT_MESSAGE],
426
- Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => env[Core::Git::Ext::ENV_COMMIT_AUTHOR_NAME],
427
- Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => env[Core::Git::Ext::ENV_COMMIT_AUTHOR_EMAIL],
428
- Core::Git::Ext::TAG_COMMIT_AUTHOR_DATE => env[Core::Git::Ext::ENV_COMMIT_AUTHOR_DATE],
429
- Core::Git::Ext::TAG_COMMIT_COMMITTER_NAME => env[Core::Git::Ext::ENV_COMMIT_COMMITTER_NAME],
430
- Core::Git::Ext::TAG_COMMIT_COMMITTER_EMAIL => env[Core::Git::Ext::ENV_COMMIT_COMMITTER_EMAIL],
431
- Core::Git::Ext::TAG_COMMIT_COMMITTER_DATE => env[Core::Git::Ext::ENV_COMMIT_COMMITTER_DATE]
432
- }.reject { |_, v| v.nil? || v.strip.empty? }
433
- end
434
-
435
- def git_commit_users
436
- # Get committer and author information in one command.
437
- output = exec_git_command("git show -s --format='%an\t%ae\t%at\t%cn\t%ce\t%ct'")
438
- return unless output
439
-
440
- fields = output.split("\t").each(&:strip!)
441
-
442
- {
443
- author_name: fields[0],
444
- author_email: fields[1],
445
- # Because we can't get a reliable UTC time from all recent versions of git
446
- # We have to rely on converting the date to UTC ourselves.
447
- author_date: Time.at(fields[2].to_i).utc.to_datetime.iso8601,
448
- committer_name: fields[3],
449
- committer_email: fields[4],
450
- # Because we can't get a reliable UTC time from all recent versions of git
451
- # We have to rely on converting the date to UTC ourselves.
452
- committer_date: Time.at(fields[5].to_i).utc.to_datetime.iso8601
453
- }
454
- rescue => e
455
- Datadog.logger.debug(
456
- "Unable to read git commit users: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
457
- )
458
- nil
459
- end
460
-
461
- def git_repository_url
462
- exec_git_command('git ls-remote --get-url')
463
- rescue => e
464
- Datadog.logger.debug(
465
- "Unable to read git repository url: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
466
- )
467
- nil
468
- end
469
-
470
- def git_commit_message
471
- exec_git_command('git show -s --format=%s')
472
- rescue => e
473
- Datadog.logger.debug(
474
- "Unable to read git commit message: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
475
- )
476
- nil
477
- end
478
-
479
- def git_branch
480
- exec_git_command('git rev-parse --abbrev-ref HEAD')
481
- rescue => e
482
- Datadog.logger.debug(
483
- "Unable to read git branch: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
484
- )
485
- nil
486
- end
487
-
488
- def git_commit_sha
489
- exec_git_command('git rev-parse HEAD')
490
- rescue => e
491
- Datadog.logger.debug(
492
- "Unable to read git commit SHA: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
493
- )
494
- nil
495
- end
496
-
497
- def git_tag
498
- exec_git_command('git tag --points-at HEAD')
499
- rescue => e
500
- Datadog.logger.debug(
501
- "Unable to read git tag: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
502
- )
503
- nil
504
- end
505
-
506
- def git_base_directory
507
- exec_git_command('git rev-parse --show-toplevel')
508
- rescue => e
509
- Datadog.logger.debug(
510
- "Unable to read git base directory: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
511
- )
512
- nil
513
- end
514
-
515
- def exec_git_command(cmd)
516
- out, status = Open3.capture2e(cmd)
517
-
518
- raise "Failed to run git command #{cmd}: #{out}" unless status.success?
519
-
520
- out.strip! # There's always a "\n" at the end of the command output
521
-
522
- return nil if out.empty?
523
-
524
- out
525
- end
526
-
527
- def extract_local_git
528
- env = {
529
- TAG_WORKSPACE_PATH => git_base_directory,
530
- Core::Git::Ext::TAG_REPOSITORY_URL => git_repository_url,
531
- Core::Git::Ext::TAG_COMMIT_SHA => git_commit_sha,
532
- Core::Git::Ext::TAG_BRANCH => git_branch,
533
- Core::Git::Ext::TAG_TAG => git_tag,
534
- Core::Git::Ext::TAG_COMMIT_MESSAGE => git_commit_message
535
- }
536
-
537
- if (commit_users = git_commit_users)
538
- env.merge!(
539
- Core::Git::Ext::TAG_COMMIT_AUTHOR_NAME => commit_users[:author_name],
540
- Core::Git::Ext::TAG_COMMIT_AUTHOR_EMAIL => commit_users[:author_email],
541
- Core::Git::Ext::TAG_COMMIT_AUTHOR_DATE => commit_users[:author_date],
542
- Core::Git::Ext::TAG_COMMIT_COMMITTER_NAME => commit_users[:committer_name],
543
- Core::Git::Ext::TAG_COMMIT_COMMITTER_EMAIL => commit_users[:committer_email],
544
- Core::Git::Ext::TAG_COMMIT_COMMITTER_DATE => commit_users[:committer_date]
545
- )
546
- end
547
-
548
- env
549
- end
550
-
551
- def branch_or_tag(branch_or_tag)
552
- branch = tag = nil
553
- if branch_or_tag && branch_or_tag.include?('tags/')
554
- tag = branch_or_tag
555
- else
556
- branch = branch_or_tag
557
- end
558
-
559
- [branch, tag]
560
- end
561
-
562
- def extract_name_email(name_and_email)
563
- if name_and_email.include?('<') && (match = /^([^<]*)<([^>]*)>$/.match(name_and_email))
564
- name = match[1]
565
- name = name.strip if name
566
- email = match[2]
567
- return [name, email] if name && email
568
- end
569
-
570
- [nil, name_and_email]
571
- end
572
- end
573
- end
574
- end
575
- end
@@ -1,10 +0,0 @@
1
- module Datadog
2
- module CI
3
- module Ext
4
- # Defines constants for test tags
5
- module Settings
6
- ENV_MODE_ENABLED = 'DD_TRACE_CI_ENABLED'.freeze
7
- end
8
- end
9
- end
10
- end
@@ -1,35 +0,0 @@
1
- module Datadog
2
- module CI
3
- module Ext
4
- # Defines constants for test tags
5
- module Test
6
- CONTEXT_ORIGIN = 'ciapp-test'.freeze
7
-
8
- TAG_ARGUMENTS = 'test.arguments'.freeze
9
- TAG_FRAMEWORK = 'test.framework'.freeze
10
- TAG_FRAMEWORK_VERSION = 'test.framework_version'.freeze
11
- TAG_NAME = 'test.name'.freeze
12
- TAG_SKIP_REASON = 'test.skip_reason'.freeze # DEV: Not populated yet
13
- TAG_STATUS = 'test.status'.freeze
14
- TAG_SUITE = 'test.suite'.freeze
15
- TAG_TRAITS = 'test.traits'.freeze
16
- TAG_TYPE = 'test.type'.freeze
17
-
18
- # Environment runtime tags
19
- TAG_OS_ARCHITECTURE = 'os.architecture'.freeze
20
- TAG_OS_PLATFORM = 'os.platform'.freeze
21
- TAG_RUNTIME_NAME = 'runtime.name'.freeze
22
- TAG_RUNTIME_VERSION = 'runtime.version'.freeze
23
-
24
- # TODO: is there a better place for SPAN_KIND?
25
- TAG_SPAN_KIND = 'span.kind'.freeze
26
-
27
- module Status
28
- PASS = 'pass'.freeze
29
- FAIL = 'fail'.freeze
30
- SKIP = 'skip'.freeze
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../core/configuration/settings'
4
- require_relative '../core/configuration/components'
5
-
6
- require_relative 'configuration/settings'
7
- require_relative 'configuration/components'
8
-
9
- module Datadog
10
- module CI
11
- # Extends Datadog tracing with CI features
12
- module Extensions
13
- def self.activate!
14
- Core::Configuration::Settings.extend(CI::Configuration::Settings)
15
- Core::Configuration::Components.prepend(CI::Configuration::Components)
16
- end
17
- end
18
- end
19
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../tracing/metadata/ext'
4
- require_relative '../tracing/flush'
5
-
6
- module Datadog
7
- module CI
8
- module Flush
9
- # Common behavior for CI flushing
10
- module Tagging
11
- # Decorate a trace with CI tags
12
- def get_trace(trace_op)
13
- trace = trace_op.flush!
14
-
15
- # Origin tag is required on every span
16
- trace.spans.each do |span|
17
- span.set_tag(
18
- Tracing::Metadata::Ext::Distributed::TAG_ORIGIN,
19
- trace.origin
20
- )
21
- end
22
-
23
- trace
24
- end
25
- end
26
-
27
- # Consumes only completed traces (where all spans have finished)
28
- class Finished < Tracing::Flush::Finished
29
- prepend Tagging
30
- end
31
-
32
- # Performs partial trace flushing to avoid large traces residing in memory for too long
33
- class Partial < Tracing::Flush::Partial
34
- prepend Tagging
35
- end
36
- end
37
- end
38
- end