ddtrace 1.5.2 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -1
  3. data/ext/ddtrace_profiling_loader/ddtrace_profiling_loader.c +9 -2
  4. data/ext/ddtrace_profiling_loader/extconf.rb +17 -0
  5. data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +38 -2
  6. data/ext/ddtrace_profiling_native_extension/clock_id.h +1 -0
  7. data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +1 -0
  8. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +517 -42
  9. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.h +3 -0
  10. data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +208 -30
  11. data/ext/ddtrace_profiling_native_extension/collectors_stack.c +156 -46
  12. data/ext/ddtrace_profiling_native_extension/collectors_stack.h +11 -2
  13. data/ext/ddtrace_profiling_native_extension/extconf.rb +11 -1
  14. data/ext/ddtrace_profiling_native_extension/http_transport.c +83 -64
  15. data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +4 -4
  16. data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +3 -2
  17. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +59 -0
  18. data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +3 -0
  19. data/ext/ddtrace_profiling_native_extension/profiling.c +10 -0
  20. data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +0 -1
  21. data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +4 -2
  22. data/ext/ddtrace_profiling_native_extension/stack_recorder.c +45 -29
  23. data/ext/ddtrace_profiling_native_extension/stack_recorder.h +7 -7
  24. data/lib/datadog/appsec/contrib/rack/request_middleware.rb +4 -0
  25. data/lib/datadog/appsec/event.rb +6 -0
  26. data/lib/datadog/core/configuration/components.rb +20 -14
  27. data/lib/datadog/core/configuration/settings.rb +42 -4
  28. data/lib/datadog/core/diagnostics/environment_logger.rb +5 -1
  29. data/lib/datadog/core/utils/compression.rb +5 -1
  30. data/lib/datadog/core.rb +0 -54
  31. data/lib/datadog/profiling/collectors/cpu_and_wall_time.rb +12 -2
  32. data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +5 -3
  33. data/lib/datadog/profiling/exporter.rb +2 -4
  34. data/lib/datadog/profiling/http_transport.rb +1 -1
  35. data/lib/datadog/tracing/configuration/ext.rb +1 -0
  36. data/lib/datadog/tracing/contrib/aws/instrumentation.rb +2 -0
  37. data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
  38. data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +4 -0
  39. data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +2 -0
  40. data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +3 -0
  41. data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +2 -0
  42. data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +2 -0
  43. data/lib/datadog/tracing/contrib/excon/middleware.rb +2 -0
  44. data/lib/datadog/tracing/contrib/ext.rb +6 -0
  45. data/lib/datadog/tracing/contrib/faraday/middleware.rb +2 -0
  46. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +5 -0
  47. data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +7 -1
  48. data/lib/datadog/tracing/contrib/grpc/ext.rb +2 -0
  49. data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +47 -0
  50. data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +22 -0
  51. data/lib/datadog/tracing/contrib/hanami/ext.rb +24 -0
  52. data/lib/datadog/tracing/contrib/hanami/integration.rb +44 -0
  53. data/lib/datadog/tracing/contrib/hanami/patcher.rb +33 -0
  54. data/lib/datadog/tracing/contrib/hanami/plugin.rb +23 -0
  55. data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +41 -0
  56. data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +44 -0
  57. data/lib/datadog/tracing/contrib/http/instrumentation.rb +2 -0
  58. data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +2 -0
  59. data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +2 -0
  60. data/lib/datadog/tracing/contrib/mongodb/ext.rb +7 -0
  61. data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +4 -0
  62. data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +12 -0
  63. data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
  64. data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +16 -0
  65. data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +12 -0
  66. data/lib/datadog/tracing/contrib/pg/ext.rb +2 -1
  67. data/lib/datadog/tracing/contrib/pg/instrumentation.rb +34 -18
  68. data/lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb +43 -0
  69. data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +32 -0
  70. data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +28 -0
  71. data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +49 -0
  72. data/lib/datadog/tracing/contrib/rack/middlewares.rb +11 -5
  73. data/lib/datadog/tracing/contrib/redis/ext.rb +2 -0
  74. data/lib/datadog/tracing/contrib/redis/instrumentation.rb +4 -2
  75. data/lib/datadog/tracing/contrib/redis/patcher.rb +41 -0
  76. data/lib/datadog/tracing/contrib/redis/tags.rb +5 -0
  77. data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +2 -0
  78. data/lib/datadog/tracing/contrib/sinatra/env.rb +12 -23
  79. data/lib/datadog/tracing/contrib/sinatra/ext.rb +7 -3
  80. data/lib/datadog/tracing/contrib/sinatra/patcher.rb +2 -2
  81. data/lib/datadog/tracing/contrib/sinatra/tracer.rb +8 -80
  82. data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +14 -9
  83. data/lib/datadog/tracing/contrib.rb +1 -0
  84. data/lib/datadog/tracing/distributed/datadog_tags_codec.rb +84 -0
  85. data/lib/datadog/tracing/distributed/headers/datadog.rb +122 -30
  86. data/lib/datadog/tracing/distributed/headers/ext.rb +2 -0
  87. data/lib/datadog/tracing/flush.rb +1 -1
  88. data/lib/datadog/tracing/metadata/ext.rb +8 -0
  89. data/lib/datadog/tracing/propagation/http.rb +9 -1
  90. data/lib/datadog/tracing/sampling/ext.rb +31 -0
  91. data/lib/datadog/tracing/sampling/priority_sampler.rb +46 -4
  92. data/lib/datadog/tracing/sampling/rate_by_key_sampler.rb +8 -9
  93. data/lib/datadog/tracing/sampling/rate_by_service_sampler.rb +29 -5
  94. data/lib/datadog/tracing/sampling/rate_sampler.rb +10 -3
  95. data/lib/datadog/tracing/sampling/rule_sampler.rb +4 -3
  96. data/lib/datadog/tracing/sampling/span/ext.rb +0 -4
  97. data/lib/datadog/tracing/sampling/span/rule.rb +1 -1
  98. data/lib/datadog/tracing/sampling/span/sampler.rb +14 -3
  99. data/lib/datadog/tracing/trace_digest.rb +3 -0
  100. data/lib/datadog/tracing/trace_operation.rb +10 -0
  101. data/lib/datadog/tracing/trace_segment.rb +6 -0
  102. data/lib/datadog/tracing/tracer.rb +3 -1
  103. data/lib/datadog/tracing/writer.rb +7 -0
  104. data/lib/ddtrace/transport/trace_formatter.rb +7 -0
  105. data/lib/ddtrace/transport/traces.rb +1 -1
  106. data/lib/ddtrace/version.rb +2 -2
  107. metadata +18 -14
  108. data/lib/datadog/profiling/old_ext.rb +0 -42
  109. data/lib/datadog/profiling/transport/http/api/endpoint.rb +0 -85
  110. data/lib/datadog/profiling/transport/http/api/instance.rb +0 -38
  111. data/lib/datadog/profiling/transport/http/api/spec.rb +0 -42
  112. data/lib/datadog/profiling/transport/http/api.rb +0 -45
  113. data/lib/datadog/profiling/transport/http/builder.rb +0 -30
  114. data/lib/datadog/profiling/transport/http/client.rb +0 -37
  115. data/lib/datadog/profiling/transport/http/response.rb +0 -21
  116. data/lib/datadog/profiling/transport/http.rb +0 -118
