datadog 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +66 -2
- data/README.md +1 -1
- data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +19 -1
- data/ext/datadog_profiling_native_extension/collectors_stack.c +41 -0
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +1 -1
- data/ext/datadog_profiling_native_extension/crashtracker.c +1 -1
- data/ext/datadog_profiling_native_extension/extconf.rb +6 -4
- data/ext/datadog_profiling_native_extension/native_extension_helpers.rb +47 -1
- data/ext/datadog_profiling_native_extension/setup_signal_handler.c +1 -1
- data/ext/datadog_profiling_native_extension/stack_recorder.c +13 -6
- data/ext/datadog_profiling_native_extension/stack_recorder.h +1 -0
- data/lib/datadog/appsec/configuration/settings.rb +5 -0
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +0 -1
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +1 -1
- data/lib/datadog/appsec/extensions.rb +1 -0
- data/lib/datadog/core/configuration/components.rb +6 -3
- data/lib/datadog/core/configuration/ext.rb +1 -0
- data/lib/datadog/core/configuration/option.rb +21 -14
- data/lib/datadog/core/configuration/options.rb +5 -1
- data/lib/datadog/core/configuration/settings.rb +68 -5
- data/lib/datadog/core/configuration.rb +3 -17
- data/lib/datadog/core/deprecations.rb +58 -0
- data/lib/datadog/core/environment/ext.rb +2 -0
- data/lib/datadog/core/environment/yjit.rb +5 -0
- data/lib/datadog/core/runtime/ext.rb +2 -0
- data/lib/datadog/core/runtime/metrics.rb +6 -0
- data/lib/datadog/core/telemetry/component.rb +107 -0
- data/lib/datadog/core/telemetry/event.rb +124 -31
- data/lib/datadog/core/telemetry/ext.rb +2 -0
- data/lib/datadog/core/telemetry/http/adapters/net.rb +1 -1
- data/lib/datadog/core/telemetry/metric.rb +167 -0
- data/lib/datadog/core/telemetry/metrics_collection.rb +81 -0
- data/lib/datadog/core/telemetry/metrics_manager.rb +81 -0
- data/lib/datadog/core/telemetry/request.rb +1 -1
- data/lib/datadog/core/telemetry/worker.rb +173 -0
- data/lib/datadog/core/utils/only_once_successful.rb +76 -0
- data/lib/datadog/core.rb +2 -19
- data/lib/datadog/opentelemetry/sdk/propagator.rb +5 -10
- data/lib/datadog/opentelemetry/sdk/span_processor.rb +5 -2
- data/lib/datadog/profiling/collectors/code_provenance.rb +18 -5
- data/lib/datadog/profiling/component.rb +18 -1
- data/lib/datadog/profiling/ext/dir_monkey_patches.rb +410 -0
- data/lib/datadog/profiling.rb +1 -0
- data/lib/datadog/tracing/configuration/ext.rb +7 -0
- data/lib/datadog/tracing/configuration/settings.rb +52 -3
- data/lib/datadog/tracing/contrib/action_cable/event.rb +1 -1
- data/lib/datadog/tracing/contrib/action_cable/events/broadcast.rb +1 -1
- data/lib/datadog/tracing/contrib/action_cable/events/perform_action.rb +1 -1
- data/lib/datadog/tracing/contrib/action_cable/events/transmit.rb +1 -1
- data/lib/datadog/tracing/contrib/action_mailer/event.rb +4 -6
- data/lib/datadog/tracing/contrib/action_mailer/events/deliver.rb +9 -4
- data/lib/datadog/tracing/contrib/action_mailer/events/process.rb +3 -2
- data/lib/datadog/tracing/contrib/action_view/events/render_partial.rb +1 -5
- data/lib/datadog/tracing/contrib/action_view/events/render_template.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/discard.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/enqueue.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_at.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/enqueue_retry.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/perform.rb +1 -1
- data/lib/datadog/tracing/contrib/active_job/events/retry_stopped.rb +1 -1
- data/lib/datadog/tracing/contrib/active_model_serializers/events/render.rb +1 -1
- data/lib/datadog/tracing/contrib/active_model_serializers/events/serialize.rb +1 -1
- data/lib/datadog/tracing/contrib/active_record/events/instantiation.rb +1 -1
- data/lib/datadog/tracing/contrib/active_record/events/sql.rb +1 -1
- data/lib/datadog/tracing/contrib/active_support/cache/event.rb +32 -0
- data/lib/datadog/tracing/contrib/active_support/cache/events/cache.rb +156 -0
- data/lib/datadog/tracing/contrib/active_support/cache/events.rb +34 -0
- data/lib/datadog/tracing/contrib/active_support/cache/instrumentation.rb +45 -41
- data/lib/datadog/tracing/contrib/active_support/cache/patcher.rb +17 -40
- data/lib/datadog/tracing/contrib/active_support/cache/redis.rb +4 -1
- data/lib/datadog/tracing/contrib/active_support/notifications/event.rb +29 -6
- data/lib/datadog/tracing/contrib/active_support/notifications/subscriber.rb +16 -4
- data/lib/datadog/tracing/contrib/active_support/notifications/subscription.rb +33 -29
- data/lib/datadog/tracing/contrib/analytics.rb +5 -0
- data/lib/datadog/tracing/contrib/graphql/configuration/settings.rb +5 -0
- data/lib/datadog/tracing/contrib/graphql/patcher.rb +8 -2
- data/lib/datadog/tracing/contrib/graphql/unified_trace.rb +166 -0
- data/lib/datadog/tracing/contrib/graphql/unified_trace_patcher.rb +25 -0
- data/lib/datadog/tracing/contrib/kafka/consumer_event.rb +1 -1
- data/lib/datadog/tracing/contrib/kafka/consumer_group_event.rb +1 -1
- data/lib/datadog/tracing/contrib/kafka/event.rb +1 -1
- data/lib/datadog/tracing/contrib/kafka/events/connection/request.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_batch.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/consumer/process_message.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/consumer_group/heartbeat.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/produce_operation/send_messages.rb +3 -3
- data/lib/datadog/tracing/contrib/kafka/events/producer/deliver_messages.rb +3 -3
- data/lib/datadog/tracing/contrib/racecar/event.rb +2 -2
- data/lib/datadog/tracing/contrib/rails/ext.rb +9 -0
- data/lib/datadog/tracing/contrib/rails/patcher.rb +7 -0
- data/lib/datadog/tracing/contrib/rails/runner.rb +95 -0
- data/lib/datadog/tracing/distributed/b3_multi.rb +1 -1
- data/lib/datadog/tracing/distributed/b3_single.rb +3 -1
- data/lib/datadog/tracing/distributed/datadog.rb +2 -2
- data/lib/datadog/tracing/distributed/propagation.rb +39 -4
- data/lib/datadog/tracing/distributed/trace_context.rb +5 -3
- data/lib/datadog/tracing/metadata/ext.rb +1 -0
- data/lib/datadog/tracing/span_operation.rb +3 -2
- data/lib/datadog/tracing/trace_operation.rb +7 -3
- data/lib/datadog/tracing/trace_segment.rb +4 -1
- data/lib/datadog/tracing/tracer.rb +9 -2
- data/lib/datadog/tracing.rb +5 -1
- data/lib/datadog/version.rb +2 -2
- metadata +21 -8
- data/lib/datadog/core/telemetry/client.rb +0 -95
- data/lib/datadog/core/telemetry/heartbeat.rb +0 -33
@@ -26,21 +26,25 @@ module Datadog
|
|
26
26
|
super
|
27
27
|
end
|
28
28
|
|
29
|
-
def subscription(span_name = nil,
|
29
|
+
def subscription(span_name = nil, span_options = nil, on_start: nil, on_finish: nil, trace: nil)
|
30
30
|
super(
|
31
31
|
span_name || self.span_name,
|
32
|
-
|
33
|
-
|
32
|
+
span_options || self.span_options,
|
33
|
+
on_start: on_start,
|
34
|
+
on_finish: on_finish,
|
35
|
+
trace: trace
|
34
36
|
)
|
35
37
|
end
|
36
38
|
|
37
|
-
def subscribe(pattern = nil, span_name = nil,
|
39
|
+
def subscribe(pattern = nil, span_name = nil, span_options = nil)
|
38
40
|
if supported?
|
39
41
|
super(
|
40
42
|
pattern || event_name,
|
41
43
|
span_name || self.span_name,
|
42
|
-
|
43
|
-
|
44
|
+
span_options || self.span_options,
|
45
|
+
on_start: method(:on_start),
|
46
|
+
on_finish: method(:on_finish),
|
47
|
+
trace: method(:trace?)
|
44
48
|
)
|
45
49
|
end
|
46
50
|
end
|
@@ -62,6 +66,25 @@ module Datadog
|
|
62
66
|
payload[:exception_object] ||
|
63
67
|
payload[:exception] # Fallback for ActiveSupport < 5.0
|
64
68
|
end
|
69
|
+
|
70
|
+
def on_start(_span, _event, _id, _payload); end
|
71
|
+
|
72
|
+
def on_finish(span, _event, _id, payload)
|
73
|
+
record_exception(span, payload)
|
74
|
+
end
|
75
|
+
|
76
|
+
def trace?(_event, _payload)
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
def record_exception(span, payload)
|
81
|
+
if payload[:exception_object]
|
82
|
+
span.set_error(payload[:exception_object])
|
83
|
+
elsif payload[:exception]
|
84
|
+
# Fallback for ActiveSupport < 5.0
|
85
|
+
span.set_error(payload[:exception])
|
86
|
+
end
|
87
|
+
end
|
65
88
|
end
|
66
89
|
end
|
67
90
|
end
|
@@ -45,16 +45,28 @@ module Datadog
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# Creates a subscription and immediately activates it.
|
48
|
-
def subscribe(pattern, span_name,
|
49
|
-
subscription(
|
48
|
+
def subscribe(pattern, span_name, span_options = {}, on_start: nil, on_finish: nil, trace: nil)
|
49
|
+
subscription(
|
50
|
+
span_name,
|
51
|
+
span_options,
|
52
|
+
on_start: on_start,
|
53
|
+
on_finish: on_finish,
|
54
|
+
trace: trace
|
55
|
+
).tap do |subscription|
|
50
56
|
subscription.subscribe(pattern)
|
51
57
|
end
|
52
58
|
end
|
53
59
|
|
54
60
|
# Creates a subscription without activating it.
|
55
61
|
# Subscription is added to the inheriting class' list of subscriptions.
|
56
|
-
def subscription(span_name,
|
57
|
-
Subscription.new(
|
62
|
+
def subscription(span_name, span_options = {}, on_start: nil, on_finish: nil, trace: nil)
|
63
|
+
Subscription.new(
|
64
|
+
span_name,
|
65
|
+
span_options,
|
66
|
+
on_start: on_start,
|
67
|
+
on_finish: on_finish,
|
68
|
+
trace: trace
|
69
|
+
).tap do |subscription|
|
58
70
|
subscriptions << subscription
|
59
71
|
end
|
60
72
|
end
|
@@ -9,31 +9,34 @@ module Datadog
|
|
9
9
|
class Subscription
|
10
10
|
attr_accessor \
|
11
11
|
:span_name,
|
12
|
-
:
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
:span_options
|
13
|
+
|
14
|
+
# @param span_name [String] the operation name for the span
|
15
|
+
# @param span_options [Hash] span_options to pass during span creation
|
16
|
+
# @param on_start [Proc] a block to run when the event is fired,
|
17
|
+
# might not include all required information in the `payload` argument.
|
18
|
+
# @param on_finish [Proc] a block to run when the event has finished processing,
|
19
|
+
# possibly including more information in the `payload` argument.
|
20
|
+
# @param trace [Proc] whether to trace the event. Defaults to returning `true`.
|
21
|
+
def initialize(span_name, span_options, on_start: nil, on_finish: nil, trace: nil)
|
22
|
+
raise ArgumentError, 'Must be given either on_start or on_finish' unless on_start || on_finish
|
16
23
|
|
17
24
|
@span_name = span_name
|
18
|
-
@
|
19
|
-
@
|
25
|
+
@span_options = span_options
|
26
|
+
@on_start = Handler.new(on_start)
|
27
|
+
@on_finish = Handler.new(on_finish)
|
28
|
+
@trace = trace
|
20
29
|
@callbacks = Callbacks.new
|
21
30
|
end
|
22
31
|
|
23
|
-
# ActiveSupport
|
24
|
-
def call(name, start, finish, id, payload)
|
25
|
-
start_span(name, id, payload, start)
|
26
|
-
finish_span(name, id, payload, finish)
|
27
|
-
end
|
28
|
-
|
29
|
-
# ActiveSupport 4+ calls this on start
|
32
|
+
# Called by ActiveSupport on event start
|
30
33
|
def start(name, id, payload)
|
31
|
-
start_span(name, id, payload)
|
34
|
+
start_span(name, id, payload) if @trace&.call(name, payload)
|
32
35
|
end
|
33
36
|
|
34
|
-
#
|
37
|
+
# Called by ActiveSupport on event finish
|
35
38
|
def finish(name, id, payload)
|
36
|
-
finish_span(name, id, payload)
|
39
|
+
finish_span(name, id, payload) if payload[:datadog_span]
|
37
40
|
end
|
38
41
|
|
39
42
|
def before_trace(&block)
|
@@ -69,7 +72,8 @@ module Datadog
|
|
69
72
|
protected
|
70
73
|
|
71
74
|
attr_reader \
|
72
|
-
:
|
75
|
+
:on_start,
|
76
|
+
:on_finish,
|
73
77
|
:callbacks
|
74
78
|
|
75
79
|
def start_span(name, id, payload, start = nil)
|
@@ -77,11 +81,15 @@ module Datadog
|
|
77
81
|
callbacks.run(name, :before_trace, id, payload, start)
|
78
82
|
|
79
83
|
# Start a trace
|
80
|
-
Tracing.trace(@span_name, **@
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
84
|
+
span = Tracing.trace(@span_name, **@span_options)
|
85
|
+
|
86
|
+
# Start span if time is provided
|
87
|
+
span.start(start) unless start.nil?
|
88
|
+
payload[:datadog_span] = span
|
89
|
+
|
90
|
+
on_start.run(span, name, id, payload)
|
91
|
+
|
92
|
+
span
|
85
93
|
end
|
86
94
|
|
87
95
|
def finish_span(name, id, payload, finish = nil)
|
@@ -90,7 +98,7 @@ module Datadog
|
|
90
98
|
return nil if span.nil?
|
91
99
|
|
92
100
|
# Run handler for event
|
93
|
-
|
101
|
+
on_finish.run(span, name, id, payload)
|
94
102
|
|
95
103
|
# Finish the span
|
96
104
|
span.finish(finish)
|
@@ -109,21 +117,17 @@ module Datadog
|
|
109
117
|
class Handler
|
110
118
|
attr_reader :block
|
111
119
|
|
112
|
-
def initialize(
|
120
|
+
def initialize(block)
|
113
121
|
@block = block
|
114
122
|
end
|
115
123
|
|
116
124
|
def run(span, name, id, payload)
|
117
|
-
|
125
|
+
@block.call(span, name, id, payload) if @block
|
118
126
|
rescue StandardError => e
|
119
127
|
Datadog.logger.debug(
|
120
128
|
"ActiveSupport::Notifications handler for '#{name}' failed: #{e.class.name} #{e.message}"
|
121
129
|
)
|
122
130
|
end
|
123
|
-
|
124
|
-
def run!(*args)
|
125
|
-
@block.call(*args)
|
126
|
-
end
|
127
131
|
end
|
128
132
|
|
129
133
|
# Wrapper for subscription callbacks
|
@@ -9,6 +9,11 @@ module Datadog
|
|
9
9
|
module Analytics
|
10
10
|
module_function
|
11
11
|
|
12
|
+
# Applies Analytics sampling rate, if applicable for this Contrib::Configuration.
|
13
|
+
def set_rate!(span, configuration)
|
14
|
+
set_sample_rate(span, configuration[:analytics_sample_rate]) if enabled?(configuration[:analytics_enabled])
|
15
|
+
end
|
16
|
+
|
12
17
|
# Checks whether analytics should be enabled.
|
13
18
|
# `flag` is a truthy/falsey value that represents a setting on the integration.
|
14
19
|
def enabled?(flag = nil)
|
@@ -4,6 +4,7 @@ require_relative '../analytics'
|
|
4
4
|
require_relative '../patcher'
|
5
5
|
require_relative 'tracing_patcher'
|
6
6
|
require_relative 'trace_patcher'
|
7
|
+
require_relative 'unified_trace_patcher'
|
7
8
|
|
8
9
|
module Datadog
|
9
10
|
module Tracing
|
@@ -23,10 +24,15 @@ module Datadog
|
|
23
24
|
if configuration[:with_deprecated_tracer]
|
24
25
|
TracingPatcher.patch!(schemas, trace_options)
|
25
26
|
elsif Integration.trace_supported?
|
26
|
-
|
27
|
+
if configuration[:with_unified_tracer]
|
28
|
+
UnifiedTracePatcher.patch!(schemas, trace_options)
|
29
|
+
else
|
30
|
+
TracePatcher.patch!(schemas, trace_options)
|
31
|
+
end
|
27
32
|
else
|
28
33
|
Datadog.logger.warn(
|
29
|
-
"GraphQL version (#{target_version}) does not support GraphQL::Tracing::DataDogTrace
|
34
|
+
"GraphQL version (#{target_version}) does not support GraphQL::Tracing::DataDogTrace"\
|
35
|
+
'or Datadog::Tracing::Contrib::GraphQL::UnifiedTrace.'\
|
30
36
|
'Falling back to GraphQL::Tracing::DataDogTracing.'
|
31
37
|
)
|
32
38
|
TracingPatcher.patch!(schemas, trace_options)
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql/tracing'
|
4
|
+
|
5
|
+
module Datadog
|
6
|
+
module Tracing
|
7
|
+
module Contrib
|
8
|
+
module GraphQL
|
9
|
+
# These methods will be called by the GraphQL runtime to trace the execution of queries.
|
10
|
+
# This tracer differs from the upstream one as it follows the unified naming convention specification,
|
11
|
+
# which is required to use features such as API Catalog.
|
12
|
+
# DEV-3.0: This tracer should be the default one in the next major version.
|
13
|
+
module UnifiedTrace
|
14
|
+
# @param analytics_enabled [Boolean] Deprecated
|
15
|
+
# @param analytics_sample_rate [Float] Deprecated
|
16
|
+
# @param service [String|nil] The service name to be set on the spans
|
17
|
+
def initialize(*args, analytics_enabled: false, analytics_sample_rate: 1.0, service: nil, **kwargs)
|
18
|
+
@analytics_enabled = analytics_enabled
|
19
|
+
@analytics_sample_rate = analytics_sample_rate
|
20
|
+
|
21
|
+
@service_name = service
|
22
|
+
@has_prepare_span = respond_to?(:prepare_span)
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def lex(*args, query_string:, **kwargs)
|
27
|
+
trace(proc { super }, 'lex', query_string, query_string: query_string)
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse(*args, query_string:, **kwargs)
|
31
|
+
trace(proc { super }, 'parse', query_string, query_string: query_string) do |span|
|
32
|
+
span.set_tag('graphql.source', query_string)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def validate(*args, query:, validate:, **kwargs)
|
37
|
+
trace(proc { super }, 'validate', query.selected_operation_name, query: query, validate: validate) do |span|
|
38
|
+
span.set_tag('graphql.source', query.query_string)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def analyze_multiplex(*args, multiplex:, **kwargs)
|
43
|
+
trace(proc { super }, 'analyze_multiplex', multiplex_resource(multiplex), multiplex: multiplex)
|
44
|
+
end
|
45
|
+
|
46
|
+
def analyze_query(*args, query:, **kwargs)
|
47
|
+
trace(proc { super }, 'analyze', query.query_string, query: query)
|
48
|
+
end
|
49
|
+
|
50
|
+
def execute_multiplex(*args, multiplex:, **kwargs)
|
51
|
+
trace(proc { super }, 'execute_multiplex', multiplex_resource(multiplex), multiplex: multiplex) do |span|
|
52
|
+
span.set_tag('graphql.source', "Multiplex[#{multiplex.queries.map(&:query_string).join(', ')}]")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def execute_query(*args, query:, **kwargs)
|
57
|
+
trace(proc { super }, 'execute', query.selected_operation_name, query: query) do |span|
|
58
|
+
span.set_tag('graphql.source', query.query_string)
|
59
|
+
span.set_tag('graphql.operation.type', query.selected_operation.operation_type)
|
60
|
+
span.set_tag('graphql.operation.name', query.selected_operation_name) if query.selected_operation_name
|
61
|
+
query.variables.instance_variable_get(:@storage).each do |key, value|
|
62
|
+
span.set_tag("graphql.variables.#{key}", value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def execute_query_lazy(*args, query:, multiplex:, **kwargs)
|
68
|
+
resource = if query
|
69
|
+
query.selected_operation_name || fallback_transaction_name(query.context)
|
70
|
+
else
|
71
|
+
multiplex_resource(multiplex)
|
72
|
+
end
|
73
|
+
trace(proc { super }, 'execute_lazy', resource, query: query, multiplex: multiplex)
|
74
|
+
end
|
75
|
+
|
76
|
+
def execute_field_span(callable, span_key, **kwargs)
|
77
|
+
# @platform_key_cache is initialized upstream, in ::GraphQL::Tracing::PlatformTrace
|
78
|
+
platform_key = @platform_key_cache[UnifiedTrace].platform_field_key_cache[kwargs[:field]]
|
79
|
+
|
80
|
+
if platform_key
|
81
|
+
trace(callable, span_key, platform_key, **kwargs) do |span|
|
82
|
+
kwargs[:arguments].each do |key, value|
|
83
|
+
span.set_tag("graphql.variables.#{key}", value)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
else
|
87
|
+
callable.call
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def execute_field(*args, **kwargs)
|
92
|
+
execute_field_span(proc { super }, 'resolve', **kwargs)
|
93
|
+
end
|
94
|
+
|
95
|
+
def execute_field_lazy(*args, **kwargs)
|
96
|
+
execute_field_span(proc { super }, 'resolve_lazy', **kwargs)
|
97
|
+
end
|
98
|
+
|
99
|
+
def authorized_span(callable, span_key, **kwargs)
|
100
|
+
platform_key = @platform_key_cache[UnifiedTrace].platform_authorized_key_cache[kwargs[:type]]
|
101
|
+
trace(callable, span_key, platform_key, **kwargs)
|
102
|
+
end
|
103
|
+
|
104
|
+
def authorized(*args, **kwargs)
|
105
|
+
authorized_span(proc { super }, 'authorized', **kwargs)
|
106
|
+
end
|
107
|
+
|
108
|
+
def authorized_lazy(*args, **kwargs)
|
109
|
+
authorized_span(proc { super }, 'authorized_lazy', **kwargs)
|
110
|
+
end
|
111
|
+
|
112
|
+
def resolve_type_span(callable, span_key, **kwargs)
|
113
|
+
platform_key = @platform_key_cache[UnifiedTrace].platform_resolve_type_key_cache[kwargs[:type]]
|
114
|
+
trace(callable, span_key, platform_key, **kwargs)
|
115
|
+
end
|
116
|
+
|
117
|
+
def resolve_type(*args, **kwargs)
|
118
|
+
resolve_type_span(proc { super }, 'resolve_type', **kwargs)
|
119
|
+
end
|
120
|
+
|
121
|
+
def resolve_type_lazy(*args, **kwargs)
|
122
|
+
resolve_type_span(proc { super }, 'resolve_type_lazy', **kwargs)
|
123
|
+
end
|
124
|
+
|
125
|
+
include ::GraphQL::Tracing::PlatformTrace
|
126
|
+
|
127
|
+
def platform_field_key(field, *args, **kwargs)
|
128
|
+
field.path
|
129
|
+
end
|
130
|
+
|
131
|
+
def platform_authorized_key(type, *args, **kwargs)
|
132
|
+
"#{type.graphql_name}.authorized"
|
133
|
+
end
|
134
|
+
|
135
|
+
def platform_resolve_type_key(type, *args, **kwargs)
|
136
|
+
"#{type.graphql_name}.resolve_type"
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def trace(callable, trace_key, resource, **kwargs)
|
142
|
+
Tracing.trace("graphql.#{trace_key}", resource: resource, service: @service_name, type: 'graphql') do |span|
|
143
|
+
yield(span) if block_given?
|
144
|
+
|
145
|
+
prepare_span(trace_key, kwargs, span) if @has_prepare_span
|
146
|
+
|
147
|
+
callable.call
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def multiplex_resource(multiplex)
|
152
|
+
return nil unless multiplex
|
153
|
+
|
154
|
+
operations = multiplex.queries.map(&:selected_operation_name).compact.join(', ')
|
155
|
+
if operations.empty?
|
156
|
+
first_query = multiplex.queries.first
|
157
|
+
fallback_transaction_name(first_query && first_query.context)
|
158
|
+
else
|
159
|
+
operations
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datadog
|
4
|
+
module Tracing
|
5
|
+
module Contrib
|
6
|
+
module GraphQL
|
7
|
+
# Provides instrumentation for `graphql` through the GraphQL's tracing with methods defined in UnifiedTrace
|
8
|
+
module UnifiedTracePatcher
|
9
|
+
module_function
|
10
|
+
|
11
|
+
def patch!(schemas, options)
|
12
|
+
require_relative 'unified_trace'
|
13
|
+
if schemas.empty?
|
14
|
+
::GraphQL::Schema.trace_with(UnifiedTrace, **options)
|
15
|
+
else
|
16
|
+
schemas.each do |schema|
|
17
|
+
schema.trace_with(UnifiedTrace, **options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -29,7 +29,7 @@ module Datadog
|
|
29
29
|
Datadog.configuration.tracing[:kafka]
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def on_start(span, _event, _id, payload)
|
33
33
|
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
|
34
34
|
span.set_tag(Contrib::Ext::Messaging::TAG_SYSTEM, Ext::TAG_MESSAGING_SYSTEM)
|
35
35
|
|
@@ -15,7 +15,9 @@ module Datadog
|
|
15
15
|
|
16
16
|
EVENT_NAME = 'request.connection.kafka'
|
17
17
|
|
18
|
-
|
18
|
+
module_function
|
19
|
+
|
20
|
+
def on_start(span, _event, _id, payload)
|
19
21
|
super
|
20
22
|
|
21
23
|
span.resource = payload[:api]
|
@@ -24,8 +26,6 @@ module Datadog
|
|
24
26
|
span.set_tag(Ext::TAG_RESPONSE_SIZE, payload[:response_size]) if payload.key?(:response_size)
|
25
27
|
end
|
26
28
|
|
27
|
-
module_function
|
28
|
-
|
29
29
|
def span_name
|
30
30
|
Ext::SPAN_CONNECTION_REQUEST
|
31
31
|
end
|
@@ -17,7 +17,9 @@ module Datadog
|
|
17
17
|
|
18
18
|
EVENT_NAME = 'process_batch.consumer.kafka'
|
19
19
|
|
20
|
-
|
20
|
+
module_function
|
21
|
+
|
22
|
+
def on_start(span, _event, _id, payload)
|
21
23
|
super
|
22
24
|
|
23
25
|
span.resource = payload[:topic]
|
@@ -31,8 +33,6 @@ module Datadog
|
|
31
33
|
span.set_tag(Ext::TAG_OFFSET_LAG, payload[:offset_lag]) if payload.key?(:offset_lag)
|
32
34
|
end
|
33
35
|
|
34
|
-
module_function
|
35
|
-
|
36
36
|
def span_name
|
37
37
|
Ext::SPAN_PROCESS_BATCH
|
38
38
|
end
|
@@ -17,7 +17,9 @@ module Datadog
|
|
17
17
|
|
18
18
|
EVENT_NAME = 'process_message.consumer.kafka'
|
19
19
|
|
20
|
-
|
20
|
+
module_function
|
21
|
+
|
22
|
+
def on_start(span, _event, _id, payload)
|
21
23
|
super
|
22
24
|
|
23
25
|
span.resource = payload[:topic]
|
@@ -29,8 +31,6 @@ module Datadog
|
|
29
31
|
span.set_tag(Ext::TAG_OFFSET_LAG, payload[:offset_lag]) if payload.key?(:offset_lag)
|
30
32
|
end
|
31
33
|
|
32
|
-
module_function
|
33
|
-
|
34
34
|
def span_name
|
35
35
|
Ext::SPAN_PROCESS_MESSAGE
|
36
36
|
end
|
@@ -19,7 +19,9 @@ module Datadog
|
|
19
19
|
|
20
20
|
EVENT_NAME = 'heartbeat.consumer.kafka'
|
21
21
|
|
22
|
-
|
22
|
+
module_function
|
23
|
+
|
24
|
+
def on_start(span, _event, _id, payload)
|
23
25
|
super
|
24
26
|
|
25
27
|
if payload.key?(:topic_partitions)
|
@@ -29,8 +31,6 @@ module Datadog
|
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
|
-
module_function
|
33
|
-
|
34
34
|
def span_name
|
35
35
|
Ext::SPAN_CONSUMER_HEARTBEAT
|
36
36
|
end
|
@@ -15,7 +15,9 @@ module Datadog
|
|
15
15
|
|
16
16
|
EVENT_NAME = 'send_messages.producer.kafka'
|
17
17
|
|
18
|
-
|
18
|
+
module_function
|
19
|
+
|
20
|
+
def on_start(span, _event, _id, payload)
|
19
21
|
super
|
20
22
|
|
21
23
|
span.set_tag(Ext::TAG_MESSAGE_COUNT, payload[:message_count]) if payload.key?(:message_count)
|
@@ -23,8 +25,6 @@ module Datadog
|
|
23
25
|
span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_PRODUCER)
|
24
26
|
end
|
25
27
|
|
26
|
-
module_function
|
27
|
-
|
28
28
|
def span_name
|
29
29
|
Ext::SPAN_SEND_MESSAGES
|
30
30
|
end
|
@@ -15,7 +15,9 @@ module Datadog
|
|
15
15
|
|
16
16
|
EVENT_NAME = 'deliver_messages.producer.kafka'
|
17
17
|
|
18
|
-
|
18
|
+
module_function
|
19
|
+
|
20
|
+
def on_start(span, _event, _id, payload)
|
19
21
|
super
|
20
22
|
|
21
23
|
span.set_tag(Ext::TAG_ATTEMPTS, payload[:attempts]) if payload.key?(:attempts)
|
@@ -26,8 +28,6 @@ module Datadog
|
|
26
28
|
span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_PRODUCER)
|
27
29
|
end
|
28
30
|
|
29
|
-
module_function
|
30
|
-
|
31
31
|
def span_name
|
32
32
|
Ext::SPAN_DELIVER_MESSAGES
|
33
33
|
end
|
@@ -19,7 +19,7 @@ module Datadog
|
|
19
19
|
# Class methods for Racecar events.
|
20
20
|
# Note, they share the same process method and before_trace method.
|
21
21
|
module ClassMethods
|
22
|
-
def subscription(*args)
|
22
|
+
def subscription(*args, **kwargs)
|
23
23
|
super.tap do |subscription|
|
24
24
|
subscription.before_trace { ensure_clean_context! }
|
25
25
|
end
|
@@ -33,7 +33,7 @@ module Datadog
|
|
33
33
|
Datadog.configuration.tracing[:racecar]
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def on_start(span, event, _id, payload)
|
37
37
|
span.service = configuration[:service_name]
|
38
38
|
span.resource = payload[:consumer_class]
|
39
39
|
|
@@ -14,6 +14,15 @@ module Datadog
|
|
14
14
|
ENV_ANALYTICS_SAMPLE_RATE = 'DD_TRACE_RAILS_ANALYTICS_SAMPLE_RATE'
|
15
15
|
ENV_DISABLE = 'DISABLE_DATADOG_RAILS'
|
16
16
|
|
17
|
+
SPAN_RUNNER_FILE = 'rails.runner.file'
|
18
|
+
SPAN_RUNNER_INLINE = 'rails.runner.inline'
|
19
|
+
SPAN_RUNNER_STDIN = 'rails.runner.stdin'
|
20
|
+
TAG_COMPONENT = 'rails'
|
21
|
+
TAG_OPERATION_FILE = 'runner.file'
|
22
|
+
TAG_OPERATION_INLINE = 'runner.inline'
|
23
|
+
TAG_OPERATION_STDIN = 'runner.stdin'
|
24
|
+
TAG_RUNNER_SOURCE = 'source'
|
25
|
+
|
17
26
|
# @!visibility private
|
18
27
|
MINIMUM_VERSION = Gem::Version.new('4')
|
19
28
|
end
|
@@ -5,6 +5,7 @@ require_relative '../rack/middlewares'
|
|
5
5
|
require_relative 'framework'
|
6
6
|
require_relative 'log_injection'
|
7
7
|
require_relative 'middlewares'
|
8
|
+
require_relative 'runner'
|
8
9
|
require_relative 'utils'
|
9
10
|
require_relative '../semantic_logger/patcher'
|
10
11
|
|
@@ -28,6 +29,7 @@ module Datadog
|
|
28
29
|
def patch
|
29
30
|
patch_before_initialize
|
30
31
|
patch_after_initialize
|
32
|
+
patch_rails_runner
|
31
33
|
end
|
32
34
|
|
33
35
|
def patch_before_initialize
|
@@ -81,6 +83,11 @@ module Datadog
|
|
81
83
|
def setup_tracer
|
82
84
|
Contrib::Rails::Framework.setup
|
83
85
|
end
|
86
|
+
|
87
|
+
# Instruments the `bin/rails runner` command.
|
88
|
+
def patch_rails_runner
|
89
|
+
::Rails::Command.singleton_class.prepend(Command) if defined?(::Rails::Command)
|
90
|
+
end
|
84
91
|
end
|
85
92
|
end
|
86
93
|
end
|