mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:31:54 +00:00
feat(ci): sentry events on pipeline generation failures (#39289)
* update sg log * use sg log and log sentry events * lookup sentry DSN from environment * Update enterprise/dev/ci/gen-pipeline.go Co-authored-by: Jean-Hadrien Chabran <jh@chabran.fr> * Update enterprise/dev/ci/internal/ci/pipeline.go * Update dev/sg/internal/analytics/context.go Co-authored-by: Robert Lin <robert@bobheadxi.dev> * Update enterprise/dev/ci/gen-pipeline.go Co-authored-by: Robert Lin <robert@bobheadxi.dev> * remove package level logger Co-authored-by: Jean-Hadrien Chabran <jh@chabran.fr> Co-authored-by: Robert Lin <robert@bobheadxi.dev>
This commit is contained in:
parent
75acf942e6
commit
ef31cf98a0
@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/graph-gophers/graphql-go"
|
||||
"github.com/inconshreveable/log15"
|
||||
"github.com/keegancsmith/tmpfriend"
|
||||
@ -24,8 +25,6 @@ import (
|
||||
|
||||
sglog "github.com/sourcegraph/log"
|
||||
|
||||
sentrylib "github.com/getsentry/sentry-go"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/enterprise"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/envvar"
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/globals"
|
||||
@ -139,7 +138,11 @@ func Main(enterpriseSetupHook func(db database.DB, c conftypes.UnifiedWatchable)
|
||||
Name: env.MyName,
|
||||
Version: version.Version(),
|
||||
InstanceID: hostname.Get(),
|
||||
}, sglog.NewSentrySinkWithOptions(sentrylib.ClientOptions{SampleRate: 0.2})) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
}, sglog.NewSentrySinkWith(
|
||||
sglog.SentrySink{
|
||||
ClientOptions: sentry.ClientOptions{SampleRate: 0.2},
|
||||
},
|
||||
)) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
defer liblog.Sync()
|
||||
|
||||
hc := &check.HealthChecker{Checks: []check.Check{
|
||||
|
||||
@ -15,12 +15,12 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/gorilla/handlers"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
sentrylib "github.com/getsentry/sentry-go"
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/internal/conf"
|
||||
@ -28,7 +28,6 @@ import (
|
||||
"github.com/sourcegraph/sourcegraph/internal/env"
|
||||
"github.com/sourcegraph/sourcegraph/internal/goroutine"
|
||||
"github.com/sourcegraph/sourcegraph/internal/hostname"
|
||||
"github.com/sourcegraph/sourcegraph/internal/logging"
|
||||
"github.com/sourcegraph/sourcegraph/internal/trace"
|
||||
"github.com/sourcegraph/sourcegraph/internal/trace/ot"
|
||||
"github.com/sourcegraph/sourcegraph/internal/tracer"
|
||||
@ -60,13 +59,16 @@ var hopHeaders = map[string]struct{}{
|
||||
func main() {
|
||||
env.Lock()
|
||||
env.HandleHelpFlag()
|
||||
logging.Init()
|
||||
|
||||
liblog := log.Init(log.Resource{
|
||||
Name: env.MyName,
|
||||
Version: version.Version(),
|
||||
InstanceID: hostname.Get(),
|
||||
}, log.NewSentrySinkWithOptions(sentrylib.ClientOptions{SampleRate: 0.2})) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
}, log.NewSentrySinkWith(
|
||||
log.SentrySink{
|
||||
ClientOptions: sentry.ClientOptions{SampleRate: 0.2},
|
||||
},
|
||||
)) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
|
||||
defer liblog.Sync()
|
||||
conf.Init()
|
||||
|
||||
@ -22,8 +22,7 @@ import (
|
||||
"golang.org/x/sync/semaphore"
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
sentrylib "github.com/getsentry/sentry-go"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/gitserver/server"
|
||||
@ -89,7 +88,11 @@ func main() {
|
||||
Name: env.MyName,
|
||||
Version: version.Version(),
|
||||
InstanceID: hostname.Get(),
|
||||
}, log.NewSentrySinkWithOptions(sentrylib.ClientOptions{SampleRate: 0.2})) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
}, log.NewSentrySinkWith(
|
||||
log.SentrySink{
|
||||
ClientOptions: sentry.ClientOptions{SampleRate: 0.2},
|
||||
},
|
||||
))
|
||||
defer liblog.Sync()
|
||||
|
||||
conf.Init()
|
||||
|
||||
@ -13,12 +13,11 @@ import (
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/graph-gophers/graphql-go/relay"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
sentrylib "github.com/getsentry/sentry-go"
|
||||
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/frontend/envvar"
|
||||
@ -80,7 +79,11 @@ func Main(enterpriseInit EnterpriseInit) {
|
||||
Name: env.MyName,
|
||||
Version: version.Version(),
|
||||
InstanceID: hostname.Get(),
|
||||
}, log.NewSentrySinkWithOptions(sentrylib.ClientOptions{SampleRate: 0.2})) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
}, log.NewSentrySinkWith(
|
||||
log.SentrySink{
|
||||
ClientOptions: sentry.ClientOptions{SampleRate: 0.2},
|
||||
},
|
||||
)) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
defer liblog.Sync()
|
||||
|
||||
conf.Init()
|
||||
|
||||
@ -17,7 +17,7 @@ import (
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
sentrylib "github.com/getsentry/sentry-go"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/keegancsmith/tmpfriend"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@ -238,7 +238,11 @@ func main() {
|
||||
Name: env.MyName,
|
||||
Version: version.Version(),
|
||||
InstanceID: hostname.Get(),
|
||||
}, log.NewSentrySinkWithOptions(sentrylib.ClientOptions{SampleRate: 0.2})) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
}, log.NewSentrySinkWith(
|
||||
log.SentrySink{
|
||||
ClientOptions: sentry.ClientOptions{SampleRate: 0.2},
|
||||
},
|
||||
)) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
defer liblog.Sync()
|
||||
|
||||
conf.Init()
|
||||
|
||||
@ -9,10 +9,10 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
sentrylib "github.com/getsentry/sentry-go"
|
||||
"github.com/sourcegraph/log"
|
||||
|
||||
"github.com/sourcegraph/sourcegraph/cmd/symbols/fetcher"
|
||||
@ -52,7 +52,11 @@ func Main(setup SetupFunc) {
|
||||
Name: env.MyName,
|
||||
Version: version.Version(),
|
||||
InstanceID: hostname.Get(),
|
||||
}, log.NewSentrySinkWithOptions(sentrylib.ClientOptions{SampleRate: 0.2})) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
}, log.NewSentrySinkWith(
|
||||
log.SentrySink{
|
||||
ClientOptions: sentry.ClientOptions{SampleRate: 0.2},
|
||||
},
|
||||
)) // Experimental: DevX is observing how sampling affects the errors signal
|
||||
defer liblog.Sync()
|
||||
|
||||
conf.Init()
|
||||
|
||||
@ -31,7 +31,7 @@ func WithContext(ctx context.Context, sgVersion string) (context.Context, error)
|
||||
provider := oteltracesdk.NewTracerProvider(
|
||||
oteltracesdk.WithResource(newResource(log.Resource{
|
||||
Name: "sg",
|
||||
Namespace: "dev",
|
||||
Namespace: sgVersion,
|
||||
Version: sgVersion,
|
||||
InstanceID: identity,
|
||||
})),
|
||||
|
||||
@ -7,17 +7,19 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/grafana/regexp"
|
||||
|
||||
"github.com/sourcegraph/log"
|
||||
"github.com/sourcegraph/sourcegraph/dev/ci/runtype"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/dev/ci/internal/buildkite"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/dev/ci/internal/ci"
|
||||
"github.com/sourcegraph/sourcegraph/enterprise/dev/ci/internal/ci/changed"
|
||||
"github.com/sourcegraph/sourcegraph/internal/hostname"
|
||||
)
|
||||
|
||||
var preview bool
|
||||
@ -35,8 +37,24 @@ func init() {
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
liblog := log.Init(log.Resource{
|
||||
Name: "buildkite-ci",
|
||||
Version: "",
|
||||
InstanceID: hostname.Get(),
|
||||
}, log.NewSentrySinkWith(
|
||||
log.SentrySink{
|
||||
ClientOptions: sentry.ClientOptions{
|
||||
Dsn: os.Getenv("CI_SENTRY_DSN"),
|
||||
SampleRate: 1, //send all
|
||||
},
|
||||
},
|
||||
))
|
||||
defer liblog.Sync()
|
||||
|
||||
logger := log.Scoped("gen-pipeline", "generates the pipeline for ci")
|
||||
|
||||
if docs {
|
||||
renderPipelineDocs(os.Stdout)
|
||||
renderPipelineDocs(logger, os.Stdout)
|
||||
return
|
||||
}
|
||||
|
||||
@ -44,7 +62,7 @@ func main() {
|
||||
|
||||
pipeline, err := ci.GeneratePipeline(config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
logger.Fatal("failed to generate pipeline", log.Error(err))
|
||||
}
|
||||
|
||||
if preview {
|
||||
@ -58,7 +76,7 @@ func main() {
|
||||
_, err = pipeline.WriteJSONTo(os.Stdout)
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
logger.Fatal("failed to write pipeline out to stdout", log.Error(err), log.Bool("wantYaml", wantYaml))
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,7 +118,7 @@ func trimEmoji(s string) string {
|
||||
return strings.TrimSpace(emojiRegexp.ReplaceAllString(s, ""))
|
||||
}
|
||||
|
||||
func renderPipelineDocs(w io.Writer) {
|
||||
func renderPipelineDocs(logger log.Logger, w io.Writer) {
|
||||
fmt.Fprintln(w, "# Pipeline types reference")
|
||||
fmt.Fprintln(w, "\nThis is a reference outlining what CI pipelines we generate under different conditions.")
|
||||
fmt.Fprintln(w, "\nTo preview the pipeline for your branch, use `sg ci preview`.")
|
||||
@ -117,7 +135,7 @@ func renderPipelineDocs(w io.Writer) {
|
||||
Diff: diff,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("Generating pipeline for diff %q: %s", diff, err)
|
||||
logger.Fatal("generating pipeline for diff", log.Error(err), log.Uint32("diff", uint32(diff)))
|
||||
}
|
||||
fmt.Fprintf(w, "\n- Pipeline for `%s` changes:\n", diff)
|
||||
for _, raw := range pipeline.Steps {
|
||||
@ -190,7 +208,7 @@ func renderPipelineDocs(w io.Writer) {
|
||||
Version: "v1.1.1",
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("Generating pipeline for RunType %q: %s", rt.String(), err)
|
||||
logger.Fatal("generating pipeline for RunType", log.String("runType", rt.String()), log.Error(err))
|
||||
}
|
||||
fmt.Fprint(w, "\nBase pipeline (more steps might be included based on branch changes):\n\n")
|
||||
for _, raw := range pipeline.Steps {
|
||||
|
||||
4
go.mod
4
go.mod
@ -141,7 +141,7 @@ require (
|
||||
github.com/sourcegraph/go-lsp v0.0.0-20200429204803-219e11d77f5d
|
||||
github.com/sourcegraph/go-rendezvous v0.0.0-20210910070954-ef39ade5591d
|
||||
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf
|
||||
github.com/sourcegraph/log v0.0.0-20220707160925-6a936691c838
|
||||
github.com/sourcegraph/log v0.0.0-20220822162457-5c757f638021
|
||||
github.com/sourcegraph/run v0.9.0
|
||||
github.com/sourcegraph/scip v0.1.0
|
||||
github.com/sourcegraph/sourcegraph/enterprise/dev/ci/images v0.0.0-20220203145655-4d2a39d3038a
|
||||
@ -174,7 +174,7 @@ require (
|
||||
go.uber.org/atomic v1.9.0
|
||||
go.uber.org/automaxprocs v1.5.1
|
||||
go.uber.org/ratelimit v0.2.0
|
||||
go.uber.org/zap v1.21.0
|
||||
go.uber.org/zap v1.22.0
|
||||
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167
|
||||
golang.org/x/net v0.0.0-20220526153639-5463443f8c37
|
||||
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
|
||||
|
||||
9
go.sum
9
go.sum
@ -2062,8 +2062,8 @@ github.com/sourcegraph/httpgzip v0.0.0-20211015085752-0bad89b3b4df h1:VaS8k40GiN
|
||||
github.com/sourcegraph/httpgzip v0.0.0-20211015085752-0bad89b3b4df/go.mod h1:RqWagzxNGCvucQQC9vX6aps474LCCOgshDpUTTyb+O8=
|
||||
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf h1:oAdWFqhStsWiiMP/vkkHiMXqFXzl1XfUNOdxKJbd6bI=
|
||||
github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf/go.mod h1:ppFaPm6kpcHnZGqQTFhUIAQRIEhdQDWP1PCv4/ON354=
|
||||
github.com/sourcegraph/log v0.0.0-20220707160925-6a936691c838 h1:8wknDSCUVYbaRT63OD+Iyv+stwze5kE2FAzbA1HrNMA=
|
||||
github.com/sourcegraph/log v0.0.0-20220707160925-6a936691c838/go.mod h1:zWEPlKrWBUVpko/tOgDS+qrp7BmzaCcmUrh9+ver1iQ=
|
||||
github.com/sourcegraph/log v0.0.0-20220822162457-5c757f638021 h1:IngqLdQQ/n42AbcQqayqJeEdPg2tOwbleeIZtZEriBo=
|
||||
github.com/sourcegraph/log v0.0.0-20220822162457-5c757f638021/go.mod h1:UxiwB6C3xk3xOySJpW1R0MDUyfGuJRFS5Z8C+SA5p2I=
|
||||
github.com/sourcegraph/oauth2 v0.0.0-20210825125341-77c1d99ece3c h1:HGa4iJr6MGKnB5qbU7tI511NdGuHUHnNCqP67G6KmfE=
|
||||
github.com/sourcegraph/oauth2 v0.0.0-20210825125341-77c1d99ece3c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
||||
github.com/sourcegraph/run v0.9.0 h1:mj4pwBqCB+5qEaTp+rhauh5ubYI8n/icOkeiLTCT9Xg=
|
||||
@ -2373,7 +2373,6 @@ go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/automaxprocs v1.5.1 h1:e1YG66Lrk73dn4qhg8WFSvhF0JuFQF0ERIp4rpuV8Qk=
|
||||
go.uber.org/automaxprocs v1.5.1/go.mod h1:BF4eumQw0P9GtnuxxovUd06vwm1o18oMzFtK66vU6XU=
|
||||
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||
@ -2388,8 +2387,8 @@ go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
||||
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
|
||||
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
|
||||
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
|
||||
go.uber.org/zap v1.22.0 h1:Zcye5DUgBloQ9BaT4qc9BnjOFog5TvBSAGkJ3Nf70c0=
|
||||
go.uber.org/zap v1.22.0/go.mod h1:H4siCOZOrAolnUPJEkfaSjDqyP+BDS0DdDWzwcgt3+U=
|
||||
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
|
||||
gocloud.dev v0.19.0/go.mod h1:SmKwiR8YwIMMJvQBKLsC3fHNyMwXLw3PMDO+VVteJMI=
|
||||
golang.org/x/build v0.0.0-20190314133821-5284462c4bec/go.mod h1:atTaCNAy0f16Ah5aV1gMSwgiKVHwu/JncqDpuRr7lS4=
|
||||
|
||||
@ -1,20 +1,25 @@
|
||||
package conf
|
||||
|
||||
import "github.com/sourcegraph/log"
|
||||
import (
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/sourcegraph/log"
|
||||
)
|
||||
|
||||
func GetLogSinks() log.SinksConfig {
|
||||
cfg := Get()
|
||||
|
||||
var sentry *log.SentrySink
|
||||
var sentrySink *log.SentrySink
|
||||
if cfg.Log != nil {
|
||||
if sk := cfg.Log.Sentry; sk != nil {
|
||||
sentry = &log.SentrySink{
|
||||
DSN: sk.BackendDSN,
|
||||
sentrySink = &log.SentrySink{
|
||||
ClientOptions: sentry.ClientOptions{
|
||||
Dsn: sk.BackendDSN,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return log.SinksConfig{
|
||||
Sentry: sentry,
|
||||
Sentry: sentrySink,
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user