Skip to content

Commit 5a4da61

Browse files
committed
Update tests
1 parent 1f2210e commit 5a4da61

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

ruby/src/otel/layer/otel-handler

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,20 @@ export GEM_HOME="${RUBY_FULL_VERSION_DIR}"
3434

3535
# Ensure rubygems is preloaded and Ruby can find libs within gem directories
3636
export RUBYOPT="${RUBYOPT:--rrubygems}"
37-
# Add each gem's lib directory to RUBYLIB for extra safety (expanded at shell time)
38-
export RUBYLIB="${RUBY_FULL_VERSION_DIR}/gems/*/lib:${RUBYLIB:-}"
37+
# Build RUBYLIB as a colon-separated list of each gem's lib directory
38+
LIBS=""
39+
for d in "${RUBY_FULL_VERSION_DIR}"/gems/*/lib; do
40+
if [ -d "$d" ]; then
41+
if [ -z "$LIBS" ]; then
42+
LIBS="$d"
43+
else
44+
LIBS="$LIBS:$d"
45+
fi
46+
fi
47+
done
48+
if [ -n "$LIBS" ]; then
49+
export RUBYLIB="${LIBS}:${RUBYLIB:-}"
50+
fi
3951

4052
if [ -z "${OTEL_SERVICE_NAME}" ]; then
4153
export OTEL_SERVICE_NAME="$AWS_LAMBDA_FUNCTION_NAME";

ruby/src/otel/layer/wrapper.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# Ensure gem libs are on the load path in case environment hooks are ignored
2+
require 'rubygems'
3+
4+
begin
5+
gem_root = ENV['GEM_PATH'] || ENV['GEM_HOME']
6+
if gem_root && Dir.exist?(gem_root)
7+
# Ensure RubyGems knows about our layer paths
8+
begin
9+
default_paths = Gem.default_path
10+
Gem.use_paths(ENV['GEM_HOME'] || gem_root, [gem_root, *default_paths].uniq)
11+
Gem.refresh
12+
rescue StandardError
13+
# ignore, we still amend $LOAD_PATH manually below
14+
end
15+
Dir.glob(File.join(gem_root, 'gems', '*', 'lib')).each do |dir|
16+
$LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
17+
end
18+
end
19+
rescue StandardError
20+
# no-op: fall through to requires; errors will surface if libs are missing
21+
end
22+
123
require 'opentelemetry/sdk'
224
require 'opentelemetry/exporter/otlp'
325
require 'opentelemetry/instrumentation/all'

0 commit comments

Comments
 (0)