Class: OpenTelemetry::Instrumentation::Net::LDAP::InstrumentationService

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/net/ldap/instrumentation_service.rb

Overview

instrumentation service for ldap

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ InstrumentationService

Returns a new instance of InstrumentationService.



18
19
20
21
22
23
24
25
# File 'lib/opentelemetry/instrumentation/net/ldap/instrumentation_service.rb', line 18

def initialize(args = {})
  @host = args[:host]
  @port = args[:port]
  @hosts = args[:hosts]
  @auth = args[:auth]
  @base = args[:base]
  @encryption = args[:encryption]
end

Instance Method Details

#instrument(event, payload) ⇒ Object



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
62
63
64
65
66
67
# File 'lib/opentelemetry/instrumentation/net/ldap/instrumentation_service.rb', line 27

def instrument(event, payload)
  operation_type, span_kind = event.split('.').then { |s| [s.first, s.last == 'net_ldap_connection' ? :internal : :client] }

  attributes = {
    'ldap.auth.method' => auth[:method].to_s,
    'ldap.auth.username' => auth[:username].to_s,
    'ldap.operation.type' => operation_type,
    'ldap.request.message' => begin
      payload.to_json
    rescue JSON::GeneratorError
      nil
    end,
    'ldap.tree.base' => base,
    OpenTelemetry::SemConv::SERVER::SERVER_ADDRESS => host || hosts,
    OpenTelemetry::SemConv::SERVER::SERVER_PORT => port,
    OpenTelemetry::SemConv::Incubating::PEER::PEER_SERVICE => instrumentation_config[:peer_service],
    OpenTelemetry::SemConv::NETWORK::NETWORK_TRANSPORT => 'tcp',
    OpenTelemetry::SemConv::NETWORK::NETWORK_PROTOCOL_NAME => 'ldap',
    OpenTelemetry::SemConv::NETWORK::NETWORK_PROTOCOL_VERSION => ::Net::LDAP::Connection::LdapVersion
  }

  attributes.compact!

  tracer.in_span(
    "LDAP #{operation_type}",
    attributes: AttributeMapper.map(attributes),
    kind: span_kind
  ) do |span|
    if instrumentation_config[:enable_internal_instrumentation] == false
      OpenTelemetry::Common::Utilities.untraced do
        yield(payload).tap do |response|
          annotate_span_with_response(span, response) if response
        end
      end
    else
      yield(payload).tap do |response|
        annotate_span_with_response(span, response) if response
      end
    end
  end
end