Skip to content

Commit 01a8779

Browse files
committed
revision
1 parent 834855d commit 01a8779

File tree

4 files changed

+32
-34
lines changed

4 files changed

+32
-34
lines changed

zero-code-instrumentation/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ These environment variables are not standard OpenTelemetry environment variables
126126

127127
| Environment Variable | Description | Default | Example |
128128
|----------------------|-------------|---------|---------|
129-
| `REQUIRE_BUNDLER` | Set to `true` if you are using Bundler to install gems but without `Bundler.require` in your script during initialization. | nil | N/A |
130-
| `USE_BUNDLE_EXEC` | Set to `true` if initializing through `bundle exec`. | nil | N/A |
131-
| `ADDITIONAL_GEM_PATH` | Intended to be used for the OpenTelemetry Operator environment if you install `zero-code-instrumentation` to a customized path. | nil | N/A |
132-
| `OTEL_OPERATOR` | Set to `true` to set the binding path for the OpenTelemetry Operator. | `/otel-auto-instrumentation-ruby` | N/A |
129+
| `OTEL_RUBY_REQUIRE_BUNDLER` | Set to `true` if you are using Bundler to install gems but without `Bundler.require` in your script during initialization. | nil | N/A |
130+
| `OTEL_RUBY_ADDITIONAL_GEM_PATH` | Intended to be used for the OpenTelemetry Operator environment if you install `zero-code-instrumentation` to a customized path. | nil | N/A |
131+
| `OTEL_RUBY_OPERATOR` | Set to `true` to set the binding path for the OpenTelemetry Operator. | `/otel-auto-instrumentation-ruby` | N/A |
133132
| `OTEL_RUBY_RESOURCE_DETECTORS` | Determine what kind of resource detector is needed. Currently supports `container`, `azure`, and `google_cloud_platform`. Use commas to separate multiple detectors. | nil | `container,azure` |
134133
| `OTEL_RUBY_ENABLED_INSTRUMENTATIONS` | Shortcut used when you only want to instrument one or a couple of particular libraries. | nil | `redis,active_record` |
135-
| `ZERO_CODE_DEBUG` | Set to `true` if want to see some debug information. This to avoid preload logger gem | nil | N/A |
134+
| `OTEL_RUBY_ZERO_CODE_DEBUG` | Set to `true` if want to see some debug information. This to avoid preload logger gem | nil | N/A |
135+
| `OTEL_RUBY_UNLOAD_LIBRARY` | Use OTEL_RUBY_UNLOAD_LIBRARY to avoid certain gem preload (esp. google protobuf) | nil | N/A |
136136

137137
## How can I get involved?
138138

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

Lines changed: 15 additions & 18 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(',').map { |instrumentation| OTEL_INSTRUMENTATION_MAP[instrumentation] }
80+
env.split(',').each_with_object({}) { |instrumentation, config| config[OTEL_INSTRUMENTATION_MAP[instrumentation]] = {} }
8181
end
8282

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

9191
OpenTelemetry::SDK.configure do |c|
9292
c.resource = detect_resource_from_env
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
93+
c.use_all(required_instrumentation)
10094
end
10195
OpenTelemetry.logger.info { 'Auto-instrumentation initialized' }
10296
rescue StandardError => e
@@ -113,27 +107,30 @@ def require_otel
113107

114108
# set OTEL_OPERATOR to false if not in autoinstrumentation-ruby image, default to /otel-auto-instrumentation-ruby
115109
# /otel-auto-instrumentation-ruby is set in opentelemetry-operator ruby.go
116-
operator_gem_path = (ENV['OTEL_OPERATOR'].nil? || ENV['OTEL_OPERATOR'] == 'true') ? '/otel-auto-instrumentation-ruby' : nil
117-
additional_gem_path = operator_gem_path || ENV['ADDITIONAL_GEM_PATH'] || Gem.dir
118-
puts "Loading the additional gem path from #{additional_gem_path}" if ENV['ZERO_CODE_DEBUG'] == 'true'
110+
operator_gem_path = (ENV['OTEL_RUBY_OPERATOR'].nil? || ENV['OTEL_RUBY_OPERATOR'] == 'true') ? '/otel-auto-instrumentation-ruby' : nil
111+
additional_gem_path = operator_gem_path || ENV['OTEL_RUBY_ADDITIONAL_GEM_PATH'] || Gem.dir
112+
puts "Loading the additional gem path from #{additional_gem_path}" if ENV['OTEL_RUBY_ZERO_CODE_DEBUG'] == 'true'
119113

120-
# use UNLOAD_LIBRARY to avoid certain gem preload (esp. google protobuf)
121-
# e.g export UNLOAD_LIBRARY=google-protobuf;googleapis-common-protos-types
122-
unload_libraries = ENV['UNLOAD_LIBRARY'].to_s.split(';')
114+
# use OTEL_RUBY_UNLOAD_LIBRARY to avoid certain gem preload (esp. google protobuf)
115+
# e.g export OTEL_RUBY_UNLOAD_LIBRARY=google-protobuf;googleapis-common-protos-types
116+
unload_libraries = ENV['OTEL_RUBY_UNLOAD_LIBRARY'].to_s.split(';')
123117
loaded_library_file_path = Array.new
124118

