• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pace / bricks / 11250208184

09 Oct 2024 07:25AM UTC coverage: 57.466% (-13.7%) from 71.177%
11250208184

push

github

web-flow
Merge pull request #380 from pace/sentry-tracing-poc

tracing: replace Jaeger with Sentry

140 of 206 new or added lines in 19 files covered. (67.96%)

3 existing lines in 3 files now uncovered.

5515 of 9597 relevant lines covered (57.47%)

21.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/grpc/client.go
1
// Copyright © 2021 by PACE Telematics GmbH. All rights reserved.
2

3
package grpc
4

5
import (
6
        "context"
7
        "time"
8

9
        "google.golang.org/grpc"
10
        "google.golang.org/grpc/credentials/insecure"
11
        "google.golang.org/grpc/metadata"
12

13
        "github.com/pace/bricks/http/middleware"
14
        "github.com/pace/bricks/http/security"
15
        "github.com/pace/bricks/locale"
16
        "github.com/pace/bricks/maintenance/log"
17

18
        grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
19
        grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
20
        grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
21
)
22

23
// Deprecated: Use NewClient instead.
NEW
24
func DialContext(_ context.Context, addr string) (*grpc.ClientConn, error) {
×
NEW
25
        return NewClient(addr)
×
UNCOV
26
}
×
27

28
// Deprecated: Use NewClient instead.
29
func Dial(addr string) (*grpc.ClientConn, error) {
×
NEW
30
        return NewClient(addr)
×
31
}
×
32

NEW
33
func NewClient(addr string) (*grpc.ClientConn, error) {
×
34
        var conn *grpc.ClientConn
×
35

×
36
        clientMetrics := grpc_prometheus.NewClientMetrics()
×
37

×
38
        opts := []grpc_retry.CallOption{
×
39
                grpc_retry.WithBackoff(grpc_retry.BackoffLinear(100 * time.Millisecond)),
×
40
        }
×
NEW
41

×
NEW
42
        conn, err := grpc.NewClient(addr,
×
NEW
43
                grpc.WithTransportCredentials(insecure.NewCredentials()),
×
44
                grpc.WithChainStreamInterceptor(
×
45
                        grpc_opentracing.StreamClientInterceptor(),
×
46
                        grpc_opentracing.StreamClientInterceptor(),
×
47
                        grpc_retry.StreamClientInterceptor(opts...),
×
48
                        func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error) {
×
49
                                start := time.Now()
×
50
                                cs, err := streamer(prepareClientContext(ctx), desc, cc, method, opts...)
×
51
                                log.Ctx(ctx).Debug().Str("method", method).
×
52
                                        Dur("duration", time.Since(start)).
×
53
                                        Str("type", "stream").
×
54
                                        Err(err).
×
55
                                        Msg("GRPC requested")
×
56
                                return cs, err
×
57
                        },
×
58
                ),
59
                grpc.WithChainUnaryInterceptor(
60
                        grpc_opentracing.UnaryClientInterceptor(),
61
                        clientMetrics.UnaryClientInterceptor(),
62
                        grpc_retry.UnaryClientInterceptor(opts...),
63
                        func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
×
64
                                start := time.Now()
×
65
                                err := invoker(prepareClientContext(ctx), method, req, reply, cc, opts...)
×
66
                                log.Ctx(ctx).Debug().Str("method", method).
×
67
                                        Dur("duration", time.Since(start)).
×
68
                                        Str("type", "unary").
×
69
                                        Err(err).
×
70
                                        Msg("GRPC requested")
×
71
                                return err
×
72
                        },
×
73
                ),
74
        )
75
        return conn, err
×
76
}
77

78
func prepareClientContext(ctx context.Context) context.Context {
×
79
        if loc, ok := locale.FromCtx(ctx); ok {
×
80
                ctx = metadata.AppendToOutgoingContext(ctx, MetadataKeyLocale, loc.Serialize())
×
81
        }
×
82
        if token, ok := security.GetTokenFromContext(ctx); ok {
×
83
                ctx = metadata.AppendToOutgoingContext(ctx, MetadataKeyBearerToken, token.GetValue())
×
84
        }
×
85
        if reqID := log.RequestIDFromContext(ctx); reqID != "" {
×
86
                ctx = metadata.AppendToOutgoingContext(ctx, MetadataKeyRequestID, reqID)
×
87
        }
×
88
        ctx = EncodeContextWithUTMData(ctx)
×
89

×
90
        if dep := middleware.ExternalDependencyContextFromContext(ctx); dep != nil {
×
91
                ctx = metadata.AppendToOutgoingContext(ctx, MetadataKeyExternalDependencies, dep.String())
×
92
        }
×
93

94
        return ctx
×
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc