-
Notifications
You must be signed in to change notification settings - Fork 2
/
call_option.go
91 lines (79 loc) · 2.6 KB
/
call_option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2022 Outreach Corporation. All Rights Reserved.
// Description: Provides various call options functions
package trace
import (
"context"
"time"
"github.com/getoutreach/gobox/internal/call"
)
// CallOptions contains options for all tracing calls. See
// call.Options for more information.
type CallOptions call.Options
// WithScheduledTime sets the call scheduled time to the provided
// time. Normally, this is set automatically by StartCall.
//
// Example:
//
// ctx = trace.StartCall(ctx, "http", log.F{"query": query}, trace.WithScheduledTime(time.Now()))
func WithScheduledTime(t time.Time) call.Option {
return func(c *call.Info) {
c.Times.Scheduled = t
}
}
// AsGRPCCall changes the call type to gRPC. This SHOULD NOT be used for outbound
// calls to external services. Use AsOutboundCall instead.
func AsGRPCCall() call.Option {
return func(c *call.Info) {
c.Type = call.TypeGRPC
}
}
// AsHTTPCall changes the call type to HTTP. This SHOULD NOT be used for outbound
// calls to external services. Use AsOutboundCall instead.
func AsHTTPCall() call.Option {
return func(c *call.Info) {
c.Type = call.TypeHTTP
}
}
// AsOutboundCall changes the call type to Outbound. This is meant for calls
// to external services, such as a client making a call to a server.
func AsOutboundCall() call.Option {
return func(c *call.Info) {
c.Type = call.TypeOutbound
}
}
// SetCallOptions sets the provided call options on the current call in the
// provided context. The provided options replace any existing options.
// Call options are not preserved across application boundaries.
//
// Example:
//
// ctx = trace.StartCall(ctx, "http", trace.WithCallOptions(ctx, trace.CallOptions{DisableInfoLogging: true}))
func WithCallOptions(ctx context.Context, opts CallOptions) {
callTracker.Info(ctx).Opts = call.Options(opts)
}
// WithInfoLoggingDisabled disables info logging on the current call.
//
// Note that the default behavior is configurable. If the info logs were
// already disabled by default, this will be a no-op.
//
// Example:
//
// ctx = trace.StartCall(ctx, "http", trace.WithInfoLoggingDisabled())
func WithInfoLoggingDisabled() call.Option {
return func(c *call.Info) {
c.Opts.EnableInfoLogging = false
}
}
// WithInfoLoggingEnabled enables info logging on the current call
//
// Note that the default behavior is configurable. If the info logs were
// already enabled by default, this will be a no-op.
//
// Example:
//
// ctx = trace.StartCall(ctx, "http", trace.WithInfoLoggingEnabled())
func WithInfoLoggingEnabled() call.Option {
return func(c *call.Info) {
c.Opts.EnableInfoLogging = true
}
}