Class: WaterDrop::Instrumentation::Callbacks::OauthbearerTokenRefresh

Inherits:
Object
  • Object
show all
Defined in:
lib/waterdrop/instrumentation/callbacks/oauthbearer_token_refresh.rb

Overview

Callback that is triggered when oauth token needs to be refreshed.

Instance Method Summary collapse

Constructor Details

#initialize(bearer, monitor) ⇒ OauthbearerTokenRefresh

Returns a new instance of OauthbearerTokenRefresh.

Parameters:

  • bearer (Rdkafka::Producer)

    given rdkafka instance. It is needed as we need to have a reference to call #oauthbearer_set_token or #oauthbearer_set_token_failure upon the event.

  • monitor (WaterDrop::Instrumentation::Monitor)

    monitor we are using



12
13
14
15
# File 'lib/waterdrop/instrumentation/callbacks/oauthbearer_token_refresh.rb', line 12

def initialize(bearer, monitor)
  @bearer = bearer
  @monitor = monitor
end

Instance Method Details

#call(_rd_config, bearer_name) ⇒ Object

Upon receiving of this event, user is required to invoke either #oauthbearer_set_token or #oauthbearer_set_token_failure on the event[:bearer] depending whether token obtaining was successful or not.

Please refer to WaterDrop and Karafka documentation or Rdkafka::Helpers::OAuth documentation directly for exact parameters of those methods.

Parameters:

  • _rd_config (Rdkafka::Config)
  • bearer_name (String)

    name of the bearer for which we refresh



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/waterdrop/instrumentation/callbacks/oauthbearer_token_refresh.rb', line 26

def call(_rd_config, bearer_name)
  return unless @bearer.name == bearer_name

  @monitor.instrument(
    'oauthbearer.token_refresh',
    bearer: @bearer,
    caller: self
  )
# This runs from the rdkafka thread, thus we want to safe-guard it and prevent absolute
# crashes even if the instrumentation code fails. If it would bubble-up, it could crash
# the rdkafka background thread
rescue StandardError => e
  @monitor.instrument(
    'error.occurred',
    caller: self,
    error: e,
    producer_id: @producer_id,
    type: 'callbacks.oauthbearer_token_refresh.error'
  )
end