25
26
27
28
29
30
31
32
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
|
# File 'lib/mysql2/instrumentation.rb', line 25
def patch_query
::Mysql2::Client.class_eval do
alias_method :query_original, :query
def query(sql, options = {})
statement = sql.respond_to?(:to_str) ? sql : sql.to_s
tags = {
'component' => 'mysql2',
'db.instance' => @query_options.fetch(:database, ''),
'db.statement' => statement[0, 1024],
'db.user' => @query_options.fetch(:username, ''),
'db.type' => 'mysql',
'span.kind' => 'client',
}
operation_name = 'sql.query'
begin
candidate = sql.split(' ')[0]
unless candidate == nil or candidate.empty?
operation_name = candidate
end
rescue
end
span = ::Mysql2::Instrumentation.tracer.start_span(operation_name, tags: tags)
query_original(sql, options)
rescue => error
span.set_tag("error", true)
span.log_kv(key: "message", value: error.message)
raise error
ensure
span.finish if span
end
end end
|