@@ -19,6 +19,8 @@ module Datadog
19
19
  TAG_URL = 'elasticsearch.url'.freeze
20
20
  TAG_COMPONENT = 'elasticsearch'.freeze
21
21
  TAG_OPERATION_QUERY = 'query'.freeze
22
+
23
+ TAG_SYSTEM = 'elasticsearch'.freeze
22
24
  end
23
25
  end
24
26
  end
@@ -3,6 +3,7 @@
3
3
  require_relative '../../metadata/ext'
4
4
  require_relative '../analytics'
5
5
  require_relative 'ext'
6
+ require_relative '../ext'
6
7
  require_relative '../integration'
7
8
  require_relative '../patcher'
8
9
 
@@ -80,6 +81,8 @@ module Datadog
80
81
 
81
82
  span.span_type = Datadog::Tracing::Contrib::Elasticsearch::Ext::SPAN_TYPE_QUERY
82
83
 
84
+ span.set_tag(Contrib::Ext::DB::TAG_SYSTEM, Ext::TAG_SYSTEM)
85
+
83
86
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
84
87
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_QUERY)
85
88
 
@@ -131,6 +131,8 @@ module Datadog
131
131
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
132
132
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)
133
133
 
134
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
135
+
134
136
  uri = try_parse_uri
135
137
  return unless uri
