44ENV [ 'OTEL_TRACES_EXPORTER' ] ||= 'console,otlp'
55ENV [ 'OTEL_LOGS_EXPORTER' ] ||= 'otlp,console'
66
7+ class Otel
8+ class << self
9+ attr_accessor :enabled # To temporally disable Otel
10+ end
11+ end
12+
713unless defined? OTEL_ENABLED
814 OTEL_ENABLED = !ENV [ 'OTEL_EXPORTER_OTLP_ENDPOINT' ] . to_s . empty?
915end
16+
17+ Otel . enabled = OTEL_ENABLED
18+
1019$stdout. puts "OTEL_ENABLED: #{ OTEL_ENABLED } "
1120
1221# require 'async'
@@ -142,7 +151,7 @@ def valid_connection?(...)
142151
143152def otl_span ( name , attributes = { } )
144153 # span_ = OpenTelemetry::Trace.current_span
145- return yield ( nil ) unless OTEL_ENABLED
154+ return yield ( nil ) unless OTEL_ENABLED && Otel . enabled
146155
147156 return yield ( nil ) unless $tracer_
148157 $tracer_&.in_span ( name , attributes : flatten_hash ( attributes . transform_keys ( &:to_s ) . transform_values { _1 || 'n/a' } ) ) do |span |
@@ -151,7 +160,7 @@ def otl_span(name, attributes = {})
151160end
152161
153162def otl_current_span
154- return unless OTEL_ENABLED
163+ return unless OTEL_ENABLED && Otel . enabled
155164 yield OpenTelemetry ::Trace . current_span
156165end
157166
@@ -161,7 +170,7 @@ def otl_current_span
161170# end
162171
163172def otl_traceparent_id
164- return nil unless OTEL_ENABLED
173+ return nil unless OTEL_ENABLED && Otel . enabled
165174
166175 span_context = OpenTelemetry ::Trace . current_span . context
167176 trace_id = span_context . trace_id . unpack1 ( 'H*' )
0 commit comments