33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/datadog/tracing/contrib/opensearch/patcher.rb', line 33
def perform_request(method, path, params = {}, body = nil, = nil)
response = nil
Tracing.trace('opensearch.query', service: datadog_configuration[:service_name]) do |span|
begin
span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_CLIENT)
span.set_tag(Contrib::Ext::DB::TAG_SYSTEM, Ext::TAG_SYSTEM)
span.set_tag(OpenSearch::Ext::TAG_METHOD, method)
span.set_tag(OpenSearch::Ext::TAG_PATH, path)
tag_params(params, span)
tag_body(body, span)
original_url = transport.get_connection.full_url(path, {})
url = URI.parse(original_url)
host = url.host
port = url.port
scheme = url.scheme
url.user = nil
if datadog_configuration[:peer_service]
span.set_tag(
Tracing::Metadata::Ext::TAG_PEER_SERVICE,
datadog_configuration[:peer_service]
)
end
if span.service != Datadog.configuration.service
span.set_tag(Tracing::Contrib::Ext::Metadata::TAG_BASE_SERVICE, Datadog.configuration.service)
end
span.set_tag(OpenSearch::Ext::TAG_URL, url)
span.set_tag(OpenSearch::Ext::TAG_HOST, host)
span.set_tag(OpenSearch::Ext::TAG_PORT, port)
span.set_tag(OpenSearch::Ext::TAG_SCHEME, scheme)
span.set_tag(Tracing::Metadata::Ext::TAG_PEER_HOSTNAME, host) if host
quantized_url = OpenSearch::Quantize.format_url(url)
span.resource = "#{method} #{quantized_url}"
Contrib::SpanAttributeSchema.set_peer_service!(span, Ext::PEER_SERVICE_SOURCES)
rescue StandardError => e
Datadog.logger.error(e.message)
Datadog::Core::Telemetry::Logger.report(e)
ensure
begin
response = super
rescue => e
status_code = ::OpenSearch::Transport::Transport::ERRORS.key(e.class)
span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_STATUS_CODE, status_code) if status_code
raise
end
if response
if response.respond_to?(:status)
span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_STATUS_CODE, response.status)
end
if response.respond_to?(:headers) && (response. || {})['content-length']
span.set_tag(
OpenSearch::Ext::TAG_RESPONSE_CONTENT_LENGTH,
response.['content-length'].to_i
)
end
end
end
end
response
end
|