136
138
 
@@ -67,6 +67,8 @@ module Datadog
67
67
  @datadog_multi_span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
68
68
  @datadog_multi_span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_MULTI_REQUEST)
69
69
 
70
+ @datadog_multi_span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
71
+
70
72
  # Tag as an external peer service
71
73
  @datadog_multi_span.set_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE, @datadog_multi_span.service)
72
74
 
@@ -116,6 +116,8 @@ module Datadog
116
116
  span.service = service_name(datum[:host], @options)
117
117
  span.span_type = Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND
118
118
 
119
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
120
+
119
121
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
120
122
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)
121
123
 
@@ -13,6 +13,12 @@ module Datadog
13
13
  TAG_STATEMENT = 'db.statement'
14
14
  TAG_ROW_COUNT = 'db.row_count'
15
15
  end
16
+
17
+ module RPC
18
+ TAG_SYSTEM = 'rpc.system'
19
+ TAG_SERVICE = 'rpc.service'
20
+ TAG_METHOD = 'rpc.method'
21
+ end
16
22
  end
17
23
  end
18
24
  end
@@ -42,6 +42,8 @@ module Datadog
42
42
  span.service = service_name(env[:url].host, options)
43
43
  span.span_type = Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND
44
44
 
45
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
46
+
45
47
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
46
48
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)
47
49
 
@@ -4,6 +4,7 @@ require_relative '../../../../tracing'
4
4
  require_relative '../../../metadata/ext'
5
5
  require_relative '../../analytics'
6
6
  require_relative '../ext'
7
+ require_relative '../../ext'
7
8
 
8
9
  module Datadog
9
10
  module Tracing
@@ -36,6 +37,10 @@ module Datadog
36
37
  def annotate!(trace, span, metadata, call)
37
38
  span.set_tags(metadata)
38
39
 
40
+ span.set_tag(Contrib::Ext::RPC::TAG_SYSTEM, Ext::TAG_SYSTEM)
41
+
42
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
43
+
39
44
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
40
45
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_CLIENT)
41
46
 
@@ -6,6 +6,7 @@ require_relative '../../../metadata/ext'
6
6
  require_relative '../../../propagation/grpc'
7
7
  require_relative '../../analytics'
8
8
  require_relative '../ext'
9
+ require_relative '../../ext'
9
10
 
10
11
  module Datadog
11
12
  module Tracing
@@ -19,10 +20,11 @@ module Datadog
19
20
  # its tracing context with a parent client-side context
20
21
  class Server < Base
21
22
  def trace(keywords)
23
+ method = keywords[:method]
22
24
  options = {
23
25
  span_type: Tracing::Metadata::Ext::HTTP::TYPE_INBOUND,
24
26
  service: service_name, # TODO: Remove server-side service name configuration
25
- resource: format_resource(keywords[:method]),
27
+ resource: format_resource(method),
26
28
  on_error: error_handler
27
29
  }
28
30
  metadata = keywords[:call].metadata
@@ -30,6 +32,10 @@ module Datadog
30
32
  set_distributed_context!(metadata)
31
33
 
32
34
  Tracing.trace(Ext::SPAN_SERVICE, **options) do |span|
