Skip to content

Commit e48939b

Browse files
committed
feat: sentry
1 parent 9dea69c commit e48939b

File tree

6 files changed

+69
-13
lines changed

6 files changed

+69
-13
lines changed

Makefile

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,45 @@ endif
1919
default: install
2020

2121
build:
22-
go build -o ${BINARY}
22+
go build -ldflags="-X pkg.Version=${VERSION}" -o ${BINARY}
2323

2424
release:
25-
GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64
26-
GOOS=freebsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_freebsd_386
27-
GOOS=freebsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_freebsd_amd64
28-
GOOS=freebsd GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_freebsd_arm
29-
GOOS=linux GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_linux_386
30-
GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64
31-
GOOS=linux GOARCH=arm go build -o ./bin/${BINARY}_${VERSION}_linux_arm
32-
GOOS=openbsd GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_openbsd_386
33-
GOOS=openbsd GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_openbsd_amd64
34-
GOOS=solaris GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_solaris_amd64
35-
GOOS=windows GOARCH=386 go build -o ./bin/${BINARY}_${VERSION}_windows_386
36-
GOOS=windows GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_windows_amd64
25+
GOOS=darwin GOARCH=amd64 go build \
26+
-ldflags="-X pkg.Version=${VERSION}" \
27+
-o ./bin/${BINARY}_${VERSION}_darwin_amd64
28+
GOOS=freebsd GOARCH=386 go build \
29+
-ldflags="-X pkg.Version=${VERSION}" \
30+
-o ./bin/${BINARY}_${VERSION}_freebsd_386
31+
GOOS=freebsd GOARCH=amd64 go build \
32+
-ldflags="-X pkg.Version=${VERSION}" \
33+
-o ./bin/${BINARY}_${VERSION}_freebsd_amd64
34+
GOOS=freebsd GOARCH=arm go build \
35+
-ldflags="-X pkg.Version=${VERSION}" \
36+
-o ./bin/${BINARY}_${VERSION}_freebsd_arm
37+
GOOS=linux GOARCH=386 go build
38+
-ldflags="-X pkg.Version=${VERSION}" \
39+
-o ./bin/${BINARY}_${VERSION}_linux_386
40+
GOOS=linux GOARCH=amd64 go build \
41+
-ldflags="-X pkg.Version=${VERSION}" \
42+
-o ./bin/${BINARY}_${VERSION}_linux_amd64
43+
GOOS=linux GOARCH=arm go build \
44+
-ldflags="-X pkg.Version=${VERSION}" \
45+
-o ./bin/${BINARY}_${VERSION}_linux_arm
46+
GOOS=openbsd GOARCH=386 go build \
47+
-ldflags="-X pkg.Version=${VERSION}" \
48+
-o ./bin/${BINARY}_${VERSION}_openbsd_386
49+
GOOS=openbsd GOARCH=amd64 go build \
50+
-ldflags="-X pkg.Version=${VERSION}"\
51+
-o ./bin/${BINARY}_${VERSION}_openbsd_amd64
52+
GOOS=solaris GOARCH=amd64 go build \
53+
-ldflags="-X pkg.Version=${VERSION}" \
54+
-o ./bin/${BINARY}_${VERSION}_solaris_amd64
55+
GOOS=windows GOARCH=386 go build \
56+
-ldflags="-X pkg.Version=${VERSION}" \
57+
-o ./bin/${BINARY}_${VERSION}_windows_386
58+
GOOS=windows GOARCH=amd64 go build \
59+
-ldflags="-X pkg.Version=${VERSION}" \
60+
-o ./bin/${BINARY}_${VERSION}_windows_amd64
3761

3862
install: build
3963
mkdir -p ~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ require (
3636
github.com/dustin/go-humanize v1.0.1 // indirect
3737
github.com/emirpasic/gods v1.18.1 // indirect
3838
github.com/fatih/color v1.16.0 // indirect
39+
github.com/getsentry/sentry-go v0.31.1 // indirect
3940
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
4041
github.com/go-ini/ini v1.67.0 // indirect
4142
github.com/go-logr/logr v1.4.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
5454
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
5555
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
5656
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
57+
github.com/getsentry/sentry-go v0.31.1 h1:ELVc0h7gwyhnXHDouXkhqTFSO5oslsRDk0++eyE0KJ4=
58+
github.com/getsentry/sentry-go v0.31.1/go.mod h1:CYNcMMz73YigoHljQRG+qPF+eMq8gG72XcGN/p71BAY=
5759
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
5860
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
5961
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=

pkg/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package pkg
2+
3+
// Override by ldflags on build
4+
var Version string = "dev"

pkg/provider/impl/provider_configure.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"time"
78

9+
"github.com/getsentry/sentry-go"
810
"github.com/hashicorp/terraform-plugin-framework/provider"
911
"github.com/hashicorp/terraform-plugin-log/tflog"
12+
"go.clever-cloud.com/terraform-provider/pkg"
1013
"go.clever-cloud.dev/client"
1114
)
1215

@@ -21,6 +24,24 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
2124
return
2225
}
2326

27+
// Sentry, on the higher CONFIGURABLE level
28+
if config.ErrorReports.ValueBool() { // implicit == true
29+
err := sentry.Init(sentry.ClientOptions{
30+
Dsn: "https://9f1c17cd85db40f5a1991aefcc182944@glitchtip.corp.clever-cloud.com/35",
31+
AttachStacktrace: true,
32+
Release: pkg.Version,
33+
Dist: req.TerraformVersion,
34+
Tags: map[string]string{
35+
"endpoint": config.Endpoint.ValueString(),
36+
"owner": config.Organisation.ValueString(),
37+
},
38+
})
39+
if err != nil {
40+
tflog.Warn(ctx, "failed to setup sentry", map[string]interface{}{"error": err.Error()})
41+
}
42+
defer sentry.Flush(2 * time.Second)
43+
}
44+
2445
if config.Organisation.IsUnknown() || config.Organisation.IsNull() {
2546
p.organization = os.Getenv("CC_ORGANISATION")
2647
} else {

pkg/provider/impl/provider_schema.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ProviderData struct {
2020
Organisation types.String `tfsdk:"organisation"`
2121
ConsumerKey types.String `tfsdk:"consumer_key"`
2222
ConsumerSecret types.String `tfsdk:"consumer_secret"`
23+
ErrorReports types.Bool `tfsdk:"error_reports"`
2324
}
2425

2526
//go:embed provider.md
@@ -60,6 +61,9 @@ func (p *Provider) Schema(_ context.Context, req provider.SchemaRequest, res *pr
6061
Optional: true,
6162
Sensitive: true,
6263
MarkdownDescription: "CleverCloud OAuth1 consumer secret. Allows using a dedicated OAuth consumer.",
64+
"error_reports": schema.BoolAttribute{
65+
Optional: true,
66+
MarkdownDescription: "Report any errors on provider directly to provider",
6367
},
6468
},
6569
}

0 commit comments

Comments
 (0)