@@ -2,10 +2,12 @@ package serve
22
33import (
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
4649type 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
5059func 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