diff --git a/go.mod b/go.mod index 313f42cb..5a16216c 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require github.com/auth0/go-jwt-middleware/v2 v2.2.2 require ( github.com/MicahParks/keyfunc/v3 v3.3.5 - github.com/getsentry/sentry-go v0.29.1 + github.com/getsentry/sentry-go v0.31.1 github.com/gin-gonic/gin v1.9.1 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/lib/pq v1.10.9 diff --git a/go.sum b/go.sum index 12da4957..aedef12d 100644 --- a/go.sum +++ b/go.sum @@ -28,8 +28,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= -github.com/getsentry/sentry-go v0.29.1 h1:DyZuChN8Hz3ARxGVV8ePaNXh1dQ7d76AiB117xcREwA= -github.com/getsentry/sentry-go v0.29.1/go.mod h1:x3AtIzN01d6SiWkderzaH28Tm0lgkafpJ5Bm3li39O0= +github.com/getsentry/sentry-go v0.31.1 h1:ELVc0h7gwyhnXHDouXkhqTFSO5oslsRDk0++eyE0KJ4= +github.com/getsentry/sentry-go v0.31.1/go.mod h1:CYNcMMz73YigoHljQRG+qPF+eMq8gG72XcGN/p71BAY= github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= @@ -161,6 +161,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2 github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= diff --git a/vendor/github.com/getsentry/sentry-go/.craft.yml b/vendor/github.com/getsentry/sentry-go/.craft.yml index 238288e4..5786bba2 100644 --- a/vendor/github.com/getsentry/sentry-go/.craft.yml +++ b/vendor/github.com/getsentry/sentry-go/.craft.yml @@ -8,6 +8,33 @@ targets: - name: github tagPrefix: otel/v tagOnly: true + - name: github + tagPrefix: echo/v + tagOnly: true + - name: github + tagPrefix: fasthttp/v + tagOnly: true + - name: github + tagPrefix: fiber/v + tagOnly: true + - name: github + tagPrefix: gin/v + tagOnly: true + - name: github + tagPrefix: iris/v + tagOnly: true + - name: github + tagPrefix: negroni/v + tagOnly: true + - name: github + tagPrefix: logrus/v + tagOnly: true + - name: github + tagPrefix: slog/v + tagOnly: true + - name: github + tagPrefix: zerolog/v + tagOnly: true - name: registry sdks: github:getsentry/sentry-go: diff --git a/vendor/github.com/getsentry/sentry-go/CHANGELOG.md b/vendor/github.com/getsentry/sentry-go/CHANGELOG.md index 4818085c..94a99acd 100644 --- a/vendor/github.com/getsentry/sentry-go/CHANGELOG.md +++ b/vendor/github.com/getsentry/sentry-go/CHANGELOG.md @@ -1,5 +1,88 @@ # Changelog +## 0.31.1 + +The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.31.1. + +### Bug Fixes + +- Correct wrong module name for `sentry-go/logrus` ([#950](https://github.com/getsentry/sentry-go/pull/950)) + +## 0.31.0 + +The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.31.0. + +### Breaking Changes + +- Remove support for metrics. Read more about the end of the Metrics beta [here](https://sentry.zendesk.com/hc/en-us/articles/26369339769883-Metrics-Beta-Ended-on-October-7th). ([#914](https://github.com/getsentry/sentry-go/pull/914)) + +- Remove support for profiling. ([#915](https://github.com/getsentry/sentry-go/pull/915)) + +- Remove `Segment` field from the `User` struct. This field is no longer used in the Sentry product. ([#928](https://github.com/getsentry/sentry-go/pull/928)) + +- Every integration is now a separate module, reducing the binary size and number of dependencies. Once you update `sentry-go` to latest version, you'll need to `go get` the integration you want to use. For example, if you want to use the `echo` integration, you'll need to run `go get github.com/getsentry/sentry-go/echo` ([#919](github.com/getsentry/sentry-go/pull/919)). + +### Features + +Add the ability to override `hub` in `context` for integrations that use custom context. ([#931](https://github.com/getsentry/sentry-go/pull/931)) + +- Add `HubProvider` Hook for `sentrylogrus`, enabling dynamic Sentry hub allocation for each log entry or goroutine. ([#936](https://github.com/getsentry/sentry-go/pull/936)) + +This change enhances compatibility with Sentry's recommendation of using separate hubs per goroutine. To ensure a separate Sentry hub for each goroutine, configure the `HubProvider` like this: + +```go +hook, err := sentrylogrus.New(nil, sentry.ClientOptions{}) +if err != nil { + log.Fatalf("Failed to initialize Sentry hook: %v", err) +} + +// Set a custom HubProvider to generate a new hub for each goroutine or log entry +hook.SetHubProvider(func() *sentry.Hub { + client, _ := sentry.NewClient(sentry.ClientOptions{}) + return sentry.NewHub(client, sentry.NewScope()) +}) + +logrus.AddHook(hook) +``` + +### Bug Fixes + +- Add support for closing worker goroutines started by the `HTTPTranport` to prevent goroutine leaks. ([#894](https://github.com/getsentry/sentry-go/pull/894)) + +```go +client, _ := sentry.NewClient() +defer client.Close() +``` + +Worker can be also closed by calling `Close()` method on the `HTTPTransport` instance. `Close` should be called after `Flush` and before terminating the program otherwise some events may be lost. + +```go +transport := sentry.NewHTTPTransport() +defer transport.Close() +``` + +### Misc + +- Bump [gin-gonic/gin](https://github.com/gin-gonic/gin) to v1.9.1. ([#946](https://github.com/getsentry/sentry-go/pull/946)) + +## 0.30.0 + +The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.30.0. + +### Features + +- Add `sentryzerolog` integration ([#857](https://github.com/getsentry/sentry-go/pull/857)) +- Add `sentryslog` integration ([#865](https://github.com/getsentry/sentry-go/pull/865)) +- Always set Mechanism Type to generic ([#896](https://github.com/getsentry/sentry-go/pull/897)) + +### Bug Fixes + +- Prevent panic in `fasthttp` and `fiber` integration in case a malformed URL has to be parsed ([#912](https://github.com/getsentry/sentry-go/pull/912)) + +### Misc + +Drop support for Go 1.18, 1.19 and 1.20. The currently supported Go versions are the last 3 stable releases: 1.23, 1.22 and 1.21. + ## 0.29.1 The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.29.1. @@ -9,6 +92,10 @@ The Sentry SDK team is happy to announce the immediate availability of Sentry Go - Correlate errors to the current trace ([#886](https://github.com/getsentry/sentry-go/pull/886)) - Set the trace context when the transaction finishes ([#888](https://github.com/getsentry/sentry-go/pull/888)) +### Misc + +- Update the `sentrynegroni` integration to use the latest (v3.1.1) version of Negroni ([#885](https://github.com/getsentry/sentry-go/pull/885)) + ## 0.29.0 The Sentry SDK team is happy to announce the immediate availability of Sentry Go SDK v0.29.0. diff --git a/vendor/github.com/getsentry/sentry-go/Makefile b/vendor/github.com/getsentry/sentry-go/Makefile index 89523ac0..9cc0959f 100644 --- a/vendor/github.com/getsentry/sentry-go/Makefile +++ b/vendor/github.com/getsentry/sentry-go/Makefile @@ -58,9 +58,8 @@ test-coverage: $(COVERAGE_REPORT_DIR) clean-report-dir ## Test with coverage en mod-tidy: ## Check go.mod tidiness set -e ; \ for dir in $(ALL_GO_MOD_DIRS); do \ - cd "$${dir}"; \ echo ">>> Running 'go mod tidy' for module: $${dir}"; \ - go mod tidy -go=1.18 -compat=1.18; \ + (cd "$${dir}" && go mod tidy -go=1.21 -compat=1.21); \ done; \ git diff --exit-code; .PHONY: mod-tidy @@ -68,12 +67,12 @@ mod-tidy: ## Check go.mod tidiness vet: ## Run "go vet" set -e ; \ for dir in $(ALL_GO_MOD_DIRS); do \ - cd "$${dir}"; \ echo ">>> Running 'go vet' for module: $${dir}"; \ - go vet ./...; \ + (cd "$${dir}" && go vet ./...); \ done; .PHONY: vet + lint: ## Lint (using "golangci-lint") golangci-lint run .PHONY: lint diff --git a/vendor/github.com/getsentry/sentry-go/README.md b/vendor/github.com/getsentry/sentry-go/README.md index 3b67fb45..59a989d8 100644 --- a/vendor/github.com/getsentry/sentry-go/README.md +++ b/vendor/github.com/getsentry/sentry-go/README.md @@ -10,7 +10,7 @@ # Official Sentry SDK for Go -[![Build Status](https://github.com/getsentry/sentry-go/workflows/go-workflow/badge.svg)](https://github.com/getsentry/sentry-go/actions?query=workflow%3Ago-workflow) +[![Build Status](https://github.com/getsentry/sentry-go/actions/workflows/test.yml/badge.svg)](https://github.com/getsentry/sentry-go/actions/workflows/test.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/getsentry/sentry-go)](https://goreportcard.com/report/github.com/getsentry/sentry-go) [![Discord](https://img.shields.io/discord/621778831602221064)](https://discord.gg/Ww9hbqr) [![go.dev](https://img.shields.io/badge/go.dev-pkg-007d9c.svg?style=flat)](https://pkg.go.dev/github.com/getsentry/sentry-go) @@ -68,16 +68,20 @@ To get started, have a look at one of our [examples](_examples/): We also provide a [complete API reference](https://pkg.go.dev/github.com/getsentry/sentry-go). For more detailed information about how to get the most out of `sentry-go`, -checkout the official documentation: +check out the official documentation: - [Sentry Go SDK documentation](https://docs.sentry.io/platforms/go/) - Guides: - [net/http](https://docs.sentry.io/platforms/go/guides/http/) - [echo](https://docs.sentry.io/platforms/go/guides/echo/) - [fasthttp](https://docs.sentry.io/platforms/go/guides/fasthttp/) + - [fiber](https://docs.sentry.io/platforms/go/guides/fiber/) - [gin](https://docs.sentry.io/platforms/go/guides/gin/) - [iris](https://docs.sentry.io/platforms/go/guides/iris/) + - [logrus](https://docs.sentry.io/platforms/go/guides/logrus/) - [negroni](https://docs.sentry.io/platforms/go/guides/negroni/) + - [slog](https://docs.sentry.io/platforms/go/guides/slog/) + - [zerolog](https://docs.sentry.io/platforms/go/guides/zerolog/) ## Resources diff --git a/vendor/github.com/getsentry/sentry-go/client.go b/vendor/github.com/getsentry/sentry-go/client.go index b5b11b31..0d086902 100644 --- a/vendor/github.com/getsentry/sentry-go/client.go +++ b/vendor/github.com/getsentry/sentry-go/client.go @@ -133,9 +133,6 @@ type ClientOptions struct { TracesSampleRate float64 // Used to customize the sampling of traces, overrides TracesSampleRate. TracesSampler TracesSampler - // The sample rate for profiling traces in the range [0.0, 1.0]. - // This is relative to TracesSampleRate - it is a ratio of profiled traces out of all sampled traces. - ProfilesSampleRate float64 // List of regexp strings that will be used to match against event's message // and if applicable, caught errors type and value. // If the match is found, then a whole event will be dropped. @@ -513,6 +510,14 @@ func (client *Client) Flush(timeout time.Duration) bool { return client.Transport.Flush(timeout) } +// Close clean up underlying Transport resources. +// +// Close should be called after Flush and before terminating the program +// otherwise some events may be lost. +func (client *Client) Close() { + client.Transport.Close() +} + // EventFromMessage creates an event from the given message string. func (client *Client) EventFromMessage(message string, level Level) *Event { if message == "" { @@ -590,14 +595,6 @@ func (client *Client) GetSDKIdentifier() string { return client.sdkIdentifier } -// reverse reverses the slice a in place. -func reverse(a []Exception) { - for i := len(a)/2 - 1; i >= 0; i-- { - opp := len(a) - 1 - i - a[i], a[opp] = a[opp], a[i] - } -} - func (client *Client) processEvent(event *Event, hint *EventHint, scope EventModifier) *EventID { if event == nil { err := usageError{fmt.Errorf("%s called with nil event", callerFunctionName())} @@ -709,10 +706,6 @@ func (client *Client) prepareEvent(event *Event, hint *EventHint, scope EventMod } } - if event.sdkMetaData.transactionProfile != nil { - event.sdkMetaData.transactionProfile.UpdateFromEvent(event) - } - return event } diff --git a/vendor/github.com/getsentry/sentry-go/dsn.go b/vendor/github.com/getsentry/sentry-go/dsn.go index ac6991a4..36b9925a 100644 --- a/vendor/github.com/getsentry/sentry-go/dsn.go +++ b/vendor/github.com/getsentry/sentry-go/dsn.go @@ -89,8 +89,8 @@ func NewDsn(rawURL string) (*Dsn, error) { // Port var port int - if parsedURL.Port() != "" { - port, err = strconv.Atoi(parsedURL.Port()) + if p := parsedURL.Port(); p != "" { + port, err = strconv.Atoi(p) if err != nil { return nil, &DsnParseError{"invalid port"} } diff --git a/vendor/github.com/getsentry/sentry-go/dynamic_sampling_context.go b/vendor/github.com/getsentry/sentry-go/dynamic_sampling_context.go index 6eec95ba..8dae0838 100644 --- a/vendor/github.com/getsentry/sentry-go/dynamic_sampling_context.go +++ b/vendor/github.com/getsentry/sentry-go/dynamic_sampling_context.go @@ -100,15 +100,17 @@ func (d DynamicSamplingContext) String() string { } members = append(members, member) } - if len(members) > 0 { - baggage, err := baggage.New(members...) - if err != nil { - return "" - } - return baggage.String() + + if len(members) == 0 { + return "" + } + + baggage, err := baggage.New(members...) + if err != nil { + return "" } - return "" + return baggage.String() } // Constructs a new DynamicSamplingContext using a scope and client. Accessing diff --git a/vendor/github.com/getsentry/sentry-go/http/sentryhttp.go b/vendor/github.com/getsentry/sentry-go/http/sentryhttp.go index 1bb8819d..c63f8547 100644 --- a/vendor/github.com/getsentry/sentry-go/http/sentryhttp.go +++ b/vendor/github.com/getsentry/sentry-go/http/sentryhttp.go @@ -53,13 +53,13 @@ type Options struct { // New returns a new Handler. Use the Handle and HandleFunc methods to wrap // existing HTTP handlers. func New(options Options) *Handler { - timeout := options.Timeout - if timeout == 0 { - timeout = 2 * time.Second + if options.Timeout == 0 { + options.Timeout = 2 * time.Second } + return &Handler{ repanic: options.Repanic, - timeout: timeout, + timeout: options.Timeout, waitForDelivery: options.WaitForDelivery, } } diff --git a/vendor/github.com/getsentry/sentry-go/hub.go b/vendor/github.com/getsentry/sentry-go/hub.go index c99b6d70..04cebee3 100644 --- a/vendor/github.com/getsentry/sentry-go/hub.go +++ b/vendor/github.com/getsentry/sentry-go/hub.go @@ -294,8 +294,13 @@ func (hub *Hub) AddBreadcrumb(breadcrumb *Breadcrumb, hint *BreadcrumbHint) { } max := client.options.MaxBreadcrumbs - if max < 0 { + switch { + case max < 0: return + case max == 0: + max = defaultMaxBreadcrumbs + case max > maxBreadcrumbs: + max = maxBreadcrumbs } if client.options.BeforeBreadcrumb != nil { @@ -308,12 +313,6 @@ func (hub *Hub) AddBreadcrumb(breadcrumb *Breadcrumb, hint *BreadcrumbHint) { } } - if max == 0 { - max = defaultMaxBreadcrumbs - } else if max > maxBreadcrumbs { - max = maxBreadcrumbs - } - hub.Scope().AddBreadcrumb(breadcrumb, max) } diff --git a/vendor/github.com/getsentry/sentry-go/interfaces.go b/vendor/github.com/getsentry/sentry-go/interfaces.go index cacb2543..c6461f1f 100644 --- a/vendor/github.com/getsentry/sentry-go/interfaces.go +++ b/vendor/github.com/getsentry/sentry-go/interfaces.go @@ -8,6 +8,7 @@ import ( "net" "net/http" "reflect" + "slices" "strings" "time" ) @@ -18,16 +19,9 @@ const eventType = "event" // transactionType is the type of a transaction event. const transactionType = "transaction" -// profileType is the type of a profile event. -// currently, profiles are always sent as part of a transaction event. -const profileType = "profile" - // checkInType is the type of a check in event. const checkInType = "check_in" -// metricType is the type of a metric event. -const metricType = "statsd" - // Level marks the severity of the event. type Level string @@ -118,32 +112,27 @@ type User struct { IPAddress string `json:"ip_address,omitempty"` Username string `json:"username,omitempty"` Name string `json:"name,omitempty"` - Segment string `json:"segment,omitempty"` Data map[string]string `json:"data,omitempty"` } func (u User) IsEmpty() bool { - if len(u.ID) > 0 { + if u.ID != "" { return false } - if len(u.Email) > 0 { + if u.Email != "" { return false } - if len(u.IPAddress) > 0 { + if u.IPAddress != "" { return false } - if len(u.Username) > 0 { + if u.Username != "" { return false } - if len(u.Name) > 0 { - return false - } - - if len(u.Segment) > 0 { + if u.Name != "" { return false } @@ -195,6 +184,7 @@ func NewRequest(r *http.Request) *Request { // attach more than one Cookie header field. cookies = r.Header.Get("Cookie") + headers = make(map[string]string, len(r.Header)) for k, v := range r.Header { headers[k] = strings.Join(v, ",") } @@ -238,8 +228,7 @@ type Mechanism struct { // SetUnhandled indicates that the exception is an unhandled exception, i.e. // from a panic. func (m *Mechanism) SetUnhandled() { - h := false - m.Handled = &h + m.Handled = Pointer(false) } // Exception specifies an error that occurred. @@ -255,8 +244,7 @@ type Exception struct { // SDKMetaData is a struct to stash data which is needed at some point in the SDK's event processing pipeline // but which shouldn't get send to Sentry. type SDKMetaData struct { - dsc DynamicSamplingContext - transactionProfile *profileInfo + dsc DynamicSamplingContext } // Contains information about how the name of the transaction was determined. @@ -324,7 +312,6 @@ type Event struct { Exception []Exception `json:"exception,omitempty"` DebugMeta *DebugMeta `json:"debug_meta,omitempty"` Attachments []*Attachment `json:"-"` - Metrics []Metric `json:"-"` // The fields below are only relevant for transactions. @@ -398,12 +385,13 @@ func (e *Event) SetException(exception error, maxErrorDepth int) { } // event.Exception should be sorted such that the most recent error is last. - reverse(e.Exception) + slices.Reverse(e.Exception) for i := range e.Exception { e.Exception[i].Mechanism = &Mechanism{ IsExceptionGroup: true, ExceptionID: i, + Type: "generic", } if i == 0 { continue @@ -429,7 +417,9 @@ func (e *Event) MarshalJSON() ([]byte, error) { // and a few type tricks. if e.Type == transactionType { return e.transactionMarshalJSON() - } else if e.Type == checkInType { + } + + if e.Type == checkInType { return e.checkInMarshalJSON() } return e.defaultMarshalJSON() diff --git a/vendor/github.com/getsentry/sentry-go/internal/traceparser/README.md b/vendor/github.com/getsentry/sentry-go/internal/traceparser/README.md deleted file mode 100644 index 78964587..00000000 --- a/vendor/github.com/getsentry/sentry-go/internal/traceparser/README.md +++ /dev/null @@ -1,15 +0,0 @@ -## Benchmark results - -``` -goos: windows -goarch: amd64 -pkg: github.com/getsentry/sentry-go/internal/trace -cpu: 12th Gen Intel(R) Core(TM) i7-12700K -BenchmarkEqualBytes-20 44323621 26.08 ns/op -BenchmarkStringEqual-20 60980257 18.27 ns/op -BenchmarkEqualPrefix-20 41369181 31.12 ns/op -BenchmarkFullParse-20 702012 1507 ns/op 1353.42 MB/s 1024 B/op 6 allocs/op -BenchmarkFramesIterator-20 1229971 969.3 ns/op 896 B/op 5 allocs/op -BenchmarkFramesReversedIterator-20 1271061 944.5 ns/op 896 B/op 5 allocs/op -BenchmarkSplitOnly-20 2250800 534.0 ns/op 3818.23 MB/s 128 B/op 1 allocs/op -``` diff --git a/vendor/github.com/getsentry/sentry-go/internal/traceparser/parser.go b/vendor/github.com/getsentry/sentry-go/internal/traceparser/parser.go deleted file mode 100644 index 8a7aab32..00000000 --- a/vendor/github.com/getsentry/sentry-go/internal/traceparser/parser.go +++ /dev/null @@ -1,217 +0,0 @@ -package traceparser - -import ( - "bytes" - "strconv" -) - -var blockSeparator = []byte("\n\n") -var lineSeparator = []byte("\n") - -// Parses multi-stacktrace text dump produced by runtime.Stack([]byte, all=true). -// The parser prioritizes performance but requires the input to be well-formed in order to return correct data. -// See https://github.com/golang/go/blob/go1.20.4/src/runtime/mprof.go#L1191 -func Parse(data []byte) TraceCollection { - var it = TraceCollection{} - if len(data) > 0 { - it.blocks = bytes.Split(data, blockSeparator) - } - return it -} - -type TraceCollection struct { - blocks [][]byte -} - -func (it TraceCollection) Length() int { - return len(it.blocks) -} - -// Returns the stacktrace item at the given index. -func (it *TraceCollection) Item(i int) Trace { - // The first item may have a leading data separator and the last one may have a trailing one. - // Note: Trim() doesn't make a copy for single-character cutset under 0x80. It will just slice the original. - var data []byte - switch { - case i == 0: - data = bytes.TrimLeft(it.blocks[i], "\n") - case i == len(it.blocks)-1: - data = bytes.TrimRight(it.blocks[i], "\n") - default: - data = it.blocks[i] - } - - var splitAt = bytes.IndexByte(data, '\n') - if splitAt < 0 { - return Trace{header: data} - } - - return Trace{ - header: data[:splitAt], - data: data[splitAt+1:], - } -} - -// Trace represents a single stacktrace block, identified by a Goroutine ID and a sequence of Frames. -type Trace struct { - header []byte - data []byte -} - -var goroutinePrefix = []byte("goroutine ") - -// GoID parses the Goroutine ID from the header. -func (t *Trace) GoID() (id uint64) { - if bytes.HasPrefix(t.header, goroutinePrefix) { - var line = t.header[len(goroutinePrefix):] - var splitAt = bytes.IndexByte(line, ' ') - if splitAt >= 0 { - id, _ = strconv.ParseUint(string(line[:splitAt]), 10, 64) - } - } - return id -} - -// UniqueIdentifier can be used as a map key to identify the trace. -func (t *Trace) UniqueIdentifier() []byte { - return t.data -} - -func (t *Trace) Frames() FrameIterator { - var lines = bytes.Split(t.data, lineSeparator) - return FrameIterator{lines: lines, i: 0, len: len(lines)} -} - -func (t *Trace) FramesReversed() ReverseFrameIterator { - var lines = bytes.Split(t.data, lineSeparator) - return ReverseFrameIterator{lines: lines, i: len(lines)} -} - -const framesElided = "...additional frames elided..." - -// FrameIterator iterates over stack frames. -type FrameIterator struct { - lines [][]byte - i int - len int -} - -// Next returns the next frame, or nil if there are none. -func (it *FrameIterator) Next() Frame { - return Frame{it.popLine(), it.popLine()} -} - -func (it *FrameIterator) popLine() []byte { - switch { - case it.i >= it.len: - return nil - case string(it.lines[it.i]) == framesElided: - it.i++ - return it.popLine() - default: - it.i++ - return it.lines[it.i-1] - } -} - -// HasNext return true if there are values to be read. -func (it *FrameIterator) HasNext() bool { - return it.i < it.len -} - -// LengthUpperBound returns the maximum number of elements this stacks may contain. -// The actual number may be lower because of elided frames. As such, the returned value -// cannot be used to iterate over the frames but may be used to reserve capacity. -func (it *FrameIterator) LengthUpperBound() int { - return it.len / 2 -} - -// ReverseFrameIterator iterates over stack frames in reverse order. -type ReverseFrameIterator struct { - lines [][]byte - i int -} - -// Next returns the next frame, or nil if there are none. -func (it *ReverseFrameIterator) Next() Frame { - var line2 = it.popLine() - return Frame{it.popLine(), line2} -} - -func (it *ReverseFrameIterator) popLine() []byte { - it.i-- - switch { - case it.i < 0: - return nil - case string(it.lines[it.i]) == framesElided: - return it.popLine() - default: - return it.lines[it.i] - } -} - -// HasNext return true if there are values to be read. -func (it *ReverseFrameIterator) HasNext() bool { - return it.i > 1 -} - -// LengthUpperBound returns the maximum number of elements this stacks may contain. -// The actual number may be lower because of elided frames. As such, the returned value -// cannot be used to iterate over the frames but may be used to reserve capacity. -func (it *ReverseFrameIterator) LengthUpperBound() int { - return len(it.lines) / 2 -} - -type Frame struct { - line1 []byte - line2 []byte -} - -// UniqueIdentifier can be used as a map key to identify the frame. -func (f *Frame) UniqueIdentifier() []byte { - // line2 contains file path, line number and program-counter offset from the beginning of a function - // e.g. C:/Users/name/scoop/apps/go/current/src/testing/testing.go:1906 +0x63a - return f.line2 -} - -var createdByPrefix = []byte("created by ") - -func (f *Frame) Func() []byte { - if bytes.HasPrefix(f.line1, createdByPrefix) { - // Since go1.21, the line ends with " in goroutine X", saying which goroutine created this one. - // We currently don't have use for that so just remove it. - var line = f.line1[len(createdByPrefix):] - var spaceAt = bytes.IndexByte(line, ' ') - if spaceAt < 0 { - return line - } - return line[:spaceAt] - } - - var end = bytes.LastIndexByte(f.line1, '(') - if end >= 0 { - return f.line1[:end] - } - - return f.line1 -} - -func (f *Frame) File() (path []byte, lineNumber int) { - var line = f.line2 - if len(line) > 0 && line[0] == '\t' { - line = line[1:] - } - - var splitAt = bytes.IndexByte(line, ' ') - if splitAt >= 0 { - line = line[:splitAt] - } - - splitAt = bytes.LastIndexByte(line, ':') - if splitAt < 0 { - return line, 0 - } - - lineNumber, _ = strconv.Atoi(string(line[splitAt+1:])) - return line[:splitAt], lineNumber -} diff --git a/vendor/github.com/getsentry/sentry-go/metrics.go b/vendor/github.com/getsentry/sentry-go/metrics.go deleted file mode 100644 index bcc94e88..00000000 --- a/vendor/github.com/getsentry/sentry-go/metrics.go +++ /dev/null @@ -1,427 +0,0 @@ -package sentry - -import ( - "fmt" - "hash/crc32" - "math" - "regexp" - "sort" - "strings" -) - -type ( - NumberOrString interface { - int | string - } - - void struct{} -) - -var ( - member void - keyRegex = regexp.MustCompile(`[^a-zA-Z0-9_/.-]+`) - valueRegex = regexp.MustCompile(`[^\w\d\s_:/@\.{}\[\]$-]+`) - unitRegex = regexp.MustCompile(`[^a-z]+`) -) - -type MetricUnit struct { - unit string -} - -func (m MetricUnit) toString() string { - return m.unit -} - -func NanoSecond() MetricUnit { - return MetricUnit{ - "nanosecond", - } -} - -func MicroSecond() MetricUnit { - return MetricUnit{ - "microsecond", - } -} - -func MilliSecond() MetricUnit { - return MetricUnit{ - "millisecond", - } -} - -func Second() MetricUnit { - return MetricUnit{ - "second", - } -} - -func Minute() MetricUnit { - return MetricUnit{ - "minute", - } -} - -func Hour() MetricUnit { - return MetricUnit{ - "hour", - } -} - -func Day() MetricUnit { - return MetricUnit{ - "day", - } -} - -func Week() MetricUnit { - return MetricUnit{ - "week", - } -} - -func Bit() MetricUnit { - return MetricUnit{ - "bit", - } -} - -func Byte() MetricUnit { - return MetricUnit{ - "byte", - } -} - -func KiloByte() MetricUnit { - return MetricUnit{ - "kilobyte", - } -} - -func KibiByte() MetricUnit { - return MetricUnit{ - "kibibyte", - } -} - -func MegaByte() MetricUnit { - return MetricUnit{ - "megabyte", - } -} - -func MebiByte() MetricUnit { - return MetricUnit{ - "mebibyte", - } -} - -func GigaByte() MetricUnit { - return MetricUnit{ - "gigabyte", - } -} - -func GibiByte() MetricUnit { - return MetricUnit{ - "gibibyte", - } -} - -func TeraByte() MetricUnit { - return MetricUnit{ - "terabyte", - } -} - -func TebiByte() MetricUnit { - return MetricUnit{ - "tebibyte", - } -} - -func PetaByte() MetricUnit { - return MetricUnit{ - "petabyte", - } -} - -func PebiByte() MetricUnit { - return MetricUnit{ - "pebibyte", - } -} - -func ExaByte() MetricUnit { - return MetricUnit{ - "exabyte", - } -} - -func ExbiByte() MetricUnit { - return MetricUnit{ - "exbibyte", - } -} - -func Ratio() MetricUnit { - return MetricUnit{ - "ratio", - } -} - -func Percent() MetricUnit { - return MetricUnit{ - "percent", - } -} - -func CustomUnit(unit string) MetricUnit { - return MetricUnit{ - unitRegex.ReplaceAllString(unit, ""), - } -} - -type Metric interface { - GetType() string - GetTags() map[string]string - GetKey() string - GetUnit() string - GetTimestamp() int64 - SerializeValue() string - SerializeTags() string -} - -type abstractMetric struct { - key string - unit MetricUnit - tags map[string]string - // A unix timestamp (full seconds elapsed since 1970-01-01 00:00 UTC). - timestamp int64 -} - -func (am abstractMetric) GetTags() map[string]string { - return am.tags -} - -func (am abstractMetric) GetKey() string { - return am.key -} - -func (am abstractMetric) GetUnit() string { - return am.unit.toString() -} - -func (am abstractMetric) GetTimestamp() int64 { - return am.timestamp -} - -func (am abstractMetric) SerializeTags() string { - var sb strings.Builder - - values := make([]string, 0, len(am.tags)) - for k := range am.tags { - values = append(values, k) - } - sortSlice(values) - - for _, key := range values { - val := sanitizeValue(am.tags[key]) - key = sanitizeKey(key) - sb.WriteString(fmt.Sprintf("%s:%s,", key, val)) - } - s := sb.String() - if len(s) > 0 { - s = s[:len(s)-1] - } - return s -} - -// Counter Metric. -type CounterMetric struct { - value float64 - abstractMetric -} - -func (c *CounterMetric) Add(value float64) { - c.value += value -} - -func (c CounterMetric) GetType() string { - return "c" -} - -func (c CounterMetric) SerializeValue() string { - return fmt.Sprintf(":%v", c.value) -} - -// timestamp: A unix timestamp (full seconds elapsed since 1970-01-01 00:00 UTC). -func NewCounterMetric(key string, unit MetricUnit, tags map[string]string, timestamp int64, value float64) CounterMetric { - am := abstractMetric{ - key, - unit, - tags, - timestamp, - } - - return CounterMetric{ - value, - am, - } -} - -// Distribution Metric. -type DistributionMetric struct { - values []float64 - abstractMetric -} - -func (d *DistributionMetric) Add(value float64) { - d.values = append(d.values, value) -} - -func (d DistributionMetric) GetType() string { - return "d" -} - -func (d DistributionMetric) SerializeValue() string { - var sb strings.Builder - for _, el := range d.values { - sb.WriteString(fmt.Sprintf(":%v", el)) - } - return sb.String() -} - -// timestamp: A unix timestamp (full seconds elapsed since 1970-01-01 00:00 UTC). -func NewDistributionMetric(key string, unit MetricUnit, tags map[string]string, timestamp int64, value float64) DistributionMetric { - am := abstractMetric{ - key, - unit, - tags, - timestamp, - } - - return DistributionMetric{ - []float64{value}, - am, - } -} - -// Gauge Metric. -type GaugeMetric struct { - last float64 - min float64 - max float64 - sum float64 - count float64 - abstractMetric -} - -func (g *GaugeMetric) Add(value float64) { - g.last = value - g.min = math.Min(g.min, value) - g.max = math.Max(g.max, value) - g.sum += value - g.count++ -} - -func (g GaugeMetric) GetType() string { - return "g" -} - -func (g GaugeMetric) SerializeValue() string { - return fmt.Sprintf(":%v:%v:%v:%v:%v", g.last, g.min, g.max, g.sum, g.count) -} - -// timestamp: A unix timestamp (full seconds elapsed since 1970-01-01 00:00 UTC). -func NewGaugeMetric(key string, unit MetricUnit, tags map[string]string, timestamp int64, value float64) GaugeMetric { - am := abstractMetric{ - key, - unit, - tags, - timestamp, - } - - return GaugeMetric{ - value, // last - value, // min - value, // max - value, // sum - value, // count - am, - } -} - -// Set Metric. -type SetMetric[T NumberOrString] struct { - values map[T]void - abstractMetric -} - -func (s *SetMetric[T]) Add(value T) { - s.values[value] = member -} - -func (s SetMetric[T]) GetType() string { - return "s" -} - -func (s SetMetric[T]) SerializeValue() string { - _hash := func(s string) uint32 { - return crc32.ChecksumIEEE([]byte(s)) - } - - values := make([]T, 0, len(s.values)) - for k := range s.values { - values = append(values, k) - } - sortSlice(values) - - var sb strings.Builder - for _, el := range values { - switch any(el).(type) { - case int: - sb.WriteString(fmt.Sprintf(":%v", el)) - case string: - s := fmt.Sprintf("%v", el) - sb.WriteString(fmt.Sprintf(":%d", _hash(s))) - } - } - - return sb.String() -} - -// timestamp: A unix timestamp (full seconds elapsed since 1970-01-01 00:00 UTC). -func NewSetMetric[T NumberOrString](key string, unit MetricUnit, tags map[string]string, timestamp int64, value T) SetMetric[T] { - am := abstractMetric{ - key, - unit, - tags, - timestamp, - } - - return SetMetric[T]{ - map[T]void{ - value: member, - }, - am, - } -} - -func sanitizeKey(s string) string { - return keyRegex.ReplaceAllString(s, "_") -} - -func sanitizeValue(s string) string { - return valueRegex.ReplaceAllString(s, "") -} - -type Ordered interface { - ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string -} - -func sortSlice[T Ordered](s []T) { - sort.Slice(s, func(i, j int) bool { - return s[i] < s[j] - }) -} diff --git a/vendor/github.com/getsentry/sentry-go/profile_sample.go b/vendor/github.com/getsentry/sentry-go/profile_sample.go deleted file mode 100644 index 65059872..00000000 --- a/vendor/github.com/getsentry/sentry-go/profile_sample.go +++ /dev/null @@ -1,73 +0,0 @@ -package sentry - -// Based on https://github.com/getsentry/vroom/blob/d11c26063e802d66b9a592c4010261746ca3dfa4/internal/sample/sample.go - -import ( - "time" -) - -type ( - profileDevice struct { - Architecture string `json:"architecture"` - Classification string `json:"classification"` - Locale string `json:"locale"` - Manufacturer string `json:"manufacturer"` - Model string `json:"model"` - } - - profileOS struct { - BuildNumber string `json:"build_number"` - Name string `json:"name"` - Version string `json:"version"` - } - - profileRuntime struct { - Name string `json:"name"` - Version string `json:"version"` - } - - profileSample struct { - ElapsedSinceStartNS uint64 `json:"elapsed_since_start_ns"` - StackID int `json:"stack_id"` - ThreadID uint64 `json:"thread_id"` - } - - profileThreadMetadata struct { - Name string `json:"name,omitempty"` - Priority int `json:"priority,omitempty"` - } - - profileStack []int - - profileTrace struct { - Frames []*Frame `json:"frames"` - Samples []profileSample `json:"samples"` - Stacks []profileStack `json:"stacks"` - ThreadMetadata map[uint64]*profileThreadMetadata `json:"thread_metadata"` - } - - profileInfo struct { - DebugMeta *DebugMeta `json:"debug_meta,omitempty"` - Device profileDevice `json:"device"` - Environment string `json:"environment,omitempty"` - EventID string `json:"event_id"` - OS profileOS `json:"os"` - Platform string `json:"platform"` - Release string `json:"release"` - Dist string `json:"dist"` - Runtime profileRuntime `json:"runtime"` - Timestamp time.Time `json:"timestamp"` - Trace *profileTrace `json:"profile"` - Transaction profileTransaction `json:"transaction"` - Version string `json:"version"` - } - - // see https://github.com/getsentry/vroom/blob/a91e39416723ec44fc54010257020eeaf9a77cbd/internal/transaction/transaction.go - profileTransaction struct { - ActiveThreadID uint64 `json:"active_thread_id"` - DurationNS uint64 `json:"duration_ns,omitempty"` - ID EventID `json:"id"` - Name string `json:"name"` - TraceID string `json:"trace_id"` - } -) diff --git a/vendor/github.com/getsentry/sentry-go/profiler.go b/vendor/github.com/getsentry/sentry-go/profiler.go deleted file mode 100644 index c0b858cc..00000000 --- a/vendor/github.com/getsentry/sentry-go/profiler.go +++ /dev/null @@ -1,451 +0,0 @@ -package sentry - -import ( - "container/ring" - "strconv" - - "runtime" - "sync" - "sync/atomic" - "time" - - "github.com/getsentry/sentry-go/internal/traceparser" -) - -// Start a profiler that collects samples continuously, with a buffer of up to 30 seconds. -// Later, you can collect a slice from this buffer, producing a Trace. -func startProfiling(startTime time.Time) profiler { - onProfilerStart() - - p := newProfiler(startTime) - - // Wait for the profiler to finish setting up before returning to the caller. - started := make(chan struct{}) - go p.run(started) - - if _, ok := <-started; ok { - return p - } - return nil -} - -type profiler interface { - // GetSlice returns a slice of the profiled data between the given times. - GetSlice(startTime, endTime time.Time) *profilerResult - Stop(wait bool) -} - -type profilerResult struct { - callerGoID uint64 - trace *profileTrace -} - -func getCurrentGoID() uint64 { - // We shouldn't panic but let's be super safe. - defer func() { - if err := recover(); err != nil { - Logger.Printf("Profiler panic in getCurrentGoID(): %v\n", err) - } - }() - - // Buffer to read the stack trace into. We should be good with a small buffer because we only need the first line. - var stacksBuffer = make([]byte, 100) - var n = runtime.Stack(stacksBuffer, false) - if n > 0 { - var traces = traceparser.Parse(stacksBuffer[0:n]) - if traces.Length() > 0 { - var trace = traces.Item(0) - return trace.GoID() - } - } - return 0 -} - -const profilerSamplingRateHz = 101 // 101 Hz; not 100 Hz because of the lockstep sampling (https://stackoverflow.com/a/45471031/1181370) -const profilerSamplingRate = time.Second / profilerSamplingRateHz -const stackBufferMaxGrowth = 512 * 1024 -const stackBufferLimit = 10 * 1024 * 1024 -const profilerRuntimeLimit = 30 // seconds - -type profileRecorder struct { - startTime time.Time - stopSignal chan struct{} - stopped int64 - mutex sync.RWMutex - testProfilerPanic int64 - - // Map from runtime.StackRecord.Stack0 to an index in stacks. - stackIndexes map[string]int - stacks []profileStack - newStacks []profileStack // New stacks created in the current interation. - stackKeyBuffer []byte - - // Map from runtime.Frame.PC to an index in frames. - frameIndexes map[string]int - frames []*Frame - newFrames []*Frame // New frames created in the current interation. - - // We keep a ring buffer of 30 seconds worth of samples, so that we can later slice it. - // Each bucket is a slice of samples all taken at the same time. - samplesBucketsHead *ring.Ring - - // Buffer to read current stacks - will grow automatically up to stackBufferLimit. - stacksBuffer []byte -} - -func newProfiler(startTime time.Time) *profileRecorder { - // Pre-allocate the profile trace for the currently active number of routines & 100 ms worth of samples. - // Other coefficients are just guesses of what might be a good starting point to avoid allocs on short runs. - return &profileRecorder{ - startTime: startTime, - stopSignal: make(chan struct{}, 1), - - stackIndexes: make(map[string]int, 32), - stacks: make([]profileStack, 0, 32), - newStacks: make([]profileStack, 0, 32), - - frameIndexes: make(map[string]int, 128), - frames: make([]*Frame, 0, 128), - newFrames: make([]*Frame, 0, 128), - - samplesBucketsHead: ring.New(profilerRuntimeLimit * profilerSamplingRateHz), - - // A buffer of 2 KiB per goroutine stack looks like a good starting point (empirically determined). - stacksBuffer: make([]byte, runtime.NumGoroutine()*2048), - } -} - -// This allows us to test whether panic during profiling are handled correctly and don't block execution. -// If the number is lower than 0, profilerGoroutine() will panic immedately. -// If the number is higher than 0, profiler.onTick() will panic when the given samples-set index is being collected. -var testProfilerPanic int64 -var profilerRunning int64 - -func (p *profileRecorder) run(started chan struct{}) { - // Code backup for manual test debugging: - // if !atomic.CompareAndSwapInt64(&profilerRunning, 0, 1) { - // panic("Only one profiler can be running at a time") - // } - - // We shouldn't panic but let's be super safe. - defer func() { - if err := recover(); err != nil { - Logger.Printf("Profiler panic in run(): %v\n", err) - } - atomic.StoreInt64(&testProfilerPanic, 0) - close(started) - p.stopSignal <- struct{}{} - atomic.StoreInt64(&p.stopped, 1) - atomic.StoreInt64(&profilerRunning, 0) - }() - - p.testProfilerPanic = atomic.LoadInt64(&testProfilerPanic) - if p.testProfilerPanic < 0 { - Logger.Printf("Profiler panicking during startup because testProfilerPanic == %v\n", p.testProfilerPanic) - panic("This is an expected panic in profilerGoroutine() during tests") - } - - // Collect the first sample immediately. - p.onTick() - - // Periodically collect stacks, starting after profilerSamplingRate has passed. - collectTicker := profilerTickerFactory(profilerSamplingRate) - defer collectTicker.Stop() - var tickerChannel = collectTicker.TickSource() - - started <- struct{}{} - - for { - select { - case <-tickerChannel: - p.onTick() - collectTicker.Ticked() - case <-p.stopSignal: - return - } - } -} - -func (p *profileRecorder) Stop(wait bool) { - if atomic.LoadInt64(&p.stopped) == 1 { - return - } - p.stopSignal <- struct{}{} - if wait { - <-p.stopSignal - } -} - -func (p *profileRecorder) GetSlice(startTime, endTime time.Time) *profilerResult { - // Unlikely edge cases - profiler wasn't running at all or the given times are invalid in relation to each other. - if p.startTime.After(endTime) || startTime.After(endTime) { - return nil - } - - var relativeStartNS = uint64(0) - if p.startTime.Before(startTime) { - relativeStartNS = uint64(startTime.Sub(p.startTime).Nanoseconds()) - } - var relativeEndNS = uint64(endTime.Sub(p.startTime).Nanoseconds()) - - samplesCount, bucketsReversed, trace := p.getBuckets(relativeStartNS, relativeEndNS) - if samplesCount == 0 { - return nil - } - - var result = &profilerResult{ - callerGoID: getCurrentGoID(), - trace: trace, - } - - trace.Samples = make([]profileSample, samplesCount) - trace.ThreadMetadata = make(map[uint64]*profileThreadMetadata, len(bucketsReversed[0].goIDs)) - var s = samplesCount - 1 - for _, bucket := range bucketsReversed { - var elapsedSinceStartNS = bucket.relativeTimeNS - relativeStartNS - for i, goID := range bucket.goIDs { - trace.Samples[s].ElapsedSinceStartNS = elapsedSinceStartNS - trace.Samples[s].ThreadID = goID - trace.Samples[s].StackID = bucket.stackIDs[i] - s-- - - if _, goroutineExists := trace.ThreadMetadata[goID]; !goroutineExists { - trace.ThreadMetadata[goID] = &profileThreadMetadata{ - Name: "Goroutine " + strconv.FormatUint(goID, 10), - } - } - } - } - - return result -} - -// Collect all buckets of samples in the given time range while holding a read lock. -func (p *profileRecorder) getBuckets(relativeStartNS, relativeEndNS uint64) (samplesCount int, buckets []*profileSamplesBucket, trace *profileTrace) { - p.mutex.RLock() - defer p.mutex.RUnlock() - - // sampleBucketsHead points at the last stored bucket so it's a good starting point to search backwards for the end. - var end = p.samplesBucketsHead - for end.Value != nil && end.Value.(*profileSamplesBucket).relativeTimeNS > relativeEndNS { - end = end.Prev() - } - - // Edge case - no items stored before the given endTime. - if end.Value == nil { - return 0, nil, nil - } - - { // Find the first item after the given startTime. - var start = end - var prevBucket *profileSamplesBucket - samplesCount = 0 - buckets = make([]*profileSamplesBucket, 0, int64((relativeEndNS-relativeStartNS)/uint64(profilerSamplingRate.Nanoseconds()))+1) - for start.Value != nil { - var bucket = start.Value.(*profileSamplesBucket) - - // If this bucket's time is before the requests start time, don't collect it (and stop iterating further). - if bucket.relativeTimeNS < relativeStartNS { - break - } - - // If this bucket time is greater than previous the bucket's time, we have exhausted the whole ring buffer - // before we were able to find the start time. That means the start time is not present and we must break. - // This happens if the slice duration exceeds the ring buffer capacity. - if prevBucket != nil && bucket.relativeTimeNS > prevBucket.relativeTimeNS { - break - } - - samplesCount += len(bucket.goIDs) - buckets = append(buckets, bucket) - - start = start.Prev() - prevBucket = bucket - } - } - - // Edge case - if the period requested was too short and we haven't collected enough samples. - if len(buckets) < 2 { - return 0, nil, nil - } - - trace = &profileTrace{ - Frames: p.frames, - Stacks: p.stacks, - } - return samplesCount, buckets, trace -} - -func (p *profileRecorder) onTick() { - elapsedNs := time.Since(p.startTime).Nanoseconds() - - if p.testProfilerPanic > 0 { - Logger.Printf("Profiler testProfilerPanic == %v\n", p.testProfilerPanic) - if p.testProfilerPanic == 1 { - Logger.Println("Profiler panicking onTick()") - panic("This is an expected panic in Profiler.OnTick() during tests") - } - p.testProfilerPanic-- - } - - records := p.collectRecords() - p.processRecords(uint64(elapsedNs), records) - - // Free up some memory if we don't need such a large buffer anymore. - if len(p.stacksBuffer) > len(records)*3 { - p.stacksBuffer = make([]byte, len(records)*3) - } -} - -func (p *profileRecorder) collectRecords() []byte { - for { - // Capture stacks for all existing goroutines. - // Note: runtime.GoroutineProfile() would be better but we can't use it at the moment because - // it doesn't give us `gid` for each routine, see https://github.com/golang/go/issues/59663 - n := runtime.Stack(p.stacksBuffer, true) - - // If we couldn't read everything, increase the buffer and try again. - if n >= len(p.stacksBuffer) && n < stackBufferLimit { - var newSize = n * 2 - if newSize > n+stackBufferMaxGrowth { - newSize = n + stackBufferMaxGrowth - } - if newSize > stackBufferLimit { - newSize = stackBufferLimit - } - p.stacksBuffer = make([]byte, newSize) - } else { - return p.stacksBuffer[0:n] - } - } -} - -func (p *profileRecorder) processRecords(elapsedNs uint64, stacksBuffer []byte) { - var traces = traceparser.Parse(stacksBuffer) - var length = traces.Length() - - // Shouldn't happen but let's be safe and don't store empty buckets. - if length == 0 { - return - } - - var bucket = &profileSamplesBucket{ - relativeTimeNS: elapsedNs, - stackIDs: make([]int, length), - goIDs: make([]uint64, length), - } - - // reset buffers - p.newFrames = p.newFrames[:0] - p.newStacks = p.newStacks[:0] - - for i := 0; i < length; i++ { - var stack = traces.Item(i) - bucket.stackIDs[i] = p.addStackTrace(stack) - bucket.goIDs[i] = stack.GoID() - } - - p.mutex.Lock() - defer p.mutex.Unlock() - - p.stacks = append(p.stacks, p.newStacks...) - p.frames = append(p.frames, p.newFrames...) - - p.samplesBucketsHead = p.samplesBucketsHead.Next() - p.samplesBucketsHead.Value = bucket -} - -func (p *profileRecorder) addStackTrace(capturedStack traceparser.Trace) int { - iter := capturedStack.Frames() - stack := make(profileStack, 0, iter.LengthUpperBound()) - - // Originally, we've used `capturedStack.UniqueIdentifier()` as a key but that was incorrect because it also - // contains function arguments and we want to group stacks by function name and file/line only. - // Instead, we need to parse frames and we use a list of their indexes as a key. - // We reuse the same buffer for each stack to avoid allocations; this is a hot spot. - var expectedBufferLen = cap(stack) * 5 // 4 bytes per frame + 1 byte for space - if cap(p.stackKeyBuffer) < expectedBufferLen { - p.stackKeyBuffer = make([]byte, 0, expectedBufferLen) - } else { - p.stackKeyBuffer = p.stackKeyBuffer[:0] - } - - for iter.HasNext() { - var frame = iter.Next() - if frameIndex := p.addFrame(frame); frameIndex >= 0 { - stack = append(stack, frameIndex) - - p.stackKeyBuffer = append(p.stackKeyBuffer, 0) // space - - // The following code is just like binary.AppendUvarint() which isn't yet available in Go 1.18. - x := uint64(frameIndex) + 1 - for x >= 0x80 { - p.stackKeyBuffer = append(p.stackKeyBuffer, byte(x)|0x80) - x >>= 7 - } - p.stackKeyBuffer = append(p.stackKeyBuffer, byte(x)) - } - } - - stackIndex, exists := p.stackIndexes[string(p.stackKeyBuffer)] - if !exists { - stackIndex = len(p.stacks) + len(p.newStacks) - p.newStacks = append(p.newStacks, stack) - p.stackIndexes[string(p.stackKeyBuffer)] = stackIndex - } - - return stackIndex -} - -func (p *profileRecorder) addFrame(capturedFrame traceparser.Frame) int { - // NOTE: Don't convert to string yet, it's expensive and compiler can avoid it when - // indexing into a map (only needs a copy when adding a new key to the map). - var key = capturedFrame.UniqueIdentifier() - - frameIndex, exists := p.frameIndexes[string(key)] - if !exists { - module, function := splitQualifiedFunctionName(string(capturedFrame.Func())) - file, line := capturedFrame.File() - frame := newFrame(module, function, string(file), line) - frameIndex = len(p.frames) + len(p.newFrames) - p.newFrames = append(p.newFrames, &frame) - p.frameIndexes[string(key)] = frameIndex - } - return frameIndex -} - -type profileSamplesBucket struct { - relativeTimeNS uint64 - stackIDs []int - goIDs []uint64 -} - -// A Ticker holds a channel that delivers “ticks” of a clock at intervals. -type profilerTicker interface { - // Stop turns off a ticker. After Stop, no more ticks will be sent. - Stop() - - // TickSource returns a read-only channel of ticks. - TickSource() <-chan time.Time - - // Ticked is called by the Profiler after a tick is processed to notify the ticker. Used for testing. - Ticked() -} - -type timeTicker struct { - *time.Ticker -} - -func (t *timeTicker) TickSource() <-chan time.Time { - return t.C -} - -func (t *timeTicker) Ticked() {} - -func profilerTickerFactoryDefault(d time.Duration) profilerTicker { - return &timeTicker{time.NewTicker(d)} -} - -// We allow overriding the ticker for tests. CI is terribly flaky -// because the time.Ticker doesn't guarantee regular ticks - they may come (a lot) later than the given interval. -var profilerTickerFactory = profilerTickerFactoryDefault diff --git a/vendor/github.com/getsentry/sentry-go/profiler_other.go b/vendor/github.com/getsentry/sentry-go/profiler_other.go deleted file mode 100644 index fbb79b0c..00000000 --- a/vendor/github.com/getsentry/sentry-go/profiler_other.go +++ /dev/null @@ -1,5 +0,0 @@ -//go:build !windows - -package sentry - -func onProfilerStart() {} diff --git a/vendor/github.com/getsentry/sentry-go/profiler_windows.go b/vendor/github.com/getsentry/sentry-go/profiler_windows.go deleted file mode 100644 index 33279824..00000000 --- a/vendor/github.com/getsentry/sentry-go/profiler_windows.go +++ /dev/null @@ -1,24 +0,0 @@ -package sentry - -import ( - "sync" - "syscall" -) - -// This works around the ticker resolution on Windows being ~15ms by default. -// See https://github.com/golang/go/issues/44343 -func setTimeTickerResolution() { - var winmmDLL = syscall.NewLazyDLL("winmm.dll") - if winmmDLL != nil { - var timeBeginPeriod = winmmDLL.NewProc("timeBeginPeriod") - if timeBeginPeriod != nil { - timeBeginPeriod.Call(uintptr(1)) - } - } -} - -var setupTickerResolutionOnce sync.Once - -func onProfilerStart() { - setupTickerResolutionOnce.Do(setTimeTickerResolution) -} diff --git a/vendor/github.com/getsentry/sentry-go/scope.go b/vendor/github.com/getsentry/sentry-go/scope.go index 5be1c02e..8245fdbd 100644 --- a/vendor/github.com/getsentry/sentry-go/scope.go +++ b/vendor/github.com/getsentry/sentry-go/scope.go @@ -478,7 +478,7 @@ func (scope *Scope) ApplyToEvent(event *Event, hint *EventHint, client *Client) // a proper deep copy: if some context values are pointer types (e.g. maps), // they won't be properly copied. func cloneContext(c Context) Context { - res := Context{} + res := make(Context, len(c)) for k, v := range c { res[k] = v } diff --git a/vendor/github.com/getsentry/sentry-go/sentry.go b/vendor/github.com/getsentry/sentry-go/sentry.go index 476eb178..7f2fe05f 100644 --- a/vendor/github.com/getsentry/sentry-go/sentry.go +++ b/vendor/github.com/getsentry/sentry-go/sentry.go @@ -6,7 +6,7 @@ import ( ) // The version of the SDK. -const SDKVersion = "0.29.1" +const SDKVersion = "0.31.1" // apiVersion is the minimum version of the Sentry API compatible with the // sentry-go SDK. diff --git a/vendor/github.com/getsentry/sentry-go/stacktrace.go b/vendor/github.com/getsentry/sentry-go/stacktrace.go index 3b372bcf..f59e2366 100644 --- a/vendor/github.com/getsentry/sentry-go/stacktrace.go +++ b/vendor/github.com/getsentry/sentry-go/stacktrace.go @@ -4,6 +4,7 @@ import ( "go/build" "reflect" "runtime" + "slices" "strings" ) @@ -277,12 +278,7 @@ func extractFrames(pcs []uintptr) []runtime.Frame { } } - // TODO don't append and reverse, put in the right place from the start. - // reverse - for i, j := 0, len(frames)-1; i < j; i, j = i+1, j-1 { - frames[i], frames[j] = frames[j], frames[i] - } - + slices.Reverse(frames) return frames } @@ -336,12 +332,10 @@ func shouldSkipFrame(module string) bool { var goRoot = strings.ReplaceAll(build.Default.GOROOT, "\\", "/") func setInAppFrame(frame *Frame) { - if strings.HasPrefix(frame.AbsPath, goRoot) || - strings.Contains(frame.Module, "vendor") || + frame.InApp = true + if strings.HasPrefix(frame.AbsPath, goRoot) || strings.Contains(frame.Module, "vendor") || strings.Contains(frame.Module, "third_party") { frame.InApp = false - } else { - frame.InApp = true } } @@ -382,3 +376,32 @@ func baseName(name string) string { } return name } + +func isCompilerGeneratedSymbol(name string) bool { + // In versions of Go 1.20 and above a prefix of "type:" and "go:" is a + // compiler-generated symbol that doesn't belong to any package. + // See variable reservedimports in cmd/compile/internal/gc/subr.go + if strings.HasPrefix(name, "go:") || strings.HasPrefix(name, "type:") { + return true + } + return false +} + +// Walk backwards through the results and for the current function name +// remove it's parent function's prefix, leaving only it's actual name. This +// fixes issues grouping errors with the new fully qualified function names +// introduced from Go 1.21. +func cleanupFunctionNamePrefix(f []Frame) []Frame { + for i := len(f) - 1; i > 0; i-- { + name := f[i].Function + parentName := f[i-1].Function + "." + + if !strings.HasPrefix(name, parentName) { + continue + } + + f[i].Function = name[len(parentName):] + } + + return f +} diff --git a/vendor/github.com/getsentry/sentry-go/stacktrace_below_go1.20.go b/vendor/github.com/getsentry/sentry-go/stacktrace_below_go1.20.go deleted file mode 100644 index f6fb8e1e..00000000 --- a/vendor/github.com/getsentry/sentry-go/stacktrace_below_go1.20.go +++ /dev/null @@ -1,15 +0,0 @@ -//go:build !go1.20 - -package sentry - -import "strings" - -func isCompilerGeneratedSymbol(name string) bool { - // In versions of Go below 1.20 a prefix of "type." and "go." is a - // compiler-generated symbol that doesn't belong to any package. - // See variable reservedimports in cmd/compile/internal/gc/subr.go - if strings.HasPrefix(name, "go.") || strings.HasPrefix(name, "type.") { - return true - } - return false -} diff --git a/vendor/github.com/getsentry/sentry-go/stacktrace_below_go1.21.go b/vendor/github.com/getsentry/sentry-go/stacktrace_below_go1.21.go deleted file mode 100644 index 35a42e4d..00000000 --- a/vendor/github.com/getsentry/sentry-go/stacktrace_below_go1.21.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build !go1.21 - -package sentry - -func cleanupFunctionNamePrefix(f []Frame) []Frame { - return f -} diff --git a/vendor/github.com/getsentry/sentry-go/stacktrace_go1.20.go b/vendor/github.com/getsentry/sentry-go/stacktrace_go1.20.go deleted file mode 100644 index ff1cbf60..00000000 --- a/vendor/github.com/getsentry/sentry-go/stacktrace_go1.20.go +++ /dev/null @@ -1,15 +0,0 @@ -//go:build go1.20 - -package sentry - -import "strings" - -func isCompilerGeneratedSymbol(name string) bool { - // In versions of Go 1.20 and above a prefix of "type:" and "go:" is a - // compiler-generated symbol that doesn't belong to any package. - // See variable reservedimports in cmd/compile/internal/gc/subr.go - if strings.HasPrefix(name, "go:") || strings.HasPrefix(name, "type:") { - return true - } - return false -} diff --git a/vendor/github.com/getsentry/sentry-go/stacktrace_go1.21.go b/vendor/github.com/getsentry/sentry-go/stacktrace_go1.21.go deleted file mode 100644 index 45147c85..00000000 --- a/vendor/github.com/getsentry/sentry-go/stacktrace_go1.21.go +++ /dev/null @@ -1,25 +0,0 @@ -//go:build go1.21 - -package sentry - -import "strings" - -// Walk backwards through the results and for the current function name -// remove it's parent function's prefix, leaving only it's actual name. This -// fixes issues grouping errors with the new fully qualified function names -// introduced from Go 1.21. - -func cleanupFunctionNamePrefix(f []Frame) []Frame { - for i := len(f) - 1; i > 0; i-- { - name := f[i].Function - parentName := f[i-1].Function + "." - - if !strings.HasPrefix(name, parentName) { - continue - } - - f[i].Function = name[len(parentName):] - } - - return f -} diff --git a/vendor/github.com/getsentry/sentry-go/traces_profiler.go b/vendor/github.com/getsentry/sentry-go/traces_profiler.go deleted file mode 100644 index 23573421..00000000 --- a/vendor/github.com/getsentry/sentry-go/traces_profiler.go +++ /dev/null @@ -1,95 +0,0 @@ -package sentry - -import ( - "sync" - "time" -) - -// Checks whether the transaction should be profiled (according to ProfilesSampleRate) -// and starts a profiler if so. -func (s *Span) sampleTransactionProfile() { - var sampleRate = s.clientOptions().ProfilesSampleRate - switch { - case sampleRate < 0.0 || sampleRate > 1.0: - Logger.Printf("Skipping transaction profiling: ProfilesSampleRate out of range [0.0, 1.0]: %f\n", sampleRate) - case sampleRate == 0.0 || rng.Float64() >= sampleRate: - Logger.Printf("Skipping transaction profiling: ProfilesSampleRate is: %f\n", sampleRate) - default: - startProfilerOnce.Do(startGlobalProfiler) - if globalProfiler == nil { - Logger.Println("Skipping transaction profiling: the profiler couldn't be started") - } else { - s.collectProfile = collectTransactionProfile - } - } -} - -// transactionProfiler collects a profile for a given span. -type transactionProfiler func(span *Span) *profileInfo - -var startProfilerOnce sync.Once -var globalProfiler profiler - -func startGlobalProfiler() { - globalProfiler = startProfiling(time.Now()) -} - -func collectTransactionProfile(span *Span) *profileInfo { - result := globalProfiler.GetSlice(span.StartTime, span.EndTime) - if result == nil || result.trace == nil { - return nil - } - - info := &profileInfo{ - Version: "1", - EventID: uuid(), - // See https://github.com/getsentry/sentry-go/pull/626#discussion_r1204870340 for explanation why we use the Transaction time. - Timestamp: span.StartTime, - Trace: result.trace, - Transaction: profileTransaction{ - DurationNS: uint64(span.EndTime.Sub(span.StartTime).Nanoseconds()), - Name: span.Name, - TraceID: span.TraceID.String(), - }, - } - if len(info.Transaction.Name) == 0 { - // Name is required by Relay so use the operation name if the span name is empty. - info.Transaction.Name = span.Op - } - if result.callerGoID > 0 { - info.Transaction.ActiveThreadID = result.callerGoID - } - return info -} - -func (info *profileInfo) UpdateFromEvent(event *Event) { - info.Environment = event.Environment - info.Platform = event.Platform - info.Release = event.Release - info.Dist = event.Dist - info.Transaction.ID = event.EventID - - getStringFromContext := func(context map[string]interface{}, originalValue, key string) string { - v, ok := context[key] - if !ok { - return originalValue - } - - if s, ok := v.(string); ok { - return s - } - - return originalValue - } - - if runtimeContext, ok := event.Contexts["runtime"]; ok { - info.Runtime.Name = getStringFromContext(runtimeContext, info.Runtime.Name, "name") - info.Runtime.Version = getStringFromContext(runtimeContext, info.Runtime.Version, "version") - } - if osContext, ok := event.Contexts["os"]; ok { - info.OS.Name = getStringFromContext(osContext, info.OS.Name, "name") - } - if deviceContext, ok := event.Contexts["device"]; ok { - info.Device.Architecture = getStringFromContext(deviceContext, info.Device.Architecture, "arch") - } -} diff --git a/vendor/github.com/getsentry/sentry-go/tracing.go b/vendor/github.com/getsentry/sentry-go/tracing.go index b30ceb79..0c5877c5 100644 --- a/vendor/github.com/getsentry/sentry-go/tracing.go +++ b/vendor/github.com/getsentry/sentry-go/tracing.go @@ -68,8 +68,6 @@ type Span struct { //nolint: maligned // prefer readability over optimal memory recorder *spanRecorder // span context, can only be set on transactions contexts map[string]Context - // collectProfile is a function that collects a profile of the current transaction. May be nil. - collectProfile transactionProfiler // a Once instance to make sure that Finish() is only called once. finishOnce sync.Once } @@ -202,11 +200,6 @@ func StartSpan(ctx context.Context, operation string, options ...SpanOption) *Sp hub.Scope().SetSpan(&span) } - // Start profiling only if it's a sampled root transaction. - if span.IsTransaction() && span.Sampled.Bool() { - span.sampleTransactionProfile() - } - return &span } @@ -373,10 +366,6 @@ func (s *Span) doFinish() { return } - if s.collectProfile != nil { - event.sdkMetaData.transactionProfile = s.collectProfile(s) - } - // TODO(tracing): add breadcrumbs // (see https://github.com/getsentry/sentry-python/blob/f6f3525f8812f609/sentry_sdk/tracing.py#L372) @@ -735,31 +724,32 @@ const ( maxSpanStatus ) +var spanStatuses = [maxSpanStatus]string{ + "", + "ok", + "cancelled", // [sic] + "unknown", + "invalid_argument", + "deadline_exceeded", + "not_found", + "already_exists", + "permission_denied", + "resource_exhausted", + "failed_precondition", + "aborted", + "out_of_range", + "unimplemented", + "internal_error", + "unavailable", + "data_loss", + "unauthenticated", +} + func (ss SpanStatus) String() string { if ss >= maxSpanStatus { return "" } - m := [maxSpanStatus]string{ - "", - "ok", - "cancelled", // [sic] - "unknown", - "invalid_argument", - "deadline_exceeded", - "not_found", - "already_exists", - "permission_denied", - "resource_exhausted", - "failed_precondition", - "aborted", - "out_of_range", - "unimplemented", - "internal_error", - "unavailable", - "data_loss", - "unauthenticated", - } - return m[ss] + return spanStatuses[ss] } func (ss SpanStatus) MarshalJSON() ([]byte, error) { diff --git a/vendor/github.com/getsentry/sentry-go/transport.go b/vendor/github.com/getsentry/sentry-go/transport.go index 02fc1d4f..417252f8 100644 --- a/vendor/github.com/getsentry/sentry-go/transport.go +++ b/vendor/github.com/getsentry/sentry-go/transport.go @@ -35,6 +35,7 @@ type Transport interface { Flush(timeout time.Duration) bool Configure(options ClientOptions) SendEvent(event *Event) + Close() } func getProxyConfig(options ClientOptions) func(*http.Request) (*url.URL, error) { @@ -95,55 +96,6 @@ func getRequestBodyFromEvent(event *Event) []byte { return nil } -func marshalMetrics(metrics []Metric) []byte { - var b bytes.Buffer - for i, metric := range metrics { - b.WriteString(metric.GetKey()) - if unit := metric.GetUnit(); unit != "" { - b.WriteString(fmt.Sprintf("@%s", unit)) - } - b.WriteString(fmt.Sprintf("%s|%s", metric.SerializeValue(), metric.GetType())) - if serializedTags := metric.SerializeTags(); serializedTags != "" { - b.WriteString(fmt.Sprintf("|#%s", serializedTags)) - } - b.WriteString(fmt.Sprintf("|T%d", metric.GetTimestamp())) - - if i < len(metrics)-1 { - b.WriteString("\n") - } - } - return b.Bytes() -} - -func encodeMetric(enc *json.Encoder, b io.Writer, metrics []Metric) error { - body := marshalMetrics(metrics) - // Item header - err := enc.Encode(struct { - Type string `json:"type"` - Length int `json:"length"` - }{ - Type: metricType, - Length: len(body), - }) - if err != nil { - return err - } - - // metric payload - if _, err = b.Write(body); err != nil { - return err - } - - // "Envelopes should be terminated with a trailing newline." - // - // [1]: https://develop.sentry.dev/sdk/envelopes/#envelopes - if _, err := b.Write([]byte("\n")); err != nil { - return err - } - - return err -} - func encodeAttachment(enc *json.Encoder, b io.Writer, attachment *Attachment) error { // Attachment header err := enc.Encode(struct { @@ -228,8 +180,6 @@ func envelopeFromBody(event *Event, dsn *Dsn, sentAt time.Time, body json.RawMes switch event.Type { case transactionType, checkInType: err = encodeEnvelopeItem(enc, event.Type, body) - case metricType: - err = encodeMetric(enc, &b, event.Metrics) default: err = encodeEnvelopeItem(enc, eventType, body) } @@ -245,18 +195,6 @@ func envelopeFromBody(event *Event, dsn *Dsn, sentAt time.Time, body json.RawMes } } - // Profile data - if event.sdkMetaData.transactionProfile != nil { - body, err = json.Marshal(event.sdkMetaData.transactionProfile) - if err != nil { - return nil, err - } - err = encodeEnvelopeItem(enc, profileType, body) - if err != nil { - return nil, err - } - } - return &b, nil } @@ -279,10 +217,12 @@ func getRequestFromEvent(ctx context.Context, event *Event, dsn *Dsn) (r *http.R r.Header.Set("X-Sentry-Auth", auth) } }() + body := getRequestBodyFromEvent(event) if body == nil { return nil, errors.New("event could not be marshaled") } + envelope, err := envelopeFromBody(event, dsn, time.Now(), body) if err != nil { return nil, err @@ -350,6 +290,9 @@ type HTTPTransport struct { mu sync.RWMutex limits ratelimit.Map + + // receiving signal will terminate worker. + done chan struct{} } // NewHTTPTransport returns a new pre-configured instance of HTTPTransport. @@ -357,6 +300,7 @@ func NewHTTPTransport() *HTTPTransport { transport := HTTPTransport{ BufferSize: defaultBufferSize, Timeout: defaultTimeout, + done: make(chan struct{}), } return &transport } @@ -522,6 +466,15 @@ fail: return false } +// Close will terminate events sending loop. +// It useful to prevent goroutines leak in case of multiple HTTPTransport instances initiated. +// +// Close should be called after Flush and before terminating the program +// otherwise some events may be lost. +func (t *HTTPTransport) Close() { + close(t.done) +} + func (t *HTTPTransport) worker() { for b := range t.buffer { // Signal that processing of the current batch has started. @@ -532,35 +485,44 @@ func (t *HTTPTransport) worker() { t.buffer <- b // Process all batch items. - for item := range b.items { - if t.disabled(item.category) { - continue - } + loop: + for { + select { + case <-t.done: + return + case item, open := <-b.items: + if !open { + break loop + } + if t.disabled(item.category) { + continue + } - response, err := t.client.Do(item.request) - if err != nil { - Logger.Printf("There was an issue with sending an event: %v", err) - continue - } - if response.StatusCode >= 400 && response.StatusCode <= 599 { - b, err := io.ReadAll(response.Body) + response, err := t.client.Do(item.request) if err != nil { - Logger.Printf("Error while reading response code: %v", err) + Logger.Printf("There was an issue with sending an event: %v", err) + continue + } + if response.StatusCode >= 400 && response.StatusCode <= 599 { + b, err := io.ReadAll(response.Body) + if err != nil { + Logger.Printf("Error while reading response code: %v", err) + } + Logger.Printf("Sending %s failed with the following error: %s", eventType, string(b)) } - Logger.Printf("Sending %s failed with the following error: %s", eventType, string(b)) - } - t.mu.Lock() - if t.limits == nil { - t.limits = make(ratelimit.Map) - } - t.limits.Merge(ratelimit.FromResponse(response)) - t.mu.Unlock() + t.mu.Lock() + if t.limits == nil { + t.limits = make(ratelimit.Map) + } + t.limits.Merge(ratelimit.FromResponse(response)) + t.mu.Unlock() - // Drain body up to a limit and close it, allowing the - // transport to reuse TCP connections. - _, _ = io.CopyN(io.Discard, response.Body, maxDrainResponseBytes) - response.Body.Close() + // Drain body up to a limit and close it, allowing the + // transport to reuse TCP connections. + _, _ = io.CopyN(io.Discard, response.Body, maxDrainResponseBytes) + response.Body.Close() + } } // Signal that processing of the batch is done. @@ -648,6 +610,8 @@ func (t *HTTPSyncTransport) SendEvent(event *Event) { t.SendEventWithContext(context.Background(), event) } +func (t *HTTPSyncTransport) Close() {} + // SendEventWithContext assembles a new packet out of Event and sends it to the remote server. func (t *HTTPSyncTransport) SendEventWithContext(ctx context.Context, event *Event) { if t.dsn == nil { @@ -667,8 +631,6 @@ func (t *HTTPSyncTransport) SendEventWithContext(ctx context.Context, event *Eve switch { case event.Type == transactionType: eventType = "transaction" - case event.Type == metricType: - eventType = metricType default: eventType = fmt.Sprintf("%s event", event.Level) } @@ -743,3 +705,5 @@ func (noopTransport) SendEvent(*Event) { func (noopTransport) Flush(time.Duration) bool { return true } + +func (noopTransport) Close() {} diff --git a/vendor/modules.txt b/vendor/modules.txt index a09903ce..f9e5557c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -65,8 +65,8 @@ github.com/gabriel-vasile/mimetype github.com/gabriel-vasile/mimetype/internal/charset github.com/gabriel-vasile/mimetype/internal/json github.com/gabriel-vasile/mimetype/internal/magic -# github.com/getsentry/sentry-go v0.29.1 -## explicit; go 1.18 +# github.com/getsentry/sentry-go v0.31.1 +## explicit; go 1.21 github.com/getsentry/sentry-go github.com/getsentry/sentry-go/http github.com/getsentry/sentry-go/internal/debug @@ -74,7 +74,6 @@ github.com/getsentry/sentry-go/internal/httputils github.com/getsentry/sentry-go/internal/otel/baggage github.com/getsentry/sentry-go/internal/otel/baggage/internal/baggage github.com/getsentry/sentry-go/internal/ratelimit -github.com/getsentry/sentry-go/internal/traceparser github.com/getsentry/sentry-go/internal/traceutils # github.com/gin-contrib/sse v0.1.0 ## explicit; go 1.12