MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / logFieldsForError

Function logFieldsForError

pkg/rpcmiddleware/rpclog/utils.go:32–49  ·  view source on GitHub ↗
(err error)

Source from the content-addressed store, hash-verified

30)
31
32func logFieldsForError(err error) *log.F {
33 fields := log.Fields()
34 if ttnErr, ok := errors.From(err); ok {
35 fields = fields.WithField("grpc_code", codes.Code(ttnErr.Code()))
36 if ns := ttnErr.Namespace(); ns != "" {
37 fields = fields.WithField("error_namespace", ns)
38 }
39 if name := ttnErr.Name(); name != "" {
40 fields = fields.WithField("error_name", name)
41 }
42 if cid := ttnErr.CorrelationID(); cid != "" {
43 fields = fields.WithField("error_correlation_id", cid)
44 }
45 } else if status, ok := status.FromError(err); ok {
46 fields = fields.WithField("grpc_code", status.Code())
47 }
48 return fields
49}
50
51func logFieldsForCall(ctx context.Context, fullMethodString string) (once, propagated *log.F) {
52 service := path.Dir(fullMethodString)[1:]

Callers 4

UnaryClientInterceptorFunction · 0.85
StreamClientInterceptorFunction · 0.85
UnaryServerInterceptorFunction · 0.85
StreamServerInterceptorFunction · 0.85

Calls 7

FieldsFunction · 0.92
FromFunction · 0.92
WithFieldMethod · 0.65
CodeMethod · 0.65
NamespaceMethod · 0.65
NameMethod · 0.65
CorrelationIDMethod · 0.65

Tested by

no test coverage detected