125119
Dir.glob("#{additional_gem_path}/gems/*").each do |file_path|
126120
gem_name = file_path.match(/\/gems\/([^\/]+)-\d/)[1]
127-
include_file = (file_path.include?('opentelemetry') || file_path.include?('google')) && !unload_libraries.include? gem_name
121+
include_file = (file_path.include?('opentelemetry') || file_path.include?('google')) && !unload_libraries.include?(gem_name)
128122
loaded_library_file_path << file_path if include_file
129123
end
130124

131-
puts loaded_library_file_path.to_s if ENV['ZERO_CODE_DEBUG'] == 'true'
132-
133125
loaded_library_file_path.each do |file_path|
134126
$LOAD_PATH.unshift("#{file_path}/lib")
135127
end
136128

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
133+
137134
require 'opentelemetry-sdk'
138135
require 'opentelemetry-instrumentation-all'
139136
require 'opentelemetry-helpers-mysql'
@@ -146,4 +143,4 @@ def require_otel
146143

147144
Bundler::Runtime.prepend(OTelBundlerPatch)
148145

149-
Bundler.require if ENV['REQUIRE_BUNDLER'].to_s == 'true'
146+
Bundler.require if ENV['OTEL_RUBY_REQUIRE_BUNDLER'].to_s == 'true'

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
OTelBundlerPatch.send(:undef_method, :require)
2020
OpenTelemetry::Instrumentation::Net::HTTP::Instrumentation.instance_variable_get(:@instance).instance_variable_set(:@installed, false)
2121
OpenTelemetry::Instrumentation::Rake::Instrumentation.instance_variable_get(:@instance).instance_variable_set(:@installed, false)
22+
23+
ENV['OTEL_RUBY_ENABLED_INSTRUMENTATIONS'] = nil
2224
end
2325

2426
it 'simple_load_test' do
@@ -64,7 +66,6 @@
6466
_(registry.size).must_equal 1
6567
_(registry.first.first.name).must_equal 'OpenTelemetry::Instrumentation::Net::HTTP'
6668

67-
ENV['OTEL_RUBY_ENABLED_INSTRUMENTATIONS'] = nil
6869
end
6970

7071
it 'simple_load_with_additional_resource' do

zero-code-instrumentation/zero-code-instrumentation.gemspec

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ Gem::Specification.new do |spec|
2626
spec.require_paths = ['lib']
2727
spec.required_ruby_version = '>= 3.1'
2828

29-
spec.add_dependency 'opentelemetry-api', '1.4.0'
30-
spec.add_dependency 'opentelemetry-exporter-otlp', '0.29.1'
31-
spec.add_dependency 'opentelemetry-helpers-mysql', '0.2.0'
32-
spec.add_dependency 'opentelemetry-helpers-sql-obfuscation', '0.3.0'
33-
spec.add_dependency 'opentelemetry-instrumentation-all', '0.72.0'
34-
spec.add_dependency 'opentelemetry-resource-detector-azure', '0.2.0'
35-
spec.add_dependency 'opentelemetry-resource-detector-container', '0.2.0'
36-
spec.add_dependency 'opentelemetry-resource-detector-google_cloud_platform', '0.2.0'
37-
spec.add_dependency 'opentelemetry-sdk', '1.6.0'
29+
spec.add_dependency 'opentelemetry-api', '~> 1.4.0'
30+
spec.add_dependency 'opentelemetry-exporter-otlp', '~> 0.29.1'
31+
spec.add_dependency 'opentelemetry-helpers-mysql', '~> 0.2.0'
32+
spec.add_dependency 'opentelemetry-helpers-sql-obfuscation', '~> 0.3.0'
33+
spec.add_dependency 'opentelemetry-instrumentation-all', '~> 0.72.0'
34+
spec.add_dependency 'opentelemetry-resource-detector-azure', '~> 0.2.0'
35+
spec.add_dependency 'opentelemetry-resource-detector-container', '~> 0.2.0'
36+
spec.add_dependency 'opentelemetry-resource-detector-google_cloud_platform', '~> 0.2.0'
37+
spec.add_dependency 'opentelemetry-sdk', '~> 1.6.0'
3838

3939
spec.add_development_dependency 'bundler', '~> 2.4'
4040
spec.add_development_dependency 'minitest', '~> 5.0'
@@ -51,5 +51,5 @@ Gem::Specification.new do |spec|
5151
spec.metadata['documentation_uri'] = "https://rubydoc.info/gems/#{spec.name}/#{spec.version}"
5252
end
5353

54-
spec.post_install_message = File.read(File.expand_path('../POST_INSTALL_MESSAGE', __dir__))
54+
# spec.post_install_message = File.read(File.expand_path('../POST_INSTALL_MESSAGE', __dir__))
5555
end

0 commit comments

Comments
 (0)