Skip to content

Commit 44a1d54

Browse files
committed
chore: update attribute names
1 parent 7264acb commit 44a1d54

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ def instrument(event, payload)
2626
'ldap.auth' => auth.except(:password).to_json,
2727
'ldap.base' => base,
2828
'ldap.encryption' => encryption.to_json,
29-
'ldap.payload' => payload.to_json,
30-
OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => host || hosts,
31-
OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => port,
32-
OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE => instrumentation_config[:peer_service]
29+
'ldap.request.message' => payload.to_json,
30+
OpenTelemetry::SemConv::SERVER::SERVER_ADDRESS => host || hosts,
31+
OpenTelemetry::SemConv::SERVER::SERVER_PORT => port,
32+
OpenTelemetry::SemConv::Incubating::PEER::PEER_SERVICE => instrumentation_config[:peer_service],
33+
OpenTelemetry::SemConv::NETWORK::NETWORK_PROTOCOL_NAME => 'ldap'
3334
}
3435
attributes.delete_if { |_key, value| value.nil? }
3536

@@ -42,7 +43,10 @@ def instrument(event, payload)
4243
annotate_span_with_response(span, response) if response
4344
end
4445
rescue ::Net::LDAP::Error => e
45-
span.set_attribute('ldap.error_message', "#{e.class}: #{e.message}")
46+
span.add_attributes({
47+
'error.type' => e.class.to_s,
48+
'error.message' => e.message.to_s
49+
})
4650
span.status = OpenTelemetry::Trace::Status.error
4751
raise e
4852
end
@@ -71,10 +75,10 @@ def annotate_span_with_response(span, response)
7175
message = ::Net::LDAP.result2string(status_code)
7276
end
7377
attributes = {
74-
'ldap.status_code' => status_code
78+
'ldap.response.status_code' => status_code
7579
}
76-
attributes['ldap.message'] = message unless message.empty?
77-
attributes['ldap.error_message'] = error_message unless error_message.empty?
80+
attributes['ldap.response.message'] = message unless message.empty?
81+
attributes['error.message'] = error_message unless error_message.empty?
7882
span.add_attributes(attributes)
7983

8084
return if ::Net::LDAP::ResultCodesNonError.include?(status_code)

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ def modify(args)
7878
_(span.attributes['ldap.auth']).must_equal '{"method":"anonymous"}'
7979
_(span.attributes['ldap.base']).must_equal 'dc=com'
8080
_(span.attributes['ldap.encryption']).must_equal '{"method":"simple_tls","tls_options":{"foo":"bar"}}'
81-
_(span.attributes['ldap.payload']).must_equal '{}'
82-
_(span.attributes['ldap.status_code']).must_equal 0
83-
_(span.attributes['net.peer.name']).must_equal 'test.mocked.com'
84-
_(span.attributes['net.peer.port']).must_equal 636
81+
_(span.attributes['ldap.request.message']).must_equal '{}'
82+
_(span.attributes['ldap.response.status_code']).must_equal 0
83+
_(span.attributes['network.protocol.name']).must_equal 'ldap'
84+
_(span.attributes['server.address']).must_equal 'test.mocked.com'
85+
_(span.attributes['server.port']).must_equal 636
8586
end
8687
end
8788

@@ -95,10 +96,11 @@ def modify(args)
9596
_(span.attributes['ldap.auth']).must_equal '{"method":"anonymous"}'
9697
_(span.attributes['ldap.base']).must_equal 'dc=com'
9798
_(span.attributes['ldap.encryption']).must_equal '{"method":"simple_tls","tls_options":{"foo":"bar"}}'
98-
_(span.attributes['ldap.payload']).must_equal '{"filter":"(uid=user1)","paged_searches_supported":false,"base":"dc=com"}'
99-
_(span.attributes['ldap.status_code']).must_equal 0
100-
_(span.attributes['net.peer.name']).must_equal 'test.mocked.com'
101-
_(span.attributes['net.peer.port']).must_equal 636
99+
_(span.attributes['ldap.request.message']).must_equal '{"filter":"(uid=user1)","paged_searches_supported":false,"base":"dc=com"}'
100+
_(span.attributes['ldap.response.status_code']).must_equal 0
101+
_(span.attributes['network.protocol.name']).must_equal 'ldap'
102+
_(span.attributes['server.address']).must_equal 'test.mocked.com'
103+
_(span.attributes['server.port']).must_equal 636
102104
end
103105
end
104106

@@ -112,13 +114,15 @@ def modify(args)
112114

113115
_(exporter.finished_spans.size).must_equal 1
114116
_(span.name).must_equal 'add.net_ldap'
117+
_(span.attributes['error.message']).must_equal 'Connection timed out - user specified timeout'
118+
_(span.attributes['error.type']).must_equal 'Net::LDAP::Error'
115119
_(span.attributes['ldap.auth']).must_equal '{"method":"anonymous"}'
116120
_(span.attributes['ldap.base']).must_equal 'dc=com'
117121
_(span.attributes['ldap.encryption']).must_equal '{"method":"simple_tls","tls_options":{"foo":"bar"}}'
118-
_(span.attributes['ldap.payload']).must_equal '{}'
119-
_(span.attributes['ldap.error_message']).must_equal 'Net::LDAP::Error: Connection timed out - user specified timeout'
120-
_(span.attributes['net.peer.name']).must_equal 'test.mocked.com'
121-
_(span.attributes['net.peer.port']).must_equal 636
122+
_(span.attributes['ldap.request.message']).must_equal '{}'
123+
_(span.attributes['network.protocol.name']).must_equal 'ldap'
124+
_(span.attributes['server.address']).must_equal 'test.mocked.com'
125+
_(span.attributes['server.port']).must_equal 636
122126
end
123127
end
124128

@@ -135,10 +139,11 @@ def modify(args)
135139
_(span.attributes['ldap.auth']).must_equal '{"method":"anonymous"}'
136140
_(span.attributes['ldap.base']).must_equal 'dc=com'
137141
_(span.attributes['ldap.encryption']).must_equal '{"method":"simple_tls","tls_options":{"foo":"bar"}}'
138-
_(span.attributes['ldap.payload']).must_equal '{"dn":"CN=test,OU=test,DC=com","operations":[["replace","unicodePwd",["[REDACTED]"]]]}'
139-
_(span.attributes['ldap.status_code']).must_equal 0
140-
_(span.attributes['net.peer.name']).must_equal 'test.mocked.com'
141-
_(span.attributes['net.peer.port']).must_equal 636
142+
_(span.attributes['ldap.request.message']).must_equal '{"dn":"CN=test,OU=test,DC=com","operations":[["replace","unicodePwd",["[REDACTED]"]]]}'
143+
_(span.attributes['ldap.response.status_code']).must_equal 0
144+
_(span.attributes['network.protocol.name']).must_equal 'ldap'
145+
_(span.attributes['server.address']).must_equal 'test.mocked.com'
146+
_(span.attributes['server.port']).must_equal 636
142147
end
143148
end
144149
end

0 commit comments

Comments
 (0)