From ef4ba0b0e992f5abe01c539edce579a2f684c3b7 Mon Sep 17 00:00:00 2001 From: Hare Ram Rai Date: Thu, 2 Nov 2023 09:49:54 +0100 Subject: [PATCH] fix: Track ldap status from Net::LDAP::PDU response (#5) * 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 --- .../net/ldap/instrumentation_service.rb | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/instrumentation/net_ldap/lib/opentelemetry/instrumentation/net/ldap/instrumentation_service.rb b/instrumentation/net_ldap/lib/opentelemetry/instrumentation/net/ldap/instrumentation_service.rb index a8eb7d4c6..8bf689edd 100644 --- a/instrumentation/net_ldap/lib/opentelemetry/instrumentation/net/ldap/instrumentation_service.rb +++ b/instrumentation/net_ldap/lib/opentelemetry/instrumentation/net/ldap/instrumentation_service.rb @@ -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