35
+ span.set_tag(Contrib::Ext::RPC::TAG_SYSTEM, Ext::TAG_SYSTEM)
36
+ span.set_tag(Contrib::Ext::RPC::TAG_SERVICE, method.owner.to_s)
37
+ span.set_tag(Contrib::Ext::RPC::TAG_METHOD, method.name)
38
+
33
39
  annotate!(span, metadata)
34
40
 
35
41
  yield
@@ -17,6 +17,8 @@ module Datadog
17
17
  TAG_COMPONENT = 'grpc'.freeze
18
18
  TAG_OPERATION_CLIENT = 'client'.freeze
19
19
  TAG_OPERATION_SERVICE = 'service'.freeze
20
+
21
+ TAG_SYSTEM = 'grpc'.freeze
20
22
  end
21
23
  end
22
24
  end
@@ -0,0 +1,47 @@
1
+ # typed: ignore
2
+
3
+ require_relative '../../metadata/ext'
4
+ require_relative '../analytics'
5
+ require_relative 'ext'
6
+
7
+ module Datadog
8
+ module Tracing
9
+ module Contrib
10
+ module Hanami
11
+ # Hanami Instrumentation for `hanami.action`
12
+ class ActionTracer
13
+ def initialize(app, action)
14
+ @app = app
15
+ @action = action
16
+ end
17
+
18
+ def call(env)
19
+ Tracing.trace(
20
+ Ext::SPAN_ACTION,
21
+ resource: @action.to_s,
22
+ service: configuration[:service_name],
23
+ span_type: Tracing::Metadata::Ext::HTTP::TYPE_INBOUND
24
+ ) do |span_op, trace_op|
25
+ span_op.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
26
+ span_op.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ACTION)
27
+
28
+ if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
29
+ Contrib::Analytics.set_sample_rate(span_op, configuration[:analytics_sample_rate])
30
+ end
31
+
32
+ trace_op.resource = span_op.resource
33
+
34
+ @app.call(env)
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def configuration
41
+ Datadog.configuration.tracing[:hanami]
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,22 @@
1
+ # typed: ignore
2
+
3
+ require_relative '../../configuration/settings'
4
+ require_relative '../ext'
5
+
6
+ module Datadog
7
+ module Tracing
8
+ module Contrib
9
+ module Hanami
10
+ module Configuration
11
+ # Configuration for Hanami instrumentation
12
+ class Settings < Contrib::Configuration::Settings
13
+ option :enabled do |o|
14
+ o.default { env_to_bool(Ext::ENV_ENABLED, true) }
15
+ o.lazy
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # typed: ignore
2
+
3
+ module Datadog
4
+ module Tracing
5
+ module Contrib
6
+ module Hanami
7
+ # Hanami integration constants
8
+ # @public_api Changing resource names, tag names, or environment variables creates breaking changes.
9
+ module Ext
10
+ ENV_ENABLED = 'DD_TRACE_HANAMI_ENABLED'.freeze
11
+
12
+ SPAN_ACTION = 'hanami.action'.freeze
13
+ SPAN_ROUTING = 'hanami.routing'.freeze
14
+ SPAN_RENDER = 'hanami.render'.freeze
15
+
16
+ TAG_COMPONENT = 'hanami'.freeze
17
+ TAG_OPERATION_ACTION = 'action'.freeze
18
+ TAG_OPERATION_ROUTING = 'routing'.freeze
19
+ TAG_OPERATION_RENDER = 'render'.freeze
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ # typed: ignore
2
+
3
+ require_relative '../integration'
4
+ require_relative 'configuration/settings'
5
+ require_relative 'patcher'
6
+
7
+ module Datadog
8
+ module Tracing
9
+ module Contrib
10
+ module Hanami
11
+ # Description of Hanami integration
12
+ class Integration
13
+ include Contrib::Integration
14
+
15
+ MINIMUM_VERSION = Gem::Version.new('1.0.0')
16
+ MAXIMUM_VERSION = Gem::Version.new('2.0.0')
17
+
18
+ register_as :hanami
19
+
20
+ def self.version
21
+ Gem.loaded_specs['hanami'] && Gem.loaded_specs['hanami'].version
22
+ end
23
+
24
+ def self.loaded?
25
+ !defined?(::Hanami).nil?
26
+ end
27
+
28
+ def self.compatible?
29
+ # Tested with version larger than 1.x, but not 2.x version
30
+ super && version >= MINIMUM_VERSION && version < MAXIMUM_VERSION
31
+ end
32
+
33
+ def new_configuration
34
+ Configuration::Settings.new
35
+ end
36
+
37
+ def patcher
38
+ Patcher
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,33 @@
1
+ # typed: ignore
2
+
3
+ require_relative '../patcher'
4
+ require_relative 'action_tracer'
5
+ require_relative 'renderer_policy_tracing'
6
+ require_relative 'router_tracing'
7
+
8
+ module Datadog
9
+ module Tracing
10
+ module Contrib
11
+ module Hanami
12
+ # Patcher enables patching of Hanami
13
+ module Patcher
14
+ include Contrib::Patcher
15
+
16
+ module_function
17
+
18
+ def target_version
19
+ Integration.version
20
+ end
21
+
22
+ def patch
23
+ # For auto instrumentation, `plugin` must be required before `Hanami.boot`
24
+ require_relative 'plugin'
25
+
26
+ ::Hanami::Router.prepend(RouterTracing)
27
+ ::Hanami::RenderingPolicy.prepend(RendererPolicyTracing)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ # typed: ignore
2
+
3
+ ::Hanami.plugin do
4
+ Datadog.configure do |c|
5
+ c.tracing.instrument :rack
6
+ end
7
+
8
+ middleware.use Datadog::Tracing::Contrib::Rack::TraceMiddleware
9
+ end
10
+
11
+ ::Hanami::Application.singleton_class.prepend(
12
+ Module.new do
13
+ def inherited(base)
14
+ super
15
+
16
+ base.configure do
17
+ controller.prepare do
18
+ use Datadog::Tracing::Contrib::Hanami::ActionTracer, self
19
+ end
20
+ end
21
+ end
22
+ end
23
+ )
@@ -0,0 +1,41 @@
1
+ # typed: ignore
2
+
3
+ require_relative 'ext'
4
+ require_relative '../../metadata/ext'
5
+
6
+ module Datadog
7
+ module Tracing
8
+ module Contrib
9
+ module Hanami
10
+ # Hanami Instrumentation for `hanami.render`
11
+ module RendererPolicyTracing
12
+ def render(env, response)
13
+ action = env['hanami.action']
14
+ # env['hanami.action'] could be empty for endpoints without an action
15
+ #
16
+ # For example in config/routes.rb:
17
+ # get '/hello', to: ->(env) { [200, {}, ['Hello from Hanami!']] }
18
+ action_klass = (action && action.class) ||
19
+ ::Hanami::Routing::Default::NullAction
20
+
21
+ Tracing.trace(
22
+ Ext::SPAN_RENDER,
23
+ service: configuration[:service_name],
24
+ resource: action_klass.to_s,
25
+ span_type: Tracing::Metadata::Ext::HTTP::TYPE_INBOUND
26
+ ) do |span_op, _trace_op|
27
+ span_op.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
28
+ span_op.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_RENDER)
29
+
30
+ super
31
+ end
32
+ end
33
+
34
+ def configuration
35
+ Datadog.configuration.tracing[:hanami]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ # typed: ignore
2
+
3
+ require_relative 'ext'
4
+ require_relative '../../metadata/ext'
5
+
6
+ module Datadog
7
+ module Tracing
8
+ module Contrib
9
+ module Hanami
10
+ # Hanami Instrumentation for `hanami.routing`
11
+ module RouterTracing
12
+ def call(env)
13
+ return super if Tracing.active_span && Tracing.active_span.name == Ext::SPAN_ROUTING
14
+
15
+ Tracing.trace(
16
+ Ext::SPAN_ROUTING,
17
+ service: configuration[:service_name],
18
+ span_type: Tracing::Metadata::Ext::HTTP::TYPE_INBOUND
19
+ ) do |span_op, trace_op|
20
+ begin
21
+ span_op.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
22
+ span_op.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ROUTING)
23
+
24
+ span_op.resource = nil
25
+
26
+ super
27
+ ensure
28
+ span_op.resource ||= if trace_op.resource_override?
29
+ trace_op.resource
30
+ else
31
+ env['REQUEST_METHOD']
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ def configuration
38
+ Datadog.configuration.tracing[:hanami]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -70,6 +70,8 @@ module Datadog
70
70
  end
