Skip to content

Commit

Permalink
Able to access tracer from interceptor context
Browse files Browse the repository at this point in the history
  • Loading branch information
jterapin committed Aug 23, 2024
1 parent c5fb7fa commit a25c263
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions hearth/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Metrics/MethodLength:

Metrics/ParameterLists:
Exclude:
- 'lib/hearth/interceptor_context.rb'
- 'lib/hearth/middleware/auth.rb'
- 'lib/hearth/middleware/send.rb'
- 'lib/hearth/middleware/event_streams.rb'
Expand Down
6 changes: 5 additions & 1 deletion hearth/lib/hearth/interceptor_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ class InterceptorContext
# @param [Response] response
# @param [Output] output
# @param [Configuration] config
def initialize(input:, request:, response:, output:, config:)
def initialize(input:, request:, response:, output:, config:, tracer:)
@input = input
@request = request
@response = response
@output = output
@config = config
@tracer = tracer
@attributes = {}
end

Expand All @@ -34,6 +35,9 @@ def initialize(input:, request:, response:, output:, config:)
# @return [Configuration] config
attr_reader :config

# @return [Tracer] tracer
attr_reader :tracer

# @return [Hash] attributes Additional interceptor data
attr_reader :attributes
end
Expand Down
3 changes: 2 additions & 1 deletion hearth/lib/hearth/interceptors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def interceptor_context(input, context, output)
request: context.request,
response: context.response,
output: output,
config: context.config
config: context.config,
tracer: context.tracer
)
end

Expand Down
2 changes: 2 additions & 0 deletions hearth/sig/lib/hearth/interceptor_context.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module Hearth

attr_reader config: Configuration[ServiceConfig]

attr_reader tracer: Telemetry::TracerBase

attr_reader attributes: Hash[Symbol, untyped]
end
end
11 changes: 9 additions & 2 deletions hearth/spec/hearth/interceptors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ def read_before_execution(_ctx); end
let(:config) do
double('config', logger: logger, interceptors: interceptors)
end
let(:tracer) { Telemetry::NoOpTracer.new }
let(:context) do
Context.new(request: request, response: response, config: config)
Context.new(
request: request,
response: response,
config: config,
tracer: tracer
)
end

let(:input) { double('input') }
Expand All @@ -37,7 +43,8 @@ def read_before_execution(_ctx); end
request: request,
response: response,
output: output,
config: config
config: config,
tracer: tracer
).and_return(i_ctx)

expect(interceptor1).to receive(hook).with(i_ctx)
Expand Down

0 comments on commit a25c263

Please sign in to comment.