datadog 2.1.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +101 -1
- data/ext/datadog_profiling_loader/extconf.rb +15 -15
- data/ext/datadog_profiling_native_extension/clock_id.h +1 -0
- data/ext/datadog_profiling_native_extension/clock_id_from_pthread.c +1 -2
- data/ext/datadog_profiling_native_extension/clock_id_noop.c +1 -2
- data/ext/datadog_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +132 -44
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.c +49 -26
- data/ext/datadog_profiling_native_extension/collectors_discrete_dynamic_sampler.h +34 -4
- data/ext/datadog_profiling_native_extension/collectors_idle_sampling_helper.c +4 -0
- data/ext/datadog_profiling_native_extension/collectors_stack.c +90 -37
- data/ext/datadog_profiling_native_extension/collectors_stack.h +2 -2
- data/ext/datadog_profiling_native_extension/collectors_thread_context.c +81 -19
- data/ext/datadog_profiling_native_extension/collectors_thread_context.h +1 -0
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.c +110 -0
- data/ext/datadog_profiling_native_extension/datadog_ruby_common.h +57 -0
- data/ext/datadog_profiling_native_extension/extconf.rb +69 -62
- data/ext/datadog_profiling_native_extension/heap_recorder.c +34 -6
- data/ext/datadog_profiling_native_extension/heap_recorder.h +3 -1
- data/ext/datadog_profiling_native_extension/helpers.h +6 -17
- data/ext/datadog_profiling_native_extension/http_transport.c +3 -3
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.c +0 -86
- data/ext/datadog_profiling_native_extension/libdatadog_helpers.h +2 -23
- data/ext/datadog_profiling_native_extension/native_extension_helpers.rb +61 -126
- data/ext/datadog_profiling_native_extension/private_vm_api_access.c +64 -138
- data/ext/datadog_profiling_native_extension/private_vm_api_access.h +17 -11
- data/ext/datadog_profiling_native_extension/profiling.c +0 -2
- data/ext/datadog_profiling_native_extension/ruby_helpers.c +0 -33
- data/ext/datadog_profiling_native_extension/ruby_helpers.h +1 -26
- data/ext/datadog_profiling_native_extension/setup_signal_handler.c +1 -1
- data/ext/datadog_profiling_native_extension/setup_signal_handler.h +1 -0
- data/ext/datadog_profiling_native_extension/stack_recorder.c +27 -8
- data/ext/datadog_profiling_native_extension/stack_recorder.h +2 -0
- data/ext/datadog_profiling_native_extension/time_helpers.c +0 -15
- data/ext/datadog_profiling_native_extension/time_helpers.h +36 -6
- data/ext/{datadog_profiling_native_extension → libdatadog_api}/crashtracker.c +20 -7
- data/ext/libdatadog_api/datadog_ruby_common.c +110 -0
- data/ext/libdatadog_api/datadog_ruby_common.h +57 -0
- data/ext/libdatadog_api/extconf.rb +108 -0
- data/ext/libdatadog_api/macos_development.md +26 -0
- data/ext/libdatadog_extconf_helpers.rb +130 -0
- data/lib/datadog/appsec/contrib/graphql/appsec_trace.rb +49 -0
- data/lib/datadog/appsec/contrib/graphql/gateway/multiplex.rb +73 -0
- data/lib/datadog/appsec/contrib/graphql/gateway/watcher.rb +68 -0
- data/lib/datadog/appsec/contrib/graphql/integration.rb +41 -0
- data/lib/datadog/appsec/contrib/graphql/patcher.rb +37 -0
- data/lib/datadog/appsec/contrib/graphql/reactive/multiplex.rb +59 -0
- data/lib/datadog/appsec/contrib/rack/gateway/request.rb +1 -1
- data/lib/datadog/appsec/contrib/sinatra/patcher.rb +1 -1
- data/lib/datadog/appsec/extensions.rb +1 -0
- data/lib/datadog/appsec/processor/actions.rb +1 -1
- data/lib/datadog/appsec/response.rb +15 -1
- data/lib/datadog/appsec.rb +1 -0
- data/lib/datadog/core/configuration/components.rb +17 -12
- data/lib/datadog/core/configuration/settings.rb +93 -7
- data/lib/datadog/core/configuration.rb +3 -17
- data/lib/datadog/core/crashtracking/agent_base_url.rb +21 -0
- data/lib/datadog/core/crashtracking/component.rb +111 -0
- data/lib/datadog/core/crashtracking/tag_builder.rb +39 -0
- data/lib/datadog/core/deprecations.rb +58 -0
- data/lib/datadog/core/diagnostics/environment_logger.rb +8 -11
- data/lib/datadog/core/environment/yjit.rb +5 -0
- data/lib/datadog/core/runtime/ext.rb +1 -0
- data/lib/datadog/core/runtime/metrics.rb +6 -0
- data/lib/datadog/core/telemetry/component.rb +154 -0
- data/lib/datadog/core/telemetry/emitter.rb +9 -11
- data/lib/datadog/core/telemetry/event.rb +132 -26
- data/lib/datadog/core/telemetry/ext.rb +3 -0
- data/lib/datadog/core/telemetry/http/adapters/net.rb +11 -13
- data/lib/datadog/core/telemetry/http/ext.rb +3 -0
- data/lib/datadog/core/telemetry/http/transport.rb +38 -9
- data/lib/datadog/core/telemetry/logging.rb +35 -0
- 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/at_fork_monkey_patch.rb +102 -0
- data/lib/datadog/core/utils/only_once_successful.rb +76 -0
- data/lib/datadog/core.rb +2 -19
- data/lib/datadog/kit/appsec/events.rb +2 -4
- data/lib/datadog/opentelemetry/sdk/propagator.rb +5 -10
- data/lib/datadog/opentelemetry/sdk/span_processor.rb +15 -2
- data/lib/datadog/opentelemetry/sdk/trace/span.rb +23 -0
- data/lib/datadog/profiling/collectors/code_provenance.rb +24 -11
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +17 -17
- data/lib/datadog/profiling/collectors/idle_sampling_helper.rb +11 -13
- data/lib/datadog/profiling/collectors/info.rb +3 -3
- data/lib/datadog/profiling/collectors/thread_context.rb +4 -2
- data/lib/datadog/profiling/component.rb +85 -90
- data/lib/datadog/profiling/exporter.rb +3 -3
- data/lib/datadog/profiling/ext/dir_monkey_patches.rb +410 -0
- data/lib/datadog/profiling/ext.rb +21 -21
- data/lib/datadog/profiling/flush.rb +1 -1
- data/lib/datadog/profiling/http_transport.rb +8 -6
- data/lib/datadog/profiling/load_native_extension.rb +5 -5
- data/lib/datadog/profiling/preload.rb +1 -1
- data/lib/datadog/profiling/profiler.rb +5 -8
- data/lib/datadog/profiling/scheduler.rb +31 -25
- data/lib/datadog/profiling/tag_builder.rb +2 -2
- data/lib/datadog/profiling/tasks/exec.rb +5 -5
- data/lib/datadog/profiling/tasks/setup.rb +16 -35
- data/lib/datadog/profiling.rb +5 -5
- 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 +2 -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/ext.rb +14 -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 +28 -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/lograge/patcher.rb +16 -0
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +5 -0
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +17 -13
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +5 -0
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +4 -1
- data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +28 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +5 -1
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +22 -10
- 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/contrib/trilogy/configuration/settings.rb +5 -0
- data/lib/datadog/tracing/contrib/trilogy/instrumentation.rb +4 -1
- data/lib/datadog/tracing/diagnostics/environment_logger.rb +14 -16
- 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 +9 -2
- data/lib/datadog/tracing/distributed/trace_context.rb +3 -2
- data/lib/datadog/tracing/metadata/errors.rb +9 -1
- data/lib/datadog/tracing/metadata/ext.rb +4 -0
- data/lib/datadog/tracing/pipeline/span_filter.rb +2 -2
- data/lib/datadog/tracing/span.rb +9 -2
- data/lib/datadog/tracing/span_event.rb +41 -0
- data/lib/datadog/tracing/span_operation.rb +9 -4
- 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/transport/serializable_trace.rb +3 -0
- data/lib/datadog/tracing.rb +5 -1
- data/lib/datadog/version.rb +2 -2
- metadata +43 -12
- data/lib/datadog/core/telemetry/client.rb +0 -95
- data/lib/datadog/core/telemetry/heartbeat.rb +0 -33
- data/lib/datadog/profiling/crashtracker.rb +0 -91
- data/lib/datadog/profiling/ext/forking.rb +0 -98
@@ -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'
|
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,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if Gem.loaded_specs['graphql'] && Gem.loaded_specs['graphql'].version >= Gem::Version.new('2.0.19')
|
4
|
+
require_relative 'unified_trace'
|
5
|
+
end
|
6
|
+
|
7
|
+
module Datadog
|
8
|
+
module Tracing
|
9
|
+
module Contrib
|
10
|
+
module GraphQL
|
11
|
+
# Provides instrumentation for `graphql` through the GraphQL's tracing with methods defined in UnifiedTrace
|
12
|
+
module UnifiedTracePatcher
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def patch!(schemas, options)
|
16
|
+
if schemas.empty?
|
17
|
+
::GraphQL::Schema.trace_with(UnifiedTrace, **options)
|
18
|
+
else
|
19
|
+
schemas.each do |schema|
|
20
|
+
schema.trace_with(UnifiedTrace, **options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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
|
@@ -20,6 +20,22 @@ module Datadog
|
|
20
20
|
|
21
21
|
# patch applies our patch
|
22
22
|
def patch
|
23
|
+
# ActiveSupport::TaggedLogging is the default Rails logger since Rails 5
|
24
|
+
if defined?(::ActiveSupport::TaggedLogging::Formatter) &&
|
25
|
+
::Lograge::LogSubscribers::ActionController
|
26
|
+
.logger&.formatter.is_a?(::ActiveSupport::TaggedLogging::Formatter)
|
27
|
+
|
28
|
+
Datadog.logger.error(
|
29
|
+
'Lograge and ActiveSupport::TaggedLogging (the default Rails log formatter) are not compatible: ' \
|
30
|
+
'Lograge does not account for Rails log tags, creating polluted logs and breaking log formatting. ' \
|
31
|
+
'Traces and Logs correlation may not work. ' \
|
32
|
+
'Either: 1. Disable tagged logging in your Rails configuration ' \
|
33
|
+
'`config.logger = ActiveSupport::Logger.new(STDOUT); ' \
|
34
|
+
'config.active_job.logger = ActiveSupport::Logger.new(STDOUT)` ' \
|
35
|
+
'or 2. Use the `semantic_logger` gem instead of `lograge`.'
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
23
39
|
::Lograge::LogSubscribers::Base.include(Instrumentation)
|
24
40
|
end
|
25
41
|
end
|
@@ -48,6 +48,11 @@ module Datadog
|
|
48
48
|
o.default Contrib::Propagation::SqlComment::Ext::DISABLED
|
49
49
|
end
|
50
50
|
|
51
|
+
option :append_comment do |o|
|
52
|
+
o.type :bool
|
53
|
+
o.default false
|
54
|
+
end
|
55
|
+
|
51
56
|
option :peer_service do |o|
|
52
57
|
o.type :string, nilable: true
|
53
58
|
o.env Ext::ENV_PEER_SERVICE
|
@@ -50,21 +50,14 @@ module Datadog
|
|
50
50
|
# Set analytics sample rate
|
51
51
|
Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?
|
52
52
|
|
53
|
+
span.set_tag(Contrib::Ext::DB::TAG_INSTANCE, query_options[:database])
|
53
54
|
span.set_tag(Ext::TAG_DB_NAME, query_options[:database])
|
54
55
|
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, query_options[:host])
|
55
56
|
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, query_options[:port])
|
56
57
|
|
57
58
|
Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
Contrib::Propagation::SqlComment.annotate!(span, propagation_mode)
|
62
|
-
sql = Contrib::Propagation::SqlComment.prepend_comment(
|
63
|
-
sql,
|
64
|
-
span,
|
65
|
-
trace_op,
|
66
|
-
propagation_mode
|
67
|
-
)
|
60
|
+
sql = inject_propagation(span, sql, trace_op)
|
68
61
|
|
69
62
|
super(sql, options)
|
70
63
|
end
|
@@ -72,6 +65,21 @@ module Datadog
|
|
72
65
|
|
73
66
|
private
|
74
67
|
|
68
|
+
def inject_propagation(span, sql, trace_op)
|
69
|
+
propagation_mode = Contrib::Propagation::SqlComment::Mode.new(
|
70
|
+
datadog_configuration[:comment_propagation],
|
71
|
+
datadog_configuration[:append_comment]
|
72
|
+
)
|
73
|
+
|
74
|
+
Contrib::Propagation::SqlComment.annotate!(span, propagation_mode)
|
75
|
+
Contrib::Propagation::SqlComment.prepend_comment(
|
76
|
+
sql,
|
77
|
+
span,
|
78
|
+
trace_op,
|
79
|
+
propagation_mode
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
75
83
|
def datadog_configuration
|
76
84
|
Datadog.configuration.tracing[:mysql2]
|
77
85
|
end
|
@@ -83,10 +91,6 @@ module Datadog
|
|
83
91
|
def analytics_sample_rate
|
84
92
|
datadog_configuration[:analytics_sample_rate]
|
85
93
|
end
|
86
|
-
|
87
|
-
def comment_propagation
|
88
|
-
datadog_configuration[:comment_propagation]
|
89
|
-
end
|
90
94
|
end
|
91
95
|
end
|
92
96
|
end
|
@@ -52,6 +52,11 @@ module Datadog
|
|
52
52
|
o.default Contrib::Propagation::SqlComment::Ext::DISABLED
|
53
53
|
end
|
54
54
|
|
55
|
+
option :append_comment do |o|
|
56
|
+
o.type :bool
|
57
|
+
o.default false
|
58
|
+
end
|
59
|
+
|
55
60
|
option :peer_service do |o|
|
56
61
|
o.type :string, nilable: true
|
57
62
|
o.env Ext::ENV_PEER_SERVICE
|
@@ -114,7 +114,10 @@ module Datadog
|
|
114
114
|
Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?
|
115
115
|
|
116
116
|
if sql
|
117
|
-
propagation_mode = Contrib::Propagation::SqlComment::Mode.new(
|
117
|
+
propagation_mode = Contrib::Propagation::SqlComment::Mode.new(
|
118
|
+
comment_propagation,
|
119
|
+
datadog_configuration[:append_comment]
|
120
|
+
)
|
118
121
|
Contrib::Propagation::SqlComment.annotate!(span, propagation_mode)
|
119
122
|
propagated_sql_statement = Contrib::Propagation::SqlComment.prepend_comment(
|
120
123
|
sql,
|
@@ -20,10 +20,38 @@ module Datadog
|
|
20
20
|
# The value should be `true` when `full` mode
|
21
21
|
TAG_DBM_TRACE_INJECTED = '_dd.dbm_trace_injected'
|
22
22
|
|
23
|
+
# Database service/sql span service (i.e. the service executing the actual query)
|
24
|
+
#
|
25
|
+
# If fake services are disabled:
|
26
|
+
# This value will be the same as the parent service
|
27
|
+
#
|
28
|
+
# If fake services are enabled:
|
29
|
+
# This value is NOT the same as the parent service
|
30
|
+
#
|
31
|
+
# This should NOT be overridden by peer.service.
|
23
32
|
KEY_DATABASE_SERVICE = 'dddbs'
|
33
|
+
|
34
|
+
# The global service environment (e.g. DD_ENV)
|
24
35
|
KEY_ENVIRONMENT = 'dde'
|
36
|
+
|
37
|
+
# The global service name (e.g. DD_SERVICE)
|
25
38
|
KEY_PARENT_SERVICE = 'ddps'
|
39
|
+
|
40
|
+
# The global service version (e.g. DD_VERSION)
|
26
41
|
KEY_VERSION = 'ddpv'
|
42
|
+
|
43
|
+
# The hostname of the database server, as provided to the database client upon instantiation.
|
44
|
+
# @see Datadog::Tracing::Metadata::Ext::TAG_PEER_HOSTNAME
|
45
|
+
KEY_HOSTNAME = 'ddh'
|
46
|
+
|
47
|
+
# @see Datadog::Tracing::Contrib::Ext::DB::TAG_INSTANCE
|
48
|
+
KEY_DB_NAME = 'dddb'
|
49
|
+
|
50
|
+
# Users can use this attribute to specify the identity of the dependency/database they are connecting to.
|
51
|
+
# We should grab this attribute only if the user is EXPLICITLY specifying it.
|
52
|
+
# @see Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE
|
53
|
+
KEY_PEER_SERVICE = 'ddprs'
|
54
|
+
|
27
55
|
KEY_TRACEPARENT = 'traceparent'
|
28
56
|
end
|
29
57
|
end
|
@@ -8,7 +8,7 @@ module Datadog
|
|
8
8
|
module Propagation
|
9
9
|
# Implements sql comment propagation related contracts.
|
10
10
|
module SqlComment
|
11
|
-
Mode = Struct.new(:mode) do
|
11
|
+
Mode = Struct.new(:mode, :append) do
|
12
12
|
def enabled?
|
13
13
|
service? || full?
|
14
14
|
end
|
@@ -20,6 +20,10 @@ module Datadog
|
|
20
20
|
def full?
|
21
21
|
mode == Ext::FULL
|
22
22
|
end
|
23
|
+
|
24
|
+
def append?
|
25
|
+
append
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -22,16 +22,28 @@ module Datadog
|
|
22
22
|
def self.prepend_comment(sql, span_op, trace_op, mode)
|
23
23
|
return sql unless mode.enabled?
|
24
24
|
|
25
|
+
config = Datadog.configuration
|
26
|
+
|
27
|
+
parent_service = config.service
|
28
|
+
peer_service = span_op.get_tag(Tracing::Metadata::Ext::TAG_PEER_SERVICE)
|
29
|
+
|
25
30
|
tags = {
|
26
|
-
Ext::
|
27
|
-
Ext::
|
28
|
-
Ext::
|
29
|
-
Ext::
|
31
|
+
Ext::KEY_ENVIRONMENT => config.env,
|
32
|
+
Ext::KEY_PARENT_SERVICE => parent_service,
|
33
|
+
Ext::KEY_VERSION => config.version,
|
34
|
+
Ext::KEY_HOSTNAME => span_op.get_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME),
|
35
|
+
Ext::KEY_DB_NAME => span_op.get_tag(Contrib::Ext::DB::TAG_INSTANCE),
|
36
|
+
Ext::KEY_PEER_SERVICE => peer_service,
|
30
37
|
}
|
31
38
|
|
39
|
+
db_service = peer_service || span_op.service
|
40
|
+
if parent_service != db_service # Only set if it's different from parent_service; otherwise it's redundant
|
41
|
+
tags[Ext::KEY_DATABASE_SERVICE] = db_service
|
42
|
+
end
|
43
|
+
|
32
44
|
if mode.full?
|
33
45
|
# When tracing is disabled, trace_operation is a dummy object that does not contain data to build traceparent
|
34
|
-
if
|
46
|
+
if config.tracing.enabled
|
35
47
|
tags[Ext::KEY_TRACEPARENT] =
|
36
48
|
Tracing::Distributed::TraceContext.new(fetcher: nil).send(:build_traceparent, trace_op.to_digest)
|
37
49
|
else
|
@@ -42,11 +54,11 @@ module Datadog
|
|
42
54
|
end
|
43
55
|
end
|
44
56
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
if mode.append?
|
58
|
+
"#{sql} #{Comment.new(tags)}"
|
59
|
+
else
|
60
|
+
"#{Comment.new(tags)} #{sql}"
|
61
|
+
end
|
50
62
|
end
|
51
63
|
end
|
52
64
|
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
|