Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jterapin committed Jul 17, 2024
1 parent cab7065 commit b40a708
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hearth/lib/hearth/telemetry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Hearth
# client = Service::Client.new(telemetry_provider: otel_provider)
#
# If a provider isn't supported, you can implement your own support by
# following the no-op interfaces within `Hearth::Telemetry`.
# following the telemetry interfaces defined in RBS.
module Telemetry
# @return true if opentelemetry-sdk is available
def self.otel_loaded?
Expand Down
17 changes: 17 additions & 0 deletions hearth/lib/hearth/telemetry/otel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,35 @@ def initialize

# OpenTelemetry-based ContextManager
class OTelContextManager < ContextManager
# Returns current context
#
# @return [Context]
def current
OpenTelemetry::Context.current
end

# Returns the current span from current context
#
# @return Span
def current_span
OpenTelemetry::Trace.current_span
end

# Associates a Context with the caller’s current execution unit.
# Returns a token to be used with the matching call to detach.
#
# @param [Context] context The new context
# @return [Object] token A token to be used when detaching
def attach(context)
OpenTelemetry::Context.attach(context)
end

# Restore the previous Context associated with the current
# execution unit to the value it had before attaching a
# specified Context.
#
# @param [Object] token The token provided by matching the call to attach
# @return [Boolean] True if the calls matched, False otherwise
def detach(token)
OpenTelemetry::Context.detach(token)
end
Expand Down
4 changes: 4 additions & 0 deletions hearth/sig/lib/hearth/telemetry.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ module Hearth
def initialize: () -> void
end

class OTelContextManager
include _ContextManager
end

interface _TracerProvider
def tracer: (?String name) -> _Tracer
end
Expand Down

0 comments on commit b40a708

Please sign in to comment.