Skip to content

Commit f432544

Browse files
committed
revision
2 parents 01a8779 + 2c2b9f8 commit f432544

File tree

7 files changed

+24
-23
lines changed

7 files changed

+24
-23
lines changed

instrumentation/base/lib/opentelemetry/instrumentation/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def initialize(name, version, install_blk, present_blk,
214214
#
215215
# @param [Hash] config The config for this instrumentation
216216
def install(config = {})
217+
puts "name: #{@name}"
217218
return true if installed?
218219

219220
@config = config_options(config)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
inherit_from: ../.rubocop.yml
22
Naming/FileName:
33
Enabled: false
4+
Gemspec/DevelopmentDependencies:
5+
Enabled: false
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
# Release History: zero-code-instrumentation
2-
3-
### v0.1.0 / 2025-01-21
4-
5-
* Initial release

zero-code-instrumentation/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ OpenTelemetry provides a single set of APIs, libraries, agents, and collector se
1010

1111
## How does this gem fit in?
1212

13-
The `zero-code-instrumentation` gem provides an easy way to load and initialize the OpenTelemetry Ruby SDK. This gem is particularly used for the [OpenTelemetry Operator][opentelemetry-operator].
13+
The `zero-code-instrumentation` gem provides an easy way to load and initialize the OpenTelemetry Ruby SDK without changing your code initialize the SDK. This gem is particularly used with the [OpenTelemetry Operator][opentelemetry-operator].
1414

1515
## How do I get started?
1616

@@ -97,7 +97,7 @@ export REQUIRE_BUNDLER=true
9797
RUBYOPT="-r zero-code-instrumentation" rackup config.ru
9898
```
9999

100-
If wish to load some gem outside the Gemfile, then it needs to be placed in front of zero-code-instrumentation:
100+
If you wish to load some gems outside the Gemfile, then they need to be placed in front of zero-code-instrumentation:
101101

102102
```console
103103
export BUNDLE_WITHOUT=development,test
@@ -107,11 +107,11 @@ RUBYOPT="-r mysql2 -r zero-code-instrumentation" ruby application.rb
107107

108108
## Example
109109

110-
In example folder, execute the following commands should see the trace output.
110+
In example folder, executing the following commands should result in trace output.
111111

112112
```console
113-
# if user don't want to install zero-code-instrumentation from rubygems.org
114-
# user can build the gem and install it with gem install *.gem
113+
# if the user doesn't want to install zero-code-instrumentation from rubygems.org
114+
# the user can build the gem and install it with gem install *.gem
115115

116116
gem install zero-code-instrumentation
117117
bundle install

zero-code-instrumentation/lib/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
VERSION = '0.1.0'
7+
VERSION = '0.0.0'

zero-code-instrumentation/lib/zero-code-instrumentation.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def detect_resource_from_env
7777
def determine_enabled_instrumentation
7878
env = ENV['OTEL_RUBY_ENABLED_INSTRUMENTATIONS'].to_s
7979

80-
env.split(',').each_with_object({}) { |instrumentation, config| config[OTEL_INSTRUMENTATION_MAP[instrumentation]] = {} }
80+
env.split(',').map { |instrumentation| OTEL_INSTRUMENTATION_MAP[instrumentation] }
8181
end
8282

8383
def require_otel
@@ -90,7 +90,13 @@ def require_otel
9090

9191
OpenTelemetry::SDK.configure do |c|
9292
c.resource = detect_resource_from_env
93-
c.use_all(required_instrumentation)
93+
if required_instrumentation.empty?
94+
c.use_all # enables all instrumentation!
95+
else
96+
required_instrumentation.each do |instrumentation|
97+
c.use instrumentation
98+
end
99+
end
94100
end
95101
OpenTelemetry.logger.info { 'Auto-instrumentation initialized' }
96102
rescue StandardError => e
@@ -107,29 +113,26 @@ def require_otel
107113

108114
# set OTEL_OPERATOR to false if not in autoinstrumentation-ruby image, default to /otel-auto-instrumentation-ruby
109115
# /otel-auto-instrumentation-ruby is set in opentelemetry-operator ruby.go
110-
operator_gem_path = (ENV['OTEL_RUBY_OPERATOR'].nil? || ENV['OTEL_RUBY_OPERATOR'] == 'true') ? '/otel-auto-instrumentation-ruby' : nil
116+
operator_gem_path = ENV['OTEL_RUBY_OPERATOR'].nil? || ENV['OTEL_RUBY_OPERATOR'] == 'true' ? '/otel-auto-instrumentation-ruby' : nil
111117
additional_gem_path = operator_gem_path || ENV['OTEL_RUBY_ADDITIONAL_GEM_PATH'] || Gem.dir
112118
puts "Loading the additional gem path from #{additional_gem_path}" if ENV['OTEL_RUBY_ZERO_CODE_DEBUG'] == 'true'
113119

114120
# use OTEL_RUBY_UNLOAD_LIBRARY to avoid certain gem preload (esp. google protobuf)
115121
# e.g export OTEL_RUBY_UNLOAD_LIBRARY=google-protobuf;googleapis-common-protos-types
116122
unload_libraries = ENV['OTEL_RUBY_UNLOAD_LIBRARY'].to_s.split(';')
117-
loaded_library_file_path = Array.new
118123

119-
Dir.glob("#{additional_gem_path}/gems/*").each do |file_path|
120-
gem_name = file_path.match(/\/gems\/([^\/]+)-\d/)[1]
121-
include_file = (file_path.include?('opentelemetry') || file_path.include?('google')) && !unload_libraries.include?(gem_name)
122-
loaded_library_file_path << file_path if include_file
124+
loaded_library_file_path = Dir.glob("#{additional_gem_path}/gems/*").select do |file_path|
125+
gem_name = file_path.match(%r{/gems/([^/]+)-\d})[1]
126+
(file_path.include?('opentelemetry') || file_path.include?('google')) && !unload_libraries.include?(gem_name)
123127
end
124128

129+
puts "Loaded Library File Paths #{loaded_library_file_path.join(',')}" if ENV['ZERO_CODE_DEBUG'] == 'true'
130+
125131
loaded_library_file_path.each do |file_path|
126132
$LOAD_PATH.unshift("#{file_path}/lib")
127133
end
128134

129-
if ENV['OTEL_RUBY_ZERO_CODE_DEBUG'] == 'true'
130-
puts loaded_library_file_path.to_s
131-
puts "$LOAD_PATH #{$LOAD_PATH}"
132-
end
135+
puts "$LOAD_PATH after unshift: #{$LOAD_PATH.join(',')}" if ENV['OTEL_RUBY_ZERO_CODE_DEBUG'] == 'true'
133136

134137
require 'opentelemetry-sdk'
135138
require 'opentelemetry-instrumentation-all'

zero-code-instrumentation/test/zero-code-instrumentation_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565

6666
_(registry.size).must_equal 1
6767
_(registry.first.first.name).must_equal 'OpenTelemetry::Instrumentation::Net::HTTP'
68-
6968
end
7069

7170
it 'simple_load_with_additional_resource' do

0 commit comments

Comments
 (0)