-
Notifications
You must be signed in to change notification settings - Fork 10
/
operation.go
58 lines (48 loc) · 1.96 KB
/
operation.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
package zerodriver
import (
"github.com/rs/zerolog"
)
// operation is the complete payload that can be interpreted by Cloud Logging as
// an operation.
// see: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntryOperation
type operation struct {
// Optional. An arbitrary operation identifier. Log entries with the same
// identifier are assumed to be part of the same operation.
ID string `json:"id"`
// Optional. An arbitrary producer identifier. The combination of id and
// producer must be globally unique. Examples for producer:
// "MyDivision.MyBigCompany.com", "github.com/MyProject/MyApplication".
Producer string `json:"producer"`
// Optional. Set this to True if this is the first log entry in the operation.
First bool `json:"first"`
// Optional. Set this to True if this is the last log entry in the operation.
Last bool `json:"last"`
}
// Operation adds the correct Cloud Logging "operation" field.
//
// Additional information about a potentially long-running operation with which
// a log entry is associated.
func (e *Event) Operation(id, producer string, first, last bool) *zerolog.Event {
op := &operation{
ID: id,
Producer: producer,
First: first,
Last: last,
}
return e.Event.Interface("logging.googleapis.com/operation", op)
}
// OperationStart is a function for logging `Operation`. It should be called
// for the first operation log.
func (e *Event) OperationStart(id, producer string) *zerolog.Event {
return e.Operation(id, producer, true, false)
}
// OperationContinue is a function for logging `Operation`. It should be called
// for any non-start/end operation log.
func (e *Event) OperationContinue(id, producer string) *zerolog.Event {
return e.Operation(id, producer, false, false)
}
// OperationEnd is a function for logging `Operation`. It should be called
// for the last operation log.
func (e *Event) OperationEnd(id, producer string) *zerolog.Event {
return e.Operation(id, producer, false, true)
}