...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package logging
16
17 import (
18 "strings"
19
20 logpb "cloud.google.com/go/logging/apiv2/loggingpb"
21 "cloud.google.com/go/logging/internal"
22 )
23
24 const diagnosticLogID = "diagnostic-log"
25
26
27 type instrumentationPayload struct {
28 InstrumentationSource []map[string]string `json:"instrumentation_source"`
29 Runtime string `json:"runtime,omitempty"`
30 }
31
32 var (
33 instrumentationInfo = &instrumentationPayload{
34 InstrumentationSource: []map[string]string{
35 {
36 "name": "go",
37 "version": internal.Version,
38 },
39 },
40 Runtime: internal.VersionGo(),
41 }
42 )
43
44
45
46 func (l *Logger) instrumentLogs(entries []*logpb.LogEntry) ([]*logpb.LogEntry, bool) {
47 var instrumentationAdded bool
48
49 internal.InstrumentOnce.Do(func() {
50 ie, err := l.instrumentationEntry()
51 if err != nil {
52
53 return
54 }
55
56 if l.redirectOutputWriter == nil {
57 ie.LogName = internal.LogPath(l.client.parent, diagnosticLogID)
58 }
59 entries = append(entries, ie)
60 instrumentationAdded = true
61 })
62 return entries, instrumentationAdded
63 }
64
65 func (l *Logger) instrumentationEntry() (*logpb.LogEntry, error) {
66 ent := Entry{
67 Payload: map[string]*instrumentationPayload{
68 "logging.googleapis.com/diagnostic": instrumentationInfo,
69 },
70 }
71
72 return toLogEntryInternal(ent, nil, l.client.parent, 0)
73 }
74
75
76 func hasInstrumentation(entries []*logpb.LogEntry) bool {
77 for _, ent := range entries {
78 if strings.HasSuffix(ent.LogName, diagnosticLogID) {
79 return true
80 }
81 }
82 return false
83 }
84
View as plain text