/
diagnostics.go
72 lines (63 loc) · 1.83 KB
/
diagnostics.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
package core
import (
"github.com/cloudquery/cloudquery/pkg/plugin"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/spf13/viper"
)
type SentryDiagnostic struct {
diag.Diagnostic
Tags map[string]string
Ignore bool
}
func (d *SentryDiagnostic) Redacted() diag.Diagnostic {
v, ok := d.Diagnostic.(diag.Redactable)
if !ok {
return d
}
if r := v.Redacted(); r != nil {
return &SentryDiagnostic{
Diagnostic: r,
Tags: d.Tags,
Ignore: d.Ignore,
}
}
return d
}
func (d *SentryDiagnostic) IsSentryDiagnostic() (bool, map[string]string, bool) {
return true, d.Tags, d.Ignore
}
func convertToConfigureDiags(diags diag.Diagnostics) diag.Diagnostics {
return convertToSentryDiags(diags, func(d diag.Diagnostic) *SentryDiagnostic {
return &SentryDiagnostic{
Diagnostic: d,
Tags: map[string]string{"source": "configure"},
Ignore: d.Type() == diag.ACCESS,
}
})
}
func convertToFetchDiags(diags diag.Diagnostics, providerName, providerVersion string) diag.Diagnostics {
allowUnmanaged := viper.GetBool("debug-sentry")
return convertToSentryDiags(diags, func(d diag.Diagnostic) *SentryDiagnostic {
return &SentryDiagnostic{
Diagnostic: d,
Tags: map[string]string{
"provider": providerName,
"provider_version": providerVersion,
"resource": d.Description().Resource,
},
Ignore: !allowUnmanaged && providerVersion == plugin.Unmanaged,
}
})
}
// convertToSentryDiags gets the diags and applies the given handleFunc to each diag which converts them to a Sentry Diagnostic.
func convertToSentryDiags(diags diag.Diagnostics, handleFunc func(diag.Diagnostic) *SentryDiagnostic) diag.Diagnostics {
fd := make(diag.Diagnostics, 0, len(diags))
for i := range diags {
sd := handleFunc(diags[i])
if sd == nil {
continue
}
fd = append(fd, sd)
}
return fd
}