Skip to content

Commit d33f90d

Browse files
committed
update
1 parent 73bbb9a commit d33f90d

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
stack-service-base (0.0.73)
4+
stack-service-base (0.0.75)
55
async
66
debug
77
dotenv

lib/stack-service-base/open_telemetry.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44
ENV['OTEL_TRACES_EXPORTER'] ||= 'console,otlp'
55
ENV['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+
713
unless defined? OTEL_ENABLED
814
OTEL_ENABLED = !ENV['OTEL_EXPORTER_OTLP_ENDPOINT'].to_s.empty?
915
end
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

143152
def 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 = {})
151160
end
152161

153162
def otl_current_span
154-
return unless OTEL_ENABLED
163+
return unless OTEL_ENABLED && Otel.enabled
155164
yield OpenTelemetry::Trace.current_span
156165
end
157166

@@ -161,7 +170,7 @@ def otl_current_span
161170
# end
162171

163172
def 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*')

lib/stack-service-base/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module StackServiceBase
2-
VERSION = '0.0.74'
2+
VERSION = '0.0.75'
33
end

0 commit comments

Comments
 (0)