Skip to content

Commit

Permalink
Correct work with stack tracer
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art committed Aug 4, 2021
1 parent fe8d8e6 commit 0fde629
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 63 deletions.
8 changes: 2 additions & 6 deletions pkg/networkservice/core/trace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ func (t *beginTraceClient) Request(ctx context.Context, request *networkservice.
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}

Expand All @@ -83,10 +81,8 @@ func (t *beginTraceClient) Close(ctx context.Context, conn *networkservice.Conne
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}

Expand Down
8 changes: 2 additions & 6 deletions pkg/networkservice/core/trace/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ func (t *beginTraceServer) Request(ctx context.Context, request *networkservice.
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}

Expand All @@ -81,10 +79,8 @@ func (t *beginTraceServer) Close(ctx context.Context, conn *networkservice.Conne
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
logResponse(ctx, conn)
Expand Down
32 changes: 8 additions & 24 deletions pkg/registry/core/trace/ns_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ func (t *traceNetworkServiceRegistryFindClient) Recv() (*registry.NetworkService
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand All @@ -73,10 +71,8 @@ func (t *traceNetworkServiceRegistryClient) Register(ctx context.Context, in *re
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand All @@ -95,10 +91,8 @@ func (t *traceNetworkServiceRegistryClient) Find(ctx context.Context, in *regist
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand All @@ -119,10 +113,8 @@ func (t *traceNetworkServiceRegistryClient) Unregister(ctx context.Context, in *
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand Down Expand Up @@ -150,10 +142,8 @@ func (t *traceNetworkServiceRegistryServer) Register(ctx context.Context, in *re
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand All @@ -176,10 +166,8 @@ func (t *traceNetworkServiceRegistryServer) Find(in *registry.NetworkServiceQuer
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return err
}
return nil
Expand All @@ -198,10 +186,8 @@ func (t *traceNetworkServiceRegistryServer) Unregister(ctx context.Context, in *
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand Down Expand Up @@ -229,10 +215,8 @@ func (t *traceNetworkServiceRegistryFindServer) Send(ns *registry.NetworkService
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return err
}
return err
Expand Down
32 changes: 8 additions & 24 deletions pkg/registry/core/trace/nse_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ func (t *traceNetworkServiceEndpointRegistryFindClient) Recv() (*registry.Networ
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand All @@ -72,10 +70,8 @@ func (t *traceNetworkServiceEndpointRegistryClient) Register(ctx context.Context
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand All @@ -94,10 +90,8 @@ func (t *traceNetworkServiceEndpointRegistryClient) Find(ctx context.Context, in
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand All @@ -118,10 +112,8 @@ func (t *traceNetworkServiceEndpointRegistryClient) Unregister(ctx context.Conte
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand Down Expand Up @@ -149,10 +141,8 @@ func (t *traceNetworkServiceEndpointRegistryServer) Register(ctx context.Context
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand All @@ -175,10 +165,8 @@ func (t *traceNetworkServiceEndpointRegistryServer) Find(in *registry.NetworkSer
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return err
}
return nil
Expand All @@ -197,10 +185,8 @@ func (t *traceNetworkServiceEndpointRegistryServer) Unregister(ctx context.Conte
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return nil, err
}
log.FromContext(ctx).Object("response", rv)
Expand Down Expand Up @@ -228,10 +214,8 @@ func (t *traceNetworkServiceEndpointRegistryFindServer) Send(nse *registry.Netwo
if err != nil {
if _, ok := err.(stackTracer); !ok {
err = errors.Wrapf(err, "Error returned from %s", operation)
log.FromContext(ctx).Errorf("%+v", err)
return err
}
log.FromContext(ctx).Errorf("%v", err)
log.FromContext(ctx).Errorf("%+v", err)
return err
}
return err
Expand Down
5 changes: 2 additions & 3 deletions pkg/tools/log/spanlogger/spanlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"encoding/json"
"fmt"
"runtime/debug"
"strings"
"sync"

Expand Down Expand Up @@ -61,11 +60,11 @@ func (s *spanLogger) Warnf(format string, v ...interface{}) {
}

func (s *spanLogger) Error(v ...interface{}) {
s.WithField("stacktrace", limitString(string(debug.Stack()))).(*spanLogger).log("error", v...)
s.log("error", v...)
}

func (s *spanLogger) Errorf(format string, v ...interface{}) {
s.WithField("stacktrace", limitString(string(debug.Stack()))).(*spanLogger).logf("error", format, v...)
s.logf("error", format, v...)
}

func (s *spanLogger) Fatal(v ...interface{}) {
Expand Down

0 comments on commit 0fde629

Please sign in to comment.