Skip to content

Commit

Permalink
fix: Track ldap status from Net::LDAP::PDU response (#5)
Browse files Browse the repository at this point in the history
* fix: Track ldap status from Net::LDAP::PDU response

* fix: Add extra attribute for tracking false ldap error

* fix: OpenTelemetry error for NilClass

* fix: Ingore message & error_message if empty
  • Loading branch information
Hareramrai authored Nov 2, 2023
1 parent 46e2ac6 commit ef4ba0b
Showing 1 changed file with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,22 @@ def instrumentation_config
def annotate_span_with_response!(span, response)
return unless response

status_code = nil
message = nil
error_message = nil
successful = true
status_code = ::Net::LDAP::ResultCodeSuccess
message = ''
error_message = ''

result = response.result if response.is_a?(::Net::LDAP::PDU)

if [true, false].include?(response)
successful = response
status_code = ::Net::LDAP::ResultCodeSuccess if successful
elsif result.is_a?(Hash)
status_code = (result[:resultCode] || '').to_i
if response.is_a?(::Net::LDAP::PDU)
status_code ||= response.result_code
error_message = response.error_message.to_s
message = ::Net::LDAP.result2string(status_code)
error_message = result[:errorMessage].to_s
else
status_code = ::Net::LDAP::ResultCodeSuccess
end

span.set_attribute('ldap.status_code', status_code)
span.set_attribute('ldap.message', message) if message
span.set_attribute('ldap.error_message', error_message) unless error_message.to_s.empty?
span.status = OpenTelemetry::Trace::Status.error if !successful || error_message
span.set_attribute('ldap.message', message) unless message.empty?
span.set_attribute('ldap.error_message', error_message) unless error_message.empty?

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

span.status = OpenTelemetry::Trace::Status.error
end
end
end
Expand Down

0 comments on commit ef4ba0b

Please sign in to comment.