userver: ugrpc::server::GenericCallContext Class Reference
Loading...
Searching...
No Matches
ugrpc::server::GenericCallContext Class Reference

#include <userver/ugrpc/server/call_context.hpp>

Detailed Description

generic gRPC call context

Definition at line 76 of file call_context.hpp.

+ Inheritance diagram for ugrpc::server::GenericCallContext:

Public Member Functions

void SetMetricsCallName (std::string_view call_name)
 Set a custom call name for metric labels.
 
grpc::ServerContext & GetServerContext ()
 
std::string_view GetCallName () const
 Name of the RPC in the format full.path.ServiceName/MethodName
 
std::string_view GetServiceName () const
 Get name of gRPC service.
 
std::string_view GetMethodName () const
 Get name of called gRPC method.
 
tracing::SpanGetSpan ()
 Get the span of the current RPC.
 
utils::AnyStorage< StorageContext > & GetStorageContext ()
 Returns call context for storing per-call custom data.
 

Member Function Documentation

◆ GetServerContext()

grpc::ServerContext & ugrpc::server::CallContext::GetServerContext ( )
inherited
Returns
the ServerContext used for this RPC

◆ GetStorageContext()

utils::AnyStorage< StorageContext > & ugrpc::server::CallContext::GetStorageContext ( )
inherited

Returns call context for storing per-call custom data.

The context can be used to pass data from server middleware to client handler or from one middleware to another one.

Example usage:

In authentication middleware:

if (password_is_correct) {
// Username is authenticated, set it in per-call storage context
ctx.GetCall().GetStorageContext().Emplace(kAuthUsername, username);
}

In client handler:

const auto& username = context.GetStorageContext().Get(kAuthUsername);
auto msg = fmt::format("Hello, {}!", username);

The documentation for this class was generated from the following file: