-
Notifications
You must be signed in to change notification settings - Fork 2
/
meta.go
61 lines (45 loc) · 1.22 KB
/
meta.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
package meta
import (
"context"
"github.com/alexfalkowski/go-service/meta"
)
const (
// RequestIDKey for meta.
RequestIDKey = "requestId"
// UserAgentKey for meta.
UserAgentKey = "userAgent"
// ServiceKey for meta.
ServiceKey = "service"
// PathKey for meta.
PathKey = "path"
// MethodKey for meta.
MethodKey = "method"
// CodeKey for meta.
CodeKey = "code"
// DurationKey for meta.
DurationKey = "duration"
// StartTimeKey for meta.
StartTimeKey = "startTime"
// DeadlineKey for meta.
DeadlineKey = "deadline"
)
// WithRequestID for transport.
func WithRequestID(ctx context.Context, id string) context.Context {
return meta.WithAttribute(ctx, RequestIDKey, id)
}
// RequestID for transport.
func RequestID(ctx context.Context) string {
return meta.Attribute(ctx, RequestIDKey)
}
// WithUserAgent for transport.
func WithUserAgent(ctx context.Context, userAgent string) context.Context {
return meta.WithAttribute(ctx, UserAgentKey, userAgent)
}
// UserAgent for transport.
func UserAgent(ctx context.Context) string {
return meta.Attribute(ctx, UserAgentKey)
}
// WithTraceID for transport.
func WithTraceID(ctx context.Context, id string) context.Context {
return meta.WithAttribute(ctx, "traceId", id)
}