Skip to content

Commit

Permalink
Merge branch 'master' into feat/sentrysql
Browse files Browse the repository at this point in the history
  • Loading branch information
aldy505 authored Nov 25, 2024
2 parents 38ba84c + 9b8b7be commit 31ef60f
Show file tree
Hide file tree
Showing 58 changed files with 2,711 additions and 340 deletions.
6 changes: 6 additions & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ targets:
- name: github
tagPrefix: otel/v
tagOnly: true
- name: github
tagPrefix: slog/v
tagOnly: true
- name: github
tagPrefix: zerolog/v
tagOnly: true
- name: registry
sdks:
github:getsentry/sentry-go:
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # [email protected]
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ jobs:
run: make vet
- name: Check go.mod Tidiness
run: make mod-tidy
if: ${{ matrix.go == '1.20' }}
if: ${{ matrix.go == '1.21' }}
- name: Test
run: make test-coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # pin@v4.6.0
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # pin@v5.0.2
with:
directory: .coverage
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -64,6 +64,6 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
go: ["1.23", "1.22", "1.21", "1.20", "1.19", "1.18"]
go: ["1.23", "1.22", "1.21"]
os: [ubuntu, windows, macos]
fail-fast: false
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Changelog

### 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))

### 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.
Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,21 @@ 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

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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ checkout the official documentation:
- [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/)

## Resources
Expand Down
38 changes: 38 additions & 0 deletions _examples/slog/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"
"log"
"time"

"log/slog"

"github.com/getsentry/sentry-go"
sentryslog "github.com/getsentry/sentry-go/slog"
)

func main() {
err := sentry.Init(sentry.ClientOptions{
Dsn: "https://[email protected]/4506954545758208",
EnableTracing: false,
})
if err != nil {
log.Fatal(err)
}

defer sentry.Flush(2 * time.Second)

logger := slog.New(sentryslog.Option{Level: slog.LevelDebug}.NewSentryHandler())
logger = logger.With("release", "v1.0.0")

logger.
With(
slog.Group("user",
slog.String("id", "user-123"),
slog.Time("created_at", time.Now()),
),
).
With("environment", "dev").
With("error", fmt.Errorf("an error")).
Error("a message")
}
49 changes: 49 additions & 0 deletions _examples/zerolog/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"github.com/getsentry/sentry-go"
sentryzerolog "github.com/getsentry/sentry-go/zerolog"
"github.com/rs/zerolog"
"os"
"time"
)

func main() {
w, err := sentryzerolog.New(sentryzerolog.Config{
Options: sentryzerolog.Options{
Levels: []zerolog.Level{
zerolog.DebugLevel,
zerolog.ErrorLevel,
zerolog.FatalLevel,
zerolog.PanicLevel,
},
WithBreadcrumbs: true,
FlushTimeout: 5 * time.Second,
},
ClientOptions: sentry.ClientOptions{
Dsn: "",
Environment: "development",
Release: "1.0",
Debug: true,
AttachStacktrace: true,
},
})

if err != nil {
panic(err)
}

defer func() {
err = w.Close()
if err != nil {
panic(err)
}
}()

m := zerolog.MultiLevelWriter(os.Stdout, w)
logger := zerolog.New(m).With().Timestamp().Logger()

logger.Debug().Msg("Application has started")
logger.Error().Msg("Oh no!")
logger.Fatal().Msg("Can't continue...")
}
8 changes: 0 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,14 +590,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())}
Expand Down
16 changes: 9 additions & 7 deletions dynamic_sampling_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/getsentry/sentry-go

go 1.18
go 1.21

require (
github.com/gin-gonic/gin v1.8.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.27.1 h1:rfztXRbg6nv/5f+Raen9RcGoSecHIFgBBLQK3Wdj754=
github.com/onsi/gomega v1.27.1/go.mod h1:aHX5xOykVYzWOV4WqQy0sy8BQptgukenXpCXfadcIAw=
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
Expand Down Expand Up @@ -226,6 +228,7 @@ github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FB
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
13 changes: 6 additions & 7 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down
3 changes: 2 additions & 1 deletion hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sentry
import (
"context"
"fmt"
"slices"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -400,7 +401,7 @@ func TestGetBaggage(t *testing.T) {
t.Run(name, func(t *testing.T) {
result := tt.hub.GetBaggage()
res := strings.Split(result, ",")
sortSlice(res)
slices.Sort(res)
assertEqual(t, strings.Join(res, ","), tt.expected)
})
}
Expand Down
22 changes: 12 additions & 10 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/http"
"reflect"
"slices"
"strings"
"time"
)
Expand Down Expand Up @@ -123,27 +124,27 @@ type User struct {
}

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 {
if u.Name != "" {
return false
}

if len(u.Segment) > 0 {
if u.Segment != "" {
return false
}

Expand Down Expand Up @@ -238,8 +239,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.
Expand Down Expand Up @@ -398,7 +398,7 @@ 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{
Expand Down Expand Up @@ -430,7 +430,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()
Expand Down
Loading

0 comments on commit 31ef60f

Please sign in to comment.