71
71
 
72
72
  def annotate_span_with_request!(span, request, request_options)
73
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
74
+
73
75
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
74
76
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)
75
77
 
@@ -51,6 +51,8 @@ module Datadog
51
51
  private
52
52
 
53
53
  def annotate_span_with_request!(span, req, req_options)
54
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
55
+
54
56
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
55
57
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)
56
58
 
@@ -51,6 +51,8 @@ module Datadog
51
51
  private
52
52
 
53
53
  def annotate_span_with_request!(span, req, req_options)
54
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
55
+
54
56
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
55
57
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST)
56
58
 
@@ -20,6 +20,13 @@ module Datadog
20
20
  TAG_ROWS = 'mongodb.rows'.freeze
21
21
  TAG_COMPONENT = 'mongodb'.freeze
22
22
  TAG_OPERATION_COMMAND = 'command'.freeze
23
+ TAG_SYSTEM = 'mongodb'.freeze
24
+
25
+ # Temporary namespace to accommodate unified tags which has naming collision, before
26
+ # making breaking changes
27
+ module DB
28
+ TAG_COLLECTION = 'db.mongodb.collection'.freeze
29
+ end
23
30
  end
24
31
  end
25
32
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative '../analytics'
4
4
  require_relative 'ext'
5
+ require_relative '../ext'
5
6
  require_relative 'parsers'
