View Source Unleash.Propagation.GRPC.ContextClientInterceptor (Unleash v3.0.0)

A gRPC Client Interceptor designed to propagate Unleash context and overrides downstream.

The context and overrides must be established in the propagation context, either manually (using Unleash.Propagation.put_context/1) or through middleware, such as Unleash.Propagation.GRPC.ContextClientInterceptor or Unleash.Propagation.Plugs.extract_unleash_context/2.

For further details on the propagation mechanism, see Unleash.Propagation.

Note that this interceptor will raise if it finds invalid context or overrides values in the propagation context that it can't serialize. This can happen if you put values in the propagation context manually and you do so incorrectly.

If you'd like to prevent such instances from breaking your gRPC requests, you can easily build your own interceptor that wraps this one and catches errors, for example:

defmodule MyUnleashContextClientInterceptorWrapper do
  @moduledoc false
  @behaviour GRPC.ClientInterceptor

  @impl true
  def init(_), do: nil

  def call(stream, req, next, opts) do
    Unleash.Propagation.GRPC.ContextClientInterceptor.call(stream, req, next, opts)
  rescue
    err ->
      Logger.error("your error message here")
      next.(stream, req)  # Continue the gRPC request processing
  end
end