-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathlogger.go
56 lines (47 loc) · 1.51 KB
/
logger.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
package query
import (
"time"
"github.com/influxdata/flux"
platform "github.com/influxdata/influxdb/v2"
)
// Logger persists metadata about executed queries.
type Logger interface {
Log(Log) error
}
// Log captures a query and any relevant metadata for the query execution.
type Log struct {
// Time is the time the query was completed
Time time.Time
// OrganizationID is the ID of the organization that requested the query
OrganizationID platform.ID
// TraceID is the ID of the trace related to this query
TraceID string
// Sampled specifies whether the trace for TraceID was chosen for permanent storage
// by the sampling mechanism of the tracer
Sampled bool
// Error is any error encountered by the query
Error error
// ProxyRequest is the query request
ProxyRequest *ProxyRequest
// ResponseSize is the size in bytes of the query response
ResponseSize int64
// Statistics is a set of statistics about the query execution
Statistics flux.Statistics
}
// Redact removes any sensitive information before logging
func (q *Log) Redact() {
if q.ProxyRequest != nil && q.ProxyRequest.Request.Authorization != nil {
// Make shallow copy of request
request := new(ProxyRequest)
*request = *q.ProxyRequest
// Make shallow copy of authorization
auth := new(platform.Authorization)
*auth = *q.ProxyRequest.Request.Authorization
// Redact authorization token
auth.Token = ""
// Apply redacted authorization
request.Request.Authorization = auth
// Apply redacted request
q.ProxyRequest = request
}
}