6
7
  require_relative '../../metadata/ext'
7
8
 
@@ -30,6 +31,8 @@ module Datadog
30
31
  query = MongoDB.query_builder(event.command_name, event.database_name, event.command)
31
32
  serialized_query = query.to_s
32
33
 
34
+ span.set_tag(Contrib::Ext::DB::TAG_SYSTEM, Ext::TAG_SYSTEM)
35
+
33
36
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
34
37
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_COMMAND)
35
38
 
@@ -44,6 +47,7 @@ module Datadog
44
47
  # since it has been quantized and reduced
45
48
  span.set_tag(Ext::TAG_DB, query['database'])
46
49
  span.set_tag(Ext::TAG_COLLECTION, query['collection'])
50
+ span.set_tag(Ext::DB::TAG_COLLECTION, query['collection'])
47
51
  span.set_tag(Ext::TAG_OPERATION, query['operation'])
48
52
  span.set_tag(Ext::TAG_QUERY, serialized_query)
49
53
  span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, event.address.host)
@@ -3,6 +3,8 @@
3
3
  require_relative '../../configuration/settings'
4
4
  require_relative '../ext'
5
5
 
6
+ require_relative '../../propagation/sql_comment'
7
+
6
8
  module Datadog
7
9
  module Tracing
8
10
  module Contrib
@@ -27,6 +29,16 @@ module Datadog
27
29
  end
28
30
 
29
31
  option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
32
+
33
+ option :comment_propagation do |o|
34
+ o.default do
35
+ ENV.fetch(
36
+ Contrib::Propagation::SqlComment::Ext::ENV_DBM_PROPAGATION_MODE,
37
+ Contrib::Propagation::SqlComment::Ext::DISABLED
38
+ )
39
+ end
40
+ o.lazy
41
+ end
30
42
  end
31
43
  end
32
44
  end
@@ -15,6 +15,7 @@ module Datadog
15
15
  TAG_DB_NAME = 'mysql2.db.name'.freeze
