forked from open-telemetry/opentelemetry-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.rb
45 lines (39 loc) · 1.21 KB
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
module OpenTelemetry
module Instrumentation
module Dalli
module Patches
# Module to prepend to Dalli::Server for instrumentation
module Server
def request(op, *args)
operation = Utils.opname(op, multi?)
attributes = {
'db.system' => 'memcached',
'net.peer.name' => hostname,
'net.peer.port' => port
}
if config[:db_statement] == :include
attributes['db.statement'] = Utils.format_command(operation, args)
elsif config[:db_statement] == :obfuscate
attributes['db.statement'] = "#{operation} ?"
end
attributes['peer.service'] = config[:peer_service] if config[:peer_service]
tracer.in_span(operation, attributes: attributes, kind: :client) do
super
end
end
private
def tracer
Dalli::Instrumentation.instance.tracer
end
def config
Dalli::Instrumentation.instance.config
end
end
end
end
end
end