Skip to content

Commit 0583992

Browse files
committed
chore: feedback
1 parent e147bbe commit 0583992

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

.toys/.data/releases.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ gems:
142142

143143
- name: opentelemetry-instrumentation-active_model_serializers
144144
directory: instrumentation/active_model_serializers
145-
version_constant:
146-
[OpenTelemetry, Instrumentation, ActiveModelSerializers, VERSION]
145+
version_constant: [OpenTelemetry, Instrumentation, ActiveModelSerializers, VERSION]
147146

148147
- name: opentelemetry-instrumentation-concurrent_ruby
149148
directory: instrumentation/concurrent_ruby
@@ -237,8 +236,7 @@ gems:
237236

238237
- name: opentelemetry-propagator-google_cloud_trace_context
239238
directory: propagator/google_cloud_trace_context
240-
version_constant:
241-
[OpenTelemetry, Propagator, GoogleCloudTraceContext, VERSION]
239+
version_constant: [OpenTelemetry, Propagator, GoogleCloudTraceContext, VERSION]
242240

243241
- name: opentelemetry-propagator-ottrace
244242
directory: propagator/ottrace
@@ -270,8 +268,7 @@ gems:
270268
- name: opentelemetry-resource-detector-google_cloud_platform
271269
directory: resources/google_cloud_platform
272270
version_rb_path: lib/opentelemetry/resource/detector/google_cloud_platform/version.rb
273-
version_constant:
274-
[OpenTelemetry, Resource, Detector, GoogleCloudPlatform, VERSION]
271+
version_constant: [OpenTelemetry, Resource, Detector, GoogleCloudPlatform, VERSION]
275272

276273
- name: opentelemetry-instrumentation-grpc
277274
directory: instrumentation/grpc

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ def instrument(event, payload)
2828
OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => host || hosts,
2929
OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => port,
3030
OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE => instrumentation_config[:peer_service]
31-
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes)
31+
}
32+
attributes.delete_if { |_key, value| value.nil? }
3233

3334
tracer.in_span(
3435
event,
35-
attributes: attributes.compact,
36+
attributes: attributes,
3637
kind: :client
3738
) do |span|
3839
yield(payload).tap do |response|
39-
annotate_span_with_response!(span, response)
40+
annotate_span_with_response(span, response) if response
4041
end
41-
rescue StandardError => e
42-
span.record_exception(e)
42+
rescue ::Net::LDAP::Error => e
43+
span.set_attribute('ldap.error_message', "#{e.class}: #{e.message}")
4344
span.status = OpenTelemetry::Trace::Status.error
4445
raise e
4546
end
@@ -57,9 +58,7 @@ def instrumentation_config
5758
LDAP::Instrumentation.instance.config
5859
end
5960

60-
def annotate_span_with_response!(span, response)
61-
return unless response
62-
61+
def annotate_span_with_response(span, response)
6362
status_code = ::Net::LDAP::ResultCodeSuccess
6463
message = ''
6564
error_message = ''
@@ -69,12 +68,15 @@ def annotate_span_with_response!(span, response)
6968
error_message = response.error_message.to_s
7069
message = ::Net::LDAP.result2string(status_code)
7170
end
72-
span.set_attribute('ldap.status_code', status_code)
73-
span.set_attribute('ldap.message', message) unless message.empty?
71+
attributes = {
72+
'ldap.status_code' => status_code
73+
}
74+
attributes['ldap.message'] = message unless message.empty?
75+
attributes['ldap.error_message'] = error_message unless error_message.empty?
76+
span.add_attributes(attributes)
7477

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

77-
span.record_exception(error_message) unless error_message.empty?
7880
span.status = OpenTelemetry::Trace::Status.error
7981
end
8082
end

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,9 @@ def add(args)
110110
_(span.attributes['ldap.base']).must_equal 'dc=com'
111111
_(span.attributes['ldap.encryption']).must_equal '{"method":"simple_tls","tls_options":{"foo":"bar"}}'
112112
_(span.attributes['ldap.payload']).must_equal '{}'
113+
_(span.attributes['ldap.error_message']).must_equal 'Net::LDAP::Error: Connection timed out - user specified timeout'
113114
_(span.attributes['net.peer.name']).must_equal 'test.mocked.com'
114115
_(span.attributes['net.peer.port']).must_equal 636
115-
_(span.events.first.attributes['exception.type']).must_equal 'Net::LDAP::Error'
116-
_(span.events.first.attributes['exception.message']).must_equal 'Connection timed out - user specified timeout'
117116
end
118117
end
119118
end

release-please-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,4 @@
231231
"version-file": "lib/opentelemetry/resource/detector/google_cloud_platform/version.rb"
232232
}
233233
}
234-
}
234+
}

0 commit comments

Comments
 (0)