Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion _examples/logrus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func main() {
return event
},
// need to have logs enabled
EnableLogs: true,
Debug: true,
AttachStacktrace: true,
})
Expand Down
4 changes: 2 additions & 2 deletions _examples/logs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

func main() {
err := sentry.Init(sentry.ClientOptions{
Dsn: "",
EnableLogs: true, // you need to have EnableLogs set to true
Dsn: "",
// Logs are enabled by default. Set DisableLogs: true to disable.
})
if err != nil {
panic(err)
Expand Down
1 change: 0 additions & 1 deletion _examples/zap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func main() {
// Initialize Sentry with logs enabled
err := sentry.Init(sentry.ClientOptions{
Dsn: "your-sentry-dsn",
EnableLogs: true,
})
if err != nil {
panic(err)
Expand Down
7 changes: 4 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ type ClientOptions struct {
MaxErrorDepth int
// Default event tags. These are overridden by tags set on a scope.
Tags map[string]string
// EnableLogs controls when logs should be emitted.
EnableLogs bool
// DisableLogs controls whether logs should be emitted.
// By default, logs are enabled. Set to true to disable log emission.
DisableLogs bool
// DisableMetrics controls when metrics should be emitted.
DisableMetrics bool
// DisableClientReports controls when client reports should be emitted.
Expand Down Expand Up @@ -429,7 +430,7 @@ func NewClient(options ClientOptions) (*Client, error) {
}
client.setupTransport()

if options.EnableLogs {
if !options.DisableLogs {
client.batchLogger = newLogBatchProcessor(&client)
client.batchLogger.Start()
}
Expand Down
5 changes: 2 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,8 @@ func setupMultiClientEnv(t *testing.T) *multiClientEnv {
mkClient := func(dsn string) (*Client, *MockTransport) {
tr := &MockTransport{}
c, err := NewClient(ClientOptions{
Dsn: dsn,
Transport: tr,
EnableLogs: true,
Dsn: dsn,
Transport: tr,
Integrations: func(_ []Integration) []Integration {
return []Integration{}
},
Expand Down
1 change: 0 additions & 1 deletion crosstest/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func otelOpts() []sentrytest.Option {
sentrytest.WithClientOptions(sentry.ClientOptions{
EnableTracing: true,
TracesSampleRate: 1.0,
EnableLogs: true,
Integrations: func(integrations []sentry.Integration) []sentry.Integration {
return append(integrations, sentryotel.NewOtelIntegration())
},
Expand Down
4 changes: 2 additions & 2 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewLogger(ctx context.Context) Logger { // nolint: dupl
}

client := hub.Client()
if client != nil && client.options.EnableLogs {
if client != nil && !client.options.DisableLogs {
// Build default attrs
serverAddr := client.options.ServerName
if serverAddr == "" {
Expand Down Expand Up @@ -91,7 +91,7 @@ func NewLogger(ctx context.Context) Logger { // nolint: dupl
}
}

debuglog.Println("fallback to noopLogger: enableLogs disabled")
debuglog.Println("fallback to noopLogger: SDK not initialized or logs disabled")
return &noopLogger{}
}

Expand Down
1 change: 0 additions & 1 deletion log_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func TestSentryLogger_ShouldLinkToCorrectSpan(t *testing.T) {
Dsn: testDsn,
EnableTracing: true,
TracesSampleRate: 1.0,
EnableLogs: true,
Transport: transport,
})
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions log_fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (n *noopLogEntry) Attributes(_ ...attribute.Builder) LogEntry {
}

func (n *noopLogEntry) Emit(args ...interface{}) {
debuglog.Printf("Log with level=[%v] is being dropped. Turn on logging via EnableLogs", n.level)
debuglog.Printf("Log with level=[%v] is being dropped. SDK not initialized or logs disabled", n.level)
if n.level == LogLevelFatal {
if n.shouldPanic {
panic(args)
Expand All @@ -76,7 +76,7 @@ func (n *noopLogEntry) Emit(args ...interface{}) {
}

func (n *noopLogEntry) Emitf(message string, args ...interface{}) {
debuglog.Printf("Log with level=[%v] is being dropped. Turn on logging via EnableLogs", n.level)
debuglog.Printf("Log with level=[%v] is being dropped. SDK not initialized or logs disabled", n.level)
if n.level == LogLevelFatal {
if n.shouldPanic {
panic(fmt.Sprintf(message, args...))
Expand Down Expand Up @@ -122,9 +122,9 @@ func (*noopLogger) LFatal() LogEntry {
}

func (*noopLogger) SetAttributes(...attribute.Builder) {
debuglog.Printf("No attributes attached. Turn on logging via EnableLogs")
debuglog.Printf("No attributes attached. SDK not initialized or logs disabled")
}

func (*noopLogger) Write(_ []byte) (n int, err error) {
return 0, fmt.Errorf("log with level=[%v] is being dropped. Turn on logging via EnableLogs", LogLevelInfo)
return 0, fmt.Errorf("log with level=[%v] is being dropped. SDK not initialized or logs disabled", LogLevelInfo)
}
21 changes: 8 additions & 13 deletions log_race_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ func TestLoggingRaceConditions(t *testing.T) {

func testConcurrentLoggerSetAttributes(t *testing.T) {
client, _ := NewClient(ClientOptions{
Dsn: testDsn,
EnableLogs: true,
Transport: &MockTransport{},
Dsn: testDsn,
Transport: &MockTransport{},
})
hub := NewHub(client, NewScope())
ctx := SetHubOnContext(context.Background(), hub)
Expand Down Expand Up @@ -129,9 +128,8 @@ func testConcurrentLoggerSetAttributes(t *testing.T) {

func testConcurrentLogEmission(_ *testing.T) {
client, _ := NewClient(ClientOptions{
Dsn: testDsn,
EnableLogs: true,
Transport: &MockTransport{},
Dsn: testDsn,
Transport: &MockTransport{},
})
hub := NewHub(client, NewScope())
ctx := SetHubOnContext(context.Background(), hub)
Expand Down Expand Up @@ -208,9 +206,8 @@ func testConcurrentLogEntryOperations(t *testing.T) {
t.Skip("A single instance of a log entry should not be used concurrently")

client, _ := NewClient(ClientOptions{
Dsn: testDsn,
EnableLogs: true,
Transport: &MockTransport{},
Dsn: testDsn,
Transport: &MockTransport{},
})
hub := NewHub(client, NewScope())
ctx := SetHubOnContext(context.Background(), hub)
Expand Down Expand Up @@ -264,9 +261,8 @@ func testConcurrentLogEntryOperations(t *testing.T) {

func testConcurrentLoggerCreationAndUsage(_ *testing.T) {
client, _ := NewClient(ClientOptions{
Dsn: testDsn,
EnableLogs: true,
Transport: &MockTransport{},
Dsn: testDsn,
Transport: &MockTransport{},
})
hub := NewHub(client, NewScope())

Expand Down Expand Up @@ -316,7 +312,6 @@ func testConcurrentLoggerCreationAndUsage(_ *testing.T) {
func testConcurrentLogWithSpanOperations(_ *testing.T) {
client, _ := NewClient(ClientOptions{
Dsn: testDsn,
EnableLogs: true,
EnableTracing: true,
TracesSampleRate: 1.0,
Transport: &MockTransport{},
Expand Down
30 changes: 13 additions & 17 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func setupMockTransport() (context.Context, *MockTransport) {
Release: "v1.2.3",
Environment: "testing",
ServerName: "test-server",
EnableLogs: true,
EnableTracing: true,
})
mockClient.sdkIdentifier = "sentry.go"
Expand Down Expand Up @@ -626,7 +625,6 @@ func Test_batchLogger_Shutdown(t *testing.T) {
mockClient, _ := NewClient(ClientOptions{
Dsn: testDsn,
Transport: mockTransport,
EnableLogs: true,
DisableTelemetryBuffer: true,
})
hub := CurrentHub()
Expand Down Expand Up @@ -675,7 +673,6 @@ func Test_sentryLogger_BeforeSendLog(t *testing.T) {
Release: "v1.2.3",
Environment: "testing",
ServerName: "test-server",
EnableLogs: true,
EnableTracing: true,
BeforeSendLog: func(_ *Log) *Log {
return nil
Expand Down Expand Up @@ -750,19 +747,19 @@ func Test_sentryLogger_TracePropagationWithTransaction(t *testing.T) {

func TestSentryLogger_DebugLogging(t *testing.T) {
tests := []struct {
name string
enableLogs bool
message string
name string
disableLogs bool
message string
}{
{
name: "Debug enabled",
enableLogs: true,
message: "test message",
name: "Logs enabled (default)",
disableLogs: false,
message: "test message",
},
{
name: "Debug disabled",
enableLogs: false,
message: "test message",
name: "Logs disabled",
disableLogs: true,
message: "test message",
},
}

Expand All @@ -772,9 +769,9 @@ func TestSentryLogger_DebugLogging(t *testing.T) {

ctx := context.Background()
mockClient, _ := NewClient(ClientOptions{
Transport: &MockTransport{},
EnableLogs: tt.enableLogs,
Debug: true,
Transport: &MockTransport{},
DisableLogs: tt.disableLogs,
Debug: true,
})
hub := CurrentHub()
hub.BindClient(mockClient)
Expand All @@ -787,7 +784,7 @@ func TestSentryLogger_DebugLogging(t *testing.T) {
logger.Info().WithCtx(ctx).Emit(tt.message)

got := buf.String()
if tt.enableLogs {
if !tt.disableLogs {
assertEqual(t, strings.Contains(got, "test message"), true)
} else {
assertEqual(t, strings.Contains(got, "test message"), false)
Expand All @@ -805,7 +802,6 @@ func Test_sentryLogger_UserAttributes(t *testing.T) {
Release: "v1.2.3",
Environment: "testing",
ServerName: "test-server",
EnableLogs: true,
EnableTracing: true,
})
mockClient.sdkIdentifier = "sentry.go"
Expand Down
1 change: 0 additions & 1 deletion logrus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func main() {
return event
},
// need to have logs enabled
EnableLogs: true,
Debug: true,
AttachStacktrace: true,
})
Expand Down
4 changes: 2 additions & 2 deletions logrus/logrusentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ func (h *logHook) FlushWithContext(ctx context.Context) bool {
// NewLogHook initializes a new Logrus hook which sends logs to a new Sentry client
// configured according to opts.
func NewLogHook(levels []logrus.Level, opts sentry.ClientOptions) (Hook, error) {
if !opts.EnableLogs {
return nil, errors.New("cannot create log hook, EnableLogs is set to false")
if opts.DisableLogs {
return nil, errors.New("cannot create log hook, DisableLogs is set to true")
}
client, err := sentry.NewClient(opts)
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions logrus/logrusentry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
func setupClientTest() (*sentry.Client, *sentry.MockTransport) {
mockTransport := &sentry.MockTransport{}
mockClient, _ := sentry.NewClient(sentry.ClientOptions{
Dsn: "http://whatever@example.com/1337",
Transport: mockTransport,
EnableLogs: true,
Dsn: "http://whatever@example.com/1337",
Transport: mockTransport,
})
hub := sentry.CurrentHub()
hub.BindClient(mockClient)
Expand Down Expand Up @@ -511,7 +510,6 @@ func TestNewLogHook(t *testing.T) {
hook, err := NewLogHook(levels, sentry.ClientOptions{
Dsn: "http://whatever@example.com/1337",
Environment: "test",
EnableLogs: true,
})

assert.NoError(t, err)
Expand Down
1 change: 0 additions & 1 deletion slog/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func main() {
err := sentry.Init(sentry.ClientOptions{
Dsn: "your-public-dsn",
Debug: true,
EnableLogs: true,
})
if err != nil {
panic(err)
Expand Down
5 changes: 2 additions & 3 deletions slog/sentryslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ func newMockTransport() (context.Context, *sentry.MockTransport) {
ctx := context.Background()
mockTransport := &sentry.MockTransport{}
mockClient, _ := sentry.NewClient(sentry.ClientOptions{
Dsn: "https://public@example.com/1",
Transport: mockTransport,
EnableLogs: true,
Dsn: "https://public@example.com/1",
Transport: mockTransport,
})
hub := sentry.CurrentHub()
hub.BindClient(mockClient)
Expand Down
14 changes: 6 additions & 8 deletions zap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func main() {
// Initialize Sentry with logs enabled
err := sentry.Init(sentry.ClientOptions{
Dsn: "your-sentry-dsn",
EnableLogs: true,
})
if err != nil {
panic(err)
Expand Down Expand Up @@ -87,7 +86,6 @@ func main() {
// Initialize Sentry
sentry.Init(sentry.ClientOptions{
Dsn: "your-sentry-dsn",
EnableLogs: true,
})
defer sentry.Flush(2 * time.Second)

Expand Down Expand Up @@ -130,11 +128,11 @@ func main() {

### Option struct

| Field | Type | Description | Default |
|-------|------|-------------|---------|
| `Level` | `[]zapcore.Level` | Zap levels to capture and send to Sentry | All levels (Debug through Fatal) |
| `AddCaller` | `bool` | Include caller info (file, line, function) | `false` |
| `FlushTimeout` | `time.Duration` | How long to wait when syncing/flushing | 5 seconds |
| Field | Type | Description | Default |
| -------------- | ----------------- | ------------------------------------------ | -------------------------------- |
| `Level` | `[]zapcore.Level` | Zap levels to capture and send to Sentry | All levels (Debug through Fatal) |
| `AddCaller` | `bool` | Include caller info (file, line, function) | `false` |
| `FlushTimeout` | `time.Duration` | How long to wait when syncing/flushing | 5 seconds |

## Context and Tracing

Expand Down Expand Up @@ -182,5 +180,5 @@ scopedLogger.Info("Processing completed")
## Notes

- This integration only sends logs to Sentry (not events/errors). For error reporting, use the main `sentry-go` package.
- Ensure `EnableLogs: true` is set in your Sentry client options.
- Logs are enabled by default. If you have `DisableLogs: true`, remove it to enable log emission.
- Call `sentry.Flush()` before your application exits to ensure all logs are sent.
5 changes: 2 additions & 3 deletions zap/sentryzap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ func newMockTransport() (context.Context, *sentry.MockTransport) {
ctx := context.Background()
mockTransport := &sentry.MockTransport{}
mockClient, _ := sentry.NewClient(sentry.ClientOptions{
Dsn: "https://public@example.com/1",
Transport: mockTransport,
EnableLogs: true,
Dsn: "https://public@example.com/1",
Transport: mockTransport,
})
hub := sentry.CurrentHub()
hub.BindClient(mockClient)
Expand Down
Loading