ddtrace 1.5.1 → 1.6.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 +63 -1
- data/ext/ddtrace_profiling_loader/ddtrace_profiling_loader.c +9 -2
- data/ext/ddtrace_profiling_loader/extconf.rb +17 -0
- data/ext/ddtrace_profiling_native_extension/NativeExtensionDesign.md +38 -2
- data/ext/ddtrace_profiling_native_extension/clock_id.h +1 -0
- data/ext/ddtrace_profiling_native_extension/clock_id_from_pthread.c +1 -0
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.c +517 -42
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time.h +3 -0
- data/ext/ddtrace_profiling_native_extension/collectors_cpu_and_wall_time_worker.c +208 -30
- data/ext/ddtrace_profiling_native_extension/collectors_stack.c +156 -46
- data/ext/ddtrace_profiling_native_extension/collectors_stack.h +11 -2
- data/ext/ddtrace_profiling_native_extension/extconf.rb +11 -1
- data/ext/ddtrace_profiling_native_extension/http_transport.c +83 -64
- data/ext/ddtrace_profiling_native_extension/libdatadog_helpers.h +4 -4
- data/ext/ddtrace_profiling_native_extension/native_extension_helpers.rb +3 -2
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.c +59 -0
- data/ext/ddtrace_profiling_native_extension/private_vm_api_access.h +3 -0
- data/ext/ddtrace_profiling_native_extension/profiling.c +10 -0
- data/ext/ddtrace_profiling_native_extension/ruby_helpers.c +0 -1
- data/ext/ddtrace_profiling_native_extension/ruby_helpers.h +4 -2
- data/ext/ddtrace_profiling_native_extension/stack_recorder.c +45 -29
- data/ext/ddtrace_profiling_native_extension/stack_recorder.h +7 -7
- data/lib/datadog/appsec/contrib/rack/request_middleware.rb +44 -18
- data/lib/datadog/appsec/event.rb +8 -4
- data/lib/datadog/core/configuration/components.rb +20 -14
- data/lib/datadog/core/configuration/settings.rb +59 -7
- data/lib/datadog/core/diagnostics/environment_logger.rb +5 -1
- data/lib/datadog/core/utils/compression.rb +5 -1
- data/lib/datadog/core.rb +0 -54
- data/lib/datadog/profiling/collectors/cpu_and_wall_time.rb +12 -2
- data/lib/datadog/profiling/collectors/cpu_and_wall_time_worker.rb +5 -3
- data/lib/datadog/profiling/exporter.rb +2 -4
- data/lib/datadog/profiling/http_transport.rb +1 -1
- data/lib/datadog/tracing/client_ip.rb +11 -0
- data/lib/datadog/tracing/configuration/ext.rb +3 -1
- data/lib/datadog/tracing/contrib/aws/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/dalli/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/dalli/instrumentation.rb +4 -0
- data/lib/datadog/tracing/contrib/elasticsearch/ext.rb +2 -0
- data/lib/datadog/tracing/contrib/elasticsearch/patcher.rb +3 -0
- data/lib/datadog/tracing/contrib/ethon/easy_patch.rb +2 -0
- data/lib/datadog/tracing/contrib/ethon/multi_patch.rb +2 -0
- data/lib/datadog/tracing/contrib/excon/middleware.rb +2 -0
- data/lib/datadog/tracing/contrib/ext.rb +6 -0
- data/lib/datadog/tracing/contrib/faraday/middleware.rb +2 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/client.rb +5 -0
- data/lib/datadog/tracing/contrib/grpc/datadog_interceptor/server.rb +7 -1
- data/lib/datadog/tracing/contrib/grpc/ext.rb +2 -0
- data/lib/datadog/tracing/contrib/hanami/action_tracer.rb +47 -0
- data/lib/datadog/tracing/contrib/hanami/configuration/settings.rb +22 -0
- data/lib/datadog/tracing/contrib/hanami/ext.rb +24 -0
- data/lib/datadog/tracing/contrib/hanami/integration.rb +44 -0
- data/lib/datadog/tracing/contrib/hanami/patcher.rb +33 -0
- data/lib/datadog/tracing/contrib/hanami/plugin.rb +23 -0
- data/lib/datadog/tracing/contrib/hanami/renderer_policy_tracing.rb +41 -0
- data/lib/datadog/tracing/contrib/hanami/router_tracing.rb +44 -0
- data/lib/datadog/tracing/contrib/http/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/httpclient/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/httprb/instrumentation.rb +2 -0
- data/lib/datadog/tracing/contrib/mongodb/ext.rb +7 -0
- data/lib/datadog/tracing/contrib/mongodb/subscribers.rb +4 -0
- data/lib/datadog/tracing/contrib/mysql2/configuration/settings.rb +12 -0
- data/lib/datadog/tracing/contrib/mysql2/ext.rb +1 -0
- data/lib/datadog/tracing/contrib/mysql2/instrumentation.rb +16 -0
- data/lib/datadog/tracing/contrib/pg/configuration/settings.rb +12 -0
- data/lib/datadog/tracing/contrib/pg/ext.rb +2 -1
- data/lib/datadog/tracing/contrib/pg/instrumentation.rb +34 -18
- data/lib/datadog/tracing/contrib/propagation/sql_comment/comment.rb +43 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/ext.rb +32 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment/mode.rb +28 -0
- data/lib/datadog/tracing/contrib/propagation/sql_comment.rb +49 -0
- data/lib/datadog/tracing/contrib/rack/middlewares.rb +15 -7
- data/lib/datadog/tracing/contrib/redis/ext.rb +2 -0
- data/lib/datadog/tracing/contrib/redis/instrumentation.rb +4 -2
- data/lib/datadog/tracing/contrib/redis/patcher.rb +41 -0
- data/lib/datadog/tracing/contrib/redis/tags.rb +5 -0
- data/lib/datadog/tracing/contrib/rest_client/request_patch.rb +2 -0
- data/lib/datadog/tracing/contrib/sinatra/env.rb +12 -23
- data/lib/datadog/tracing/contrib/sinatra/ext.rb +7 -3
- data/lib/datadog/tracing/contrib/sinatra/patcher.rb +2 -2
- data/lib/datadog/tracing/contrib/sinatra/tracer.rb +8 -80
- data/lib/datadog/tracing/contrib/sinatra/tracer_middleware.rb +14 -9
- data/lib/datadog/tracing/contrib.rb +1 -0
- data/lib/datadog/tracing/distributed/datadog_tags_codec.rb +84 -0
- data/lib/datadog/tracing/distributed/headers/datadog.rb +122 -30
- data/lib/datadog/tracing/distributed/headers/ext.rb +2 -0
- data/lib/datadog/tracing/flush.rb +1 -1
- data/lib/datadog/tracing/metadata/ext.rb +8 -0
- data/lib/datadog/tracing/propagation/http.rb +9 -1
- data/lib/datadog/tracing/sampling/ext.rb +31 -0
- data/lib/datadog/tracing/sampling/priority_sampler.rb +46 -4
- data/lib/datadog/tracing/sampling/rate_by_key_sampler.rb +8 -9
- data/lib/datadog/tracing/sampling/rate_by_service_sampler.rb +29 -5
- data/lib/datadog/tracing/sampling/rate_sampler.rb +10 -3
- data/lib/datadog/tracing/sampling/rule_sampler.rb +4 -3
- data/lib/datadog/tracing/sampling/span/ext.rb +0 -4
- data/lib/datadog/tracing/sampling/span/rule.rb +1 -1
- data/lib/datadog/tracing/sampling/span/sampler.rb +14 -3
- data/lib/datadog/tracing/trace_digest.rb +3 -0
- data/lib/datadog/tracing/trace_operation.rb +10 -0
- data/lib/datadog/tracing/trace_segment.rb +6 -0
- data/lib/datadog/tracing/tracer.rb +3 -1
- data/lib/datadog/tracing/writer.rb +7 -0
- data/lib/ddtrace/transport/trace_formatter.rb +7 -0
- data/lib/ddtrace/transport/traces.rb +1 -1
- data/lib/ddtrace/version.rb +2 -2
- metadata +18 -14
- data/lib/datadog/profiling/old_ext.rb +0 -42
- data/lib/datadog/profiling/transport/http/api/endpoint.rb +0 -85
- data/lib/datadog/profiling/transport/http/api/instance.rb +0 -38
- data/lib/datadog/profiling/transport/http/api/spec.rb +0 -42
- data/lib/datadog/profiling/transport/http/api.rb +0 -45
- data/lib/datadog/profiling/transport/http/builder.rb +0 -30
- data/lib/datadog/profiling/transport/http/client.rb +0 -37
- data/lib/datadog/profiling/transport/http/response.rb +0 -21
- data/lib/datadog/profiling/transport/http.rb +0 -118
data/lib/datadog/core.rb
CHANGED
@@ -1,59 +1,5 @@
|
|
1
1
|
# typed: strict
|
2
2
|
|
3
|
-
# TODO: Move these requires to smaller modules.
|
4
|
-
# Would be better to lazy load these; not
|
5
|
-
# all of these components will be used in
|
6
|
-
# every application.
|
7
|
-
# require_relative 'core/buffer/cruby'
|
8
|
-
# require_relative 'core/buffer/random'
|
9
|
-
# require_relative 'core/buffer/thread_safe'
|
10
|
-
# require_relative 'core/chunker'
|
11
|
-
# require_relative 'core/configuration'
|
12
|
-
# require_relative 'core/diagnostics/environment_logger'
|
13
|
-
# require_relative 'core/diagnostics/ext'
|
14
|
-
# require_relative 'core/diagnostics/health'
|
15
|
-
# require_relative 'core/encoding'
|
16
|
-
# require_relative 'core/environment/cgroup'
|
17
|
-
# require_relative 'core/environment/class_count'
|
18
|
-
# require_relative 'core/environment/container'
|
19
|
-
# require_relative 'core/environment/ext'
|
20
|
-
# require_relative 'core/environment/gc'
|
21
|
-
# require_relative 'core/environment/identity'
|
22
|
-
# require_relative 'core/environment/socket'
|
23
|
-
# require_relative 'core/environment/thread_count'
|
24
|
-
# require_relative 'core/environment/variable_helpers'
|
25
|
-
# require_relative 'core/environment/vm_cache'
|
26
|
-
# require_relative 'core/error'
|
27
|
-
# require_relative 'core/event'
|
28
|
-
# require_relative 'core/git/ext'
|
29
|
-
# require_relative 'core/logger'
|
30
|
-
# require_relative 'core/metrics/client'
|
31
|
-
# require_relative 'core/metrics/ext'
|
32
|
-
# require_relative 'core/metrics/helpers'
|
33
|
-
# require_relative 'core/metrics/logging'
|
34
|
-
# require_relative 'core/metrics/metric'
|
35
|
-
# require_relative 'core/metrics/options'
|
36
|
-
# require_relative 'core/pin'
|
37
|
-
# require_relative 'core/quantization/hash'
|
38
|
-
# require_relative 'core/quantization/http'
|
39
|
-
# require_relative 'core/runtime/ext'
|
40
|
-
# require_relative 'core/runtime/metrics'
|
41
|
-
# require_relative 'core/utils'
|
42
|
-
# require_relative 'core/utils/compression'
|
43
|
-
# require_relative 'core/utils/database'
|
44
|
-
# require_relative 'core/utils/forking'
|
45
|
-
# require_relative 'core/utils/object_set'
|
46
|
-
# require_relative 'core/utils/only_once'
|
47
|
-
# require_relative 'core/utils/sequence'
|
48
|
-
# require_relative 'core/utils/string_table'
|
49
|
-
# require_relative 'core/utils/time'
|
50
|
-
# require_relative 'core/worker'
|
51
|
-
# require_relative 'core/workers/async'
|
52
|
-
# require_relative 'core/workers/interval_loop'
|
53
|
-
# require_relative 'core/workers/polling'
|
54
|
-
# require_relative 'core/workers/queue'
|
55
|
-
# require_relative 'core/workers/runtime_metrics'
|
56
|
-
|
57
3
|
require_relative 'core/extensions'
|
58
4
|
|
59
5
|
# We must load core extensions to make certain global APIs
|
@@ -11,8 +11,9 @@ module Datadog
|
|
11
11
|
#
|
12
12
|
# Methods prefixed with _native_ are implemented in `collectors_cpu_and_wall_time.c`
|
13
13
|
class CpuAndWallTime
|
14
|
-
def initialize(recorder:, max_frames:)
|
15
|
-
|
14
|
+
def initialize(recorder:, max_frames:, tracer:)
|
15
|
+
tracer_context_key = safely_extract_context_key_from(tracer)
|
16
|
+
self.class._native_initialize(self, recorder, max_frames, tracer_context_key)
|
16
17
|
end
|
17
18
|
|
18
19
|
def inspect
|
@@ -21,6 +22,15 @@ module Datadog
|
|
21
22
|
result[-1] = "#{self.class._native_inspect(self)}>"
|
22
23
|
result
|
23
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def safely_extract_context_key_from(tracer)
|
29
|
+
tracer &&
|
30
|
+
tracer.respond_to?(:provider) &&
|
31
|
+
# NOTE: instance_variable_get always works, even on nil -- it just returns nil if the variable doesn't exist
|
32
|
+
tracer.provider.instance_variable_get(:@context).instance_variable_get(:@key)
|
33
|
+
end
|
24
34
|
end
|
25
35
|
end
|
26
36
|
end
|
@@ -18,9 +18,11 @@ module Datadog
|
|
18
18
|
def initialize(
|
19
19
|
recorder:,
|
20
20
|
max_frames:,
|
21
|
-
|
21
|
+
tracer:,
|
22
|
+
gc_profiling_enabled:,
|
23
|
+
cpu_and_wall_time_collector: CpuAndWallTime.new(recorder: recorder, max_frames: max_frames, tracer: tracer)
|
22
24
|
)
|
23
|
-
self.class._native_initialize(self, cpu_and_wall_time_collector)
|
25
|
+
self.class._native_initialize(self, cpu_and_wall_time_collector, gc_profiling_enabled)
|
24
26
|
@worker_thread = nil
|
25
27
|
@failure_exception = nil
|
26
28
|
@start_stop_mutex = Mutex.new
|
@@ -28,7 +30,7 @@ module Datadog
|
|
28
30
|
|
29
31
|
def start
|
30
32
|
@start_stop_mutex.synchronize do
|
31
|
-
return if @worker_thread
|
33
|
+
return if @worker_thread && @worker_thread.alive?
|
32
34
|
|
33
35
|
Datadog.logger.debug { "Starting thread for: #{self}" }
|
34
36
|
@worker_thread = Thread.new do
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# typed: true
|
2
2
|
|
3
3
|
require_relative 'ext'
|
4
|
-
require_relative '../core/utils/compression'
|
5
4
|
require_relative 'tag_builder'
|
6
5
|
|
7
6
|
module Datadog
|
@@ -60,10 +59,9 @@ module Datadog
|
|
60
59
|
start: start,
|
61
60
|
finish: finish,
|
62
61
|
pprof_file_name: Datadog::Profiling::Ext::Transport::HTTP::PPROF_DEFAULT_FILENAME,
|
63
|
-
pprof_data:
|
62
|
+
pprof_data: uncompressed_pprof.to_s,
|
64
63
|
code_provenance_file_name: Datadog::Profiling::Ext::Transport::HTTP::CODE_PROVENANCE_FILENAME,
|
65
|
-
code_provenance_data:
|
66
|
-
(Datadog::Core::Utils::Compression.gzip(uncompressed_code_provenance) if uncompressed_code_provenance),
|
64
|
+
code_provenance_data: uncompressed_code_provenance,
|
67
65
|
tags_as_array: Datadog::Profiling::TagBuilder.call(settings: Datadog.configuration).to_a,
|
68
66
|
)
|
69
67
|
end
|
@@ -58,7 +58,7 @@ module Datadog
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
# Used to log soft failures in `
|
61
|
+
# Used to log soft failures in `ddog_Vec_tag_push` (e.g. we still report the profile in these cases)
|
62
62
|
# Called from native code
|
63
63
|
def self.log_failure_to_process_tag(failure_details)
|
64
64
|
Datadog.logger.warn("Failed to add tag to profiling request: #{failure_details}")
|
@@ -39,6 +39,17 @@ module Datadog
|
|
39
39
|
def self.set_client_ip_tag(span, headers: nil, remote_ip: nil)
|
40
40
|
return unless configuration.enabled
|
41
41
|
|
42
|
+
set_client_ip_tag!(span, headers: headers, remote_ip: remote_ip)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Forcefully sets the `http.client_ip` tag on the given span.
|
46
|
+
#
|
47
|
+
# This function ignores the user's `enabled` setting.
|
48
|
+
#
|
49
|
+
# @param [Span] span The span that's associated with the request.
|
50
|
+
# @param [HeaderCollection, #get, nil] headers A collection with the request headers.
|
51
|
+
# @param [String, nil] remote_ip The remote IP the request associated with the span is sent to.
|
52
|
+
def self.set_client_ip_tag!(span, headers: nil, remote_ip: nil)
|
42
53
|
result = raw_ip_from_request(headers, remote_ip)
|
43
54
|
|
44
55
|
if result.raw_ip
|
@@ -21,6 +21,7 @@ module Datadog
|
|
21
21
|
PROPAGATION_STYLE_B3_SINGLE_HEADER = 'B3 single header'.freeze
|
22
22
|
ENV_PROPAGATION_STYLE_INJECT = 'DD_PROPAGATION_STYLE_INJECT'.freeze
|
23
23
|
ENV_PROPAGATION_STYLE_EXTRACT = 'DD_PROPAGATION_STYLE_EXTRACT'.freeze
|
24
|
+
ENV_X_DATADOG_TAGS_MAX_LENGTH = 'DD_TRACE_X_DATADOG_TAGS_MAX_LENGTH'.freeze
|
24
25
|
end
|
25
26
|
|
26
27
|
# @public_api
|
@@ -54,7 +55,8 @@ module Datadog
|
|
54
55
|
|
55
56
|
# @public_api
|
56
57
|
module ClientIp
|
57
|
-
|
58
|
+
ENV_ENABLED = 'DD_TRACE_CLIENT_IP_ENABLED'.freeze
|
59
|
+
ENV_DISABLED = 'DD_TRACE_CLIENT_IP_HEADER_DISABLED'.freeze # TODO: deprecated, remove later
|
58
60
|
ENV_HEADER_NAME = 'DD_TRACE_CLIENT_IP_HEADER'.freeze
|
59
61
|
end
|
60
62
|
end
|
@@ -33,6 +33,8 @@ module Datadog
|
|
33
33
|
span.name = Ext::SPAN_COMMAND
|
34
34
|
span.resource = context.safely(:resource)
|
35
35
|
|
36
|
+
span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
|
37
|
+
|
36
38
|
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
|
37
39
|
span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_COMMAND)
|
38
40
|
|
@@ -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 'quantize'
|
7
8
|
|
8
9
|
module Datadog
|
@@ -37,6 +38,9 @@ module Datadog
|
|
37
38
|
|
38
39
|
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_HOST, hostname)
|
39
40
|
span.set_tag(Tracing::Metadata::Ext::NET::TAG_TARGET_PORT, port)
|
41
|
+
|
42
|
+
span.set_tag(Contrib::Ext::DB::TAG_SYSTEM, Ext::TAG_SYSTEM)
|
43
|
+
|
40
44
|
cmd = Quantize.format_command(op, args)
|
41
45
|
span.set_tag(Ext::TAG_COMMAND, cmd)
|
42
46
|
|
@@ -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
|
|
@@ -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(
|
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
|
@@ -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
|
|