Skip to content

Commit b0ad041

Browse files
committed
bring back WithPluginSentryDSN(), use CQ_SENTRY_ENABLED
1 parent f4e97f2 commit b0ad041

3 files changed

Lines changed: 17 additions & 6 deletions

File tree

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,3 @@ require (
102102
)
103103

104104
replace github.com/invopop/jsonschema => github.com/cloudquery/jsonschema v0.0.0-20240220124159-92878faa2a66
105-
106-
replace github.com/cloudquery/plugin-pb-go => github.com/cloudquery/plugin-pb-go v1.27.6-0.20260109101738-6e12d05766f1

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ github.com/cloudquery/codegen v0.3.35 h1:gRGTz1jHwLdyxciQGzXi9QeCy+XxRKt5nHeVvJJ
6060
github.com/cloudquery/codegen v0.3.35/go.mod h1:3OPYs+XD/W0OrtvxHyAkWNvrJphDvLVJEH48TjuYKPc=
6161
github.com/cloudquery/jsonschema v0.0.0-20240220124159-92878faa2a66 h1:OZLPSIBYEfvkAUeOeM8CwTgVQy5zhayI99ishCrsFV0=
6262
github.com/cloudquery/jsonschema v0.0.0-20240220124159-92878faa2a66/go.mod h1:0SoZ/U7yJlNOR+fWsBSeTvTbGXB6DK01tzJ7m2Xfg34=
63+
github.com/cloudquery/plugin-pb-go v1.27.5/go.mod h1:80SQkYlFsm+vhPrba/eia5WWwctN6Azo9rbaZHZCyps=
6364
github.com/cloudquery/plugin-pb-go v1.27.6-0.20260109101738-6e12d05766f1 h1:jvdobvTNEGDtHxmOT4c6m9vDLVPWySdX5EcumGaOJ0s=
6465
github.com/cloudquery/plugin-pb-go v1.27.6-0.20260109101738-6e12d05766f1/go.mod h1:80SQkYlFsm+vhPrba/eia5WWwctN6Azo9rbaZHZCyps=
6566
github.com/cloudquery/plugin-sdk/v2 v2.7.0 h1:hRXsdEiaOxJtsn/wZMFQC9/jPfU1MeMK3KF+gPGqm7U=

serve/plugin.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package serve
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net"
78
"os"
89
"os/signal"
10+
"strconv"
911
"strings"
1012
"syscall"
1113

@@ -38,13 +40,20 @@ type PluginServe struct {
3840
plugin *plugin.Plugin
3941
args []string
4042
destinationV0V1Server bool
43+
sentryDSN string
4144
testListener bool
4245
testListenerConn *bufconn.Listener
4346
versions []int
4447
}
4548

4649
type PluginOption func(*PluginServe)
4750

51+
func WithPluginSentryDSN(dsn string) PluginOption {
52+
return func(s *PluginServe) {
53+
s.sentryDSN = dsn
54+
}
55+
}
56+
4857
// WithDestinationV0V1Server is used to include destination v0 and v1 server to work
4958
// with older sources
5059
func WithDestinationV0V1Server() PluginOption {
@@ -106,7 +115,6 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
106115
var address string
107116
var network string
108117
var noSentry bool
109-
var sentryDSN string
110118
var otelEndpoint string
111119
var otelEndpointInsecure bool
112120
var licenseFile string
@@ -125,6 +133,11 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
125133
Long: servePluginShort,
126134
Args: cobra.NoArgs,
127135
RunE: func(cmd *cobra.Command, _ []string) error {
136+
doSentry, _ := strconv.ParseBool(os.Getenv("CQ_SENTRY_ENABLED"))
137+
if doSentry && noSentry {
138+
return errors.New("CQ_SENTRY_ENABLED and --no-sentry cannot be used together")
139+
}
140+
128141
zerologLevel, err := zerolog.ParseLevel(logLevel.String())
129142
if err != nil {
130143
return err
@@ -208,9 +221,9 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
208221

209222
version := s.plugin.Version()
210223

211-
if len(sentryDSN) > 0 && !strings.EqualFold(version, "development") && !noSentry {
224+
if doSentry && len(s.sentryDSN) > 0 && !strings.EqualFold(version, "development") && !noSentry {
212225
err = sentry.Init(sentry.ClientOptions{
213-
Dsn: sentryDSN,
226+
Dsn: s.sentryDSN,
214227
Debug: false,
215228
AttachStacktrace: false,
216229
Release: version,
@@ -265,7 +278,6 @@ func (s *PluginServe) newCmdPluginServe() *cobra.Command {
265278
cmd.Flags().StringVar(&otelEndpoint, "otel-endpoint", "", "Open Telemetry HTTP collector endpoint")
266279
cmd.Flags().BoolVar(&otelEndpointInsecure, "otel-endpoint-insecure", false, "use Open Telemetry HTTP endpoint (for development only)")
267280
cmd.Flags().BoolVar(&noSentry, "no-sentry", false, "disable sentry")
268-
cmd.Flags().StringVar(&sentryDSN, "sentry-dsn", "", "Sentry DSN to use")
269281
cmd.Flags().StringVar(&licenseFile, "license", "", "Path to offline license file or directory")
270282

271283
return cmd

0 commit comments

Comments
 (0)