Class: Karafka::Instrumentation::Callbacks::OauthbearerTokenRefresh

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/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) ⇒ OauthbearerTokenRefresh

Returns a new instance of OauthbearerTokenRefresh.

Parameters:

  • bearer (Rdkafka::Consumer, Rdkafka::Admin)

    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.



15
16
17
# File 'lib/karafka/instrumentation/callbacks/oauthbearer_token_refresh.rb', line 15

def initialize(bearer)
  @bearer = bearer
end

Instance Method Details

#call(_rd_config, bearer_name) ⇒ Object

Parameters:

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

    name of the bearer for which we refresh



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/karafka/instrumentation/callbacks/oauthbearer_token_refresh.rb', line 21

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

  monitor.instrument(
    'oauthbearer.token_refresh',
    bearer: @bearer,
    caller: self
  )
rescue StandardError => e
  monitor.instrument(
    'error.occurred',
    caller: self,
    type: 'callbacks.oauthbearer_token_refresh.error',
    error: e
  )
end