Skip to content

Support BraveRpcService #6084

Description

@jrhee17

Motivation

For high-traffic services, it may be unfeasible to add tracing for all requests due to the large volume.
It is a common practice to sample traces for specific requests (e.g. by user id) instead of random sampling.

Currently, BraveService already provides a way to do this via either 1) Tracing.newBuilder().sampler(...) or 2) HttpTracing.newBuilder(...).serverSampler().
However, sometimes users would like to sample based on a parameter parsed by rpc requests.

Because BraveService determines whether a trace should be sampled before the request is parsed into a rpc request, it is difficult for users to sample based on RPC requests.

Proposal

I propose that a BraveRpcService is introduced. By doing so, users may sample traces based on RPC parameters more easily.
By doing so, users will be able to sample traces based on ServiceRequestContext#rpcRequest

i.e.

RpcTracing.newBuilder(tracing)
          .serverSampler(arg -> {
              final ServiceRequestContext ctx = (ServiceRequestContext) arg.unwrap();
              final RpcRequest rpcRequest = ctx.rpcRequest();
              if (rpcRequest != null && "...".equals(rpcRequest.serviceName())) {
                  return true;
              }
              return null;
          });

One caveat is that BraveRpcService sampler won't have an effect if a BraveService is already in the decorator chain and was processed.
The additional span containing RPC specific information would still probably be useful though.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions