MCPcopy
hub / github.com/grpc/grpc-go / getOrCreateCallInfo

Function getOrCreateCallInfo

stats/opentelemetry/client_metrics.go:73–83  ·  view source on GitHub ↗

getOrCreateCallInfo returns the existing callInfo from context if present, or creates and attaches a new one.

(ctx context.Context, cc *grpc.ClientConn, method string, opts ...grpc.CallOption)

Source from the content-addressed store, hash-verified

71// getOrCreateCallInfo returns the existing callInfo from context if present,
72// or creates and attaches a new one.
73func getOrCreateCallInfo(ctx context.Context, cc *grpc.ClientConn, method string, opts ...grpc.CallOption) (context.Context, *callInfo) {
74 ci := getCallInfo(ctx)
75 if ci == nil {
76 ci = &callInfo{
77 target: cc.CanonicalTarget(),
78 method: determineMethod(method, opts...),
79 }
80 ctx = context.WithValue(ctx, callInfoKey{}, ci)
81 }
82 return ctx, ci
83}
84
85func (h *clientMetricsHandler) unaryInterceptor(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
86 ctx, ci := getOrCreateCallInfo(ctx, cc, method, opts...)

Callers 4

unaryInterceptorMethod · 0.85
streamInterceptorMethod · 0.85
unaryInterceptorMethod · 0.85
streamInterceptorMethod · 0.85

Calls 4

getCallInfoFunction · 0.85
determineMethodFunction · 0.85
CanonicalTargetMethod · 0.80
WithValueMethod · 0.80

Tested by

no test coverage detected