Skip to content

Commit f39b2de

Browse files
committed
chore: add ldap.operation.type attribute.
1 parent f0338fc commit f39b2de

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

instrumentation/net_ldap/lib/opentelemetry/instrumentation/net/ldap/instrumentation_service.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ def initialize(args = {})
2525
end
2626

2727
def instrument(event, payload)
28+
operation_type, span_kind = event.split('.').then { |s| [s.first, s.last == 'net_ldap_connection' ? :internal : :client] }
29+
2830
attributes = {
2931
'ldap.auth.method' => auth[:method].to_s,
3032
'ldap.auth.username' => auth[:username].to_s,
31-
'ldap.tree.base' => base,
33+
'ldap.operation.type' => operation_type,
3234
'ldap.request.message' => payload.to_json,
35+
'ldap.tree.base' => base,
3336
OpenTelemetry::SemConv::SERVER::SERVER_ADDRESS => host || hosts,
3437
OpenTelemetry::SemConv::SERVER::SERVER_PORT => port,
3538
OpenTelemetry::SemConv::Incubating::PEER::PEER_SERVICE => instrumentation_config[:peer_service],
@@ -39,9 +42,8 @@ def instrument(event, payload)
3942
}
4043
attributes.delete_if { |_key, value| value.nil? }
4144

42-
span_name, span_kind = event.split('.').then { |s| [s.first, s.last == 'net_ldap_connection' ? :internal : :client] }
4345
tracer.in_span(
44-
"LDAP #{span_name}",
46+
"LDAP #{operation_type}",
4547
attributes: AttributeMapper.map(attributes),
4648
kind: span_kind
4749
) do |span|

instrumentation/net_ldap/test/opentelemetry/instrumentation/net/ldap/instrumentation_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def modify(args)
8080
_(span.attributes['ldap.auth.username']).must_equal 'test_user'
8181
_(span.attributes['ldap.auth.method']).must_equal 'simple'
8282
_(span.attributes.values).wont_include 'test_password'
83+
_(span.attributes['ldap.operation.type']).must_equal 'bind'
8384
_(span.attributes['ldap.request.message']).must_equal '{}'
8485
_(span.attributes['ldap.response.status_code']).must_equal 0
8586
_(span.attributes['ldap.tree.base']).must_equal 'dc=com'
@@ -103,6 +104,7 @@ def modify(args)
103104
_(span.attributes['ldap.auth.username']).must_equal 'test_user'
104105
_(span.attributes['ldap.auth.method']).must_equal 'simple'
105106
_(span.attributes.values).wont_include 'test_password'
107+
_(span.attributes['ldap.operation.type']).must_equal 'search'
106108
_(span.attributes['ldap.request.message']).must_equal '{"filter":"(uid=user1)","paged_searches_supported":false,"base":"dc=com"}'
107109
_(span.attributes['ldap.response.status_code']).must_equal 0
108110
_(span.attributes['ldap.tree.base']).must_equal 'dc=com'
@@ -131,6 +133,7 @@ def modify(args)
131133
_(span.attributes['ldap.auth.username']).must_equal 'test_user'
132134
_(span.attributes['ldap.auth.method']).must_equal 'simple'
133135
_(span.attributes.values).wont_include 'test_password'
136+
_(span.attributes['ldap.operation.type']).must_equal 'add'
134137
_(span.attributes['ldap.request.message']).must_equal '{}'
135138
_(span.attributes['ldap.tree.base']).must_equal 'dc=com'
136139
_(span.attributes['network.protocol.name']).must_equal 'ldap'
@@ -156,6 +159,7 @@ def modify(args)
156159
_(span.attributes['ldap.auth.username']).must_equal 'test_user'
157160
_(span.attributes['ldap.auth.method']).must_equal 'simple'
158161
_(span.attributes.values).wont_include 'test_password'
162+
_(span.attributes['ldap.operation.type']).must_equal 'modify'
159163
_(span.attributes['ldap.request.message']).must_equal '{"dn":"CN=test,OU=test,DC=com","operations":[["replace","unicodePwd",["[REDACTED]"]]]}'
160164
_(span.attributes['ldap.response.status_code']).must_equal 0
161165
_(span.attributes['ldap.tree.base']).must_equal 'dc=com'

0 commit comments

Comments
 (0)