16
16
  TAG_COMPONENT = 'mysql2'.freeze
17
17
  TAG_OPERATION_QUERY = 'query'.freeze
18
+ TAG_SYSTEM = 'mysql'.freeze
18
19
  end
19
20
  end
20
21
  end
@@ -3,6 +3,9 @@
3
3
  require_relative '../../metadata/ext'
4
4
  require_relative '../analytics'
5
5
  require_relative 'ext'
6
+ require_relative '../ext'
7
+ require_relative '../propagation/sql_comment'
8
+ require_relative '../propagation/sql_comment/mode'
6
9
 
7
10
  module Datadog
8
11
  module Tracing
@@ -23,6 +26,9 @@ module Datadog
23
26
  span.resource = sql
24
27
  span.span_type = Tracing::Metadata::Ext::SQL::TYPE
25
28
 
29
+ span.set_tag(Contrib::Ext::DB::TAG_SYSTEM, Ext::TAG_SYSTEM)
30
+ span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
31
+
26
32
  span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
27
33
  span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_QUERY)
28
34
 
@@ -36,6 +42,12 @@ module Datadog
36
42
  span.set_tag(Ext::TAG_DB_NAME, query_options[:database])
37
43
  span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, query_options[:host])
38
44
  span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, query_options[:port])
45
+
46
+ propagation_mode = Contrib::Propagation::SqlComment::Mode.new(comment_propagation)
47
+
48
+ Contrib::Propagation::SqlComment.annotate!(span, propagation_mode)
49
+ sql = Contrib::Propagation::SqlComment.prepend_comment(sql, span, propagation_mode)
50
+
39
51
  super(sql, options)
40
52
  end
41
53
  end
@@ -53,6 +65,10 @@ module Datadog
53
65
  def analytics_sample_rate
54
66
  datadog_configuration[:analytics_sample_rate]
55
67
  end
68
+
69
+ def comment_propagation
70
+ datadog_configuration[:comment_propagation]
71
+ end
56
72
  end
57
73
  end
58
74
  end
@@ -3,6 +3,8 @@
3
3
  require_relative '../../configuration/settings'
4
4
  require_relative '../ext'
5
5
 
6
+ require_relative '../../propagation/sql_comment/ext'
7
+
6
8
  module Datadog
7
9
  module Tracing
8
10
  module Contrib
@@ -27,6 +29,16 @@ module Datadog
27
29
  end
28
30
 
29
31
  option :service_name, default: Ext::DEFAULT_PEER_SERVICE_NAME
32
+
33
+ option :comment_propagation do |o|
34
+ o.default do
35
+ ENV.fetch(
36
+ Contrib::Propagation::SqlComment::Ext::ENV_DBM_PROPAGATION_MODE,
37
+ Contrib::Propagation::SqlComment::Ext::DISABLED
38
+ )
39
+ end
40
+ o.lazy
41
+ end
30
42
  end
31
43
  end
32
44
  end
@@ -11,7 +11,6 @@ module Datadog
11
11
  ENV_ANALYTICS_ENABLED = 'DD_TRACE_PG_ANALYTICS_ENABLED'.freeze
12
12
  ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_PG_ANALYTICS_SAMPLE_RATE'.freeze
13
13
  DEFAULT_PEER_SERVICE_NAME = 'pg'.freeze
14
- SPAN_SYSTEM = 'postgresql'.freeze
15
14
  SPAN_EXEC = 'pg.exec'.freeze
16
15
  SPAN_EXEC_PARAMS = 'pg.exec.params'.freeze
17
16
  SPAN_EXEC_PREPARED = 'pg.exec.prepared'.freeze
@@ -24,6 +23,8 @@ module Datadog
24
23
  TAG_DB_NAME = 'pg.db.name'.freeze
25
24
  TAG_COMPONENT = 'pg'.freeze
26
25
  TAG_OPERATION_QUERY = 'query'.freeze
26
+
27
+ TAG_SYSTEM = 'postgresql'.freeze
27
28
  end
28
29
  end
29
30
  end