Skip to content

Commit e9988bb

Browse files
committed
revision
1 parent c1bbbcd commit e9988bb

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

lambda/otel/layer/otel_wrapper.rb

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
require 'opentelemetry-metrics-api'
44
require 'opentelemetry-metrics-sdk'
55
require 'opentelemetry-exporter-otlp'
6+
67
# We need to load the function code's dependencies, and _before_ any dependencies might
78
# be initialized outside of the function handler, bootstrap instrumentation. This allows
89
# instrumentation targets to be present, and accommodates instrumentations like AWS SDK
9-
# that add plugins on client initialization (vs. prepending methods).
10-
def preload_libraries
10+
# that add plugins on client initialization (vs. prepending methods).
11+
def preload_function_dependencies
1112
default_task_location = '/var/task'
1213

1314
handler_file = ENV.values_at('ORIG_HANDLER', '_HANDLER').compact.first&.split('.')&.first
@@ -28,27 +29,12 @@ def preload_libraries
2829
end
2930
end
3031

31-
preload_libraries
32-
33-
require 'opentelemetry/instrumentation/aws_sdk/handler'
34-
require 'opentelemetry/instrumentation/aws_sdk/services'
35-
36-
def loaded_constants
37-
services = Aws.constants & OpenTelemetry::Instrumentation::AwsSdk::SERVICES.map(&:to_sym)
32+
preload_function_dependencies
3833

39-
services.each_with_object([]) do |service, constants|
40-
next if Aws.autoload?(service)
41-
42-
begin
43-
constants << Aws.const_get(service, false).const_get(:Client, false)
44-
rescue StandardError => e
45-
OpenTelemetry.logger.warn { "Constant could not be loaded: #{e.message}" }
46-
end
47-
end
48-
end
34+
require 'opentelemetry-registry'
35+
require 'opentelemetry-instrumentation-all'
4936

50-
Seahorse::Client::Base.add_plugin(OpenTelemetry::Instrumentation::AwsSdk::Plugin) if defined?(Seahorse::Client::Base)
51-
loaded_constants.each { |klass| klass.add_plugin(OpenTelemetry::Instrumentation::AwsSdk::Plugin) }
37+
OpenTelemetry::Instrumentation.registry.install_all
5238

5339
require 'solarwinds_apm'
5440

0 commit comments

Comments
 (0)