sentry

package module
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2025 License: BSD-2-Clause Imports: 10 Imported by: 35

README

Sentry

Go Reference CI Go Report Card

A Go library that provides an enhanced wrapper around the Sentry Go SDK with additional functionality for error exclusion, automatic tag enrichment, and context data extraction.

Features

  • Automatic Tag Enrichment: Extracts data from context and errors to add as Sentry tags
  • Error Filtering: Configurable error exclusion to prevent noise
  • Context Integration: Uses github.com/bborbe/errors for context data extraction
  • Proxy Support: HTTP transport wrapper for proxy configurations
  • Type-Safe Interface: Clean interface abstraction with mock generation support

Installation

go get github.com/bborbe/sentry

Quick Start

package main

import (
    "context"
    "time"

    "github.com/bborbe/errors"
    "github.com/bborbe/sentry"
    "github.com/getsentry/sentry-go"
)

func main() {
    ctx := context.Background()

    // Create client with options
    client, err := sentry.NewClient(ctx, sentry.ClientOptions{
        Dsn: "your-sentry-dsn-here",
        Tags: map[string]string{
            "service": "my-app",
            "version": "1.0.0",
        },
    })
    if err != nil {
        panic(err)
    }
    defer func() {
        client.Flush(2 * time.Second)
        client.Close()
    }()

    // Add context data
    ctx = errors.AddToContext(ctx, "user_id", "12345")
    
    // Create error with data
    err = errors.AddDataToError(
        errors.New("something went wrong"),
        map[string]string{"operation": "user_login"},
    )

    // Capture exception with automatic tag enrichment
    client.CaptureException(err, &sentry.EventHint{
        Context: ctx,
        Data: map[string]interface{}{
            "request_id": "req-abc123",
            "retries": 3,
        },
    }, sentry.NewScope())
}

Core Components

Client Interface

The main interface provides these methods:

type Client interface {
    CaptureMessage(message string, hint *sentry.EventHint, scope sentry.EventModifier) *sentry.EventID
    CaptureException(exception error, hint *sentry.EventHint, scope sentry.EventModifier) *sentry.EventID
    Flush(timeout time.Duration) bool
    io.Closer
}
Error Exclusion

Filter out specific errors to reduce noise:

excludeFunc := func(err error) bool {
    return errors.Is(err, context.Canceled)
}

client, err := sentry.NewClient(ctx, clientOptions, excludeFunc)
Automatic Tag Enrichment

The client automatically extracts and adds tags from:

  • Context data (using github.com/bborbe/errors)
  • Error data (attached to errors)
  • Hint data (passed in EventHint)

API Documentation

For detailed API documentation, visit pkg.go.dev/github.com/bborbe/sentry.

Development

Prerequisites
  • Go 1.24.5 or later
  • Make
Building and Testing
# Install dependencies
make ensure

# Run tests
make test

# Run all checks (formatting, linting, tests)
make precommit

# Generate mocks
make generate
Running the Example
cd example
go run main.go -dsn="your-sentry-dsn-here"

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run make precommit to ensure code quality
  5. Submit a pull request

License

This project is licensed under the BSD License - see the LICENSE file for details.

Dependencies

Documentation

Overview

Package sentry provides an enhanced wrapper around the Sentry Go SDK with additional functionality for error exclusion, automatic tag enrichment, and context data extraction.

The main Client interface wraps the official Sentry Go SDK and adds:

  • Automatic tag extraction from context and errors
  • Configurable error filtering to reduce noise
  • Enhanced integration with github.com/bborbe/errors for context data
  • Proxy support for HTTP transport

Example usage:

client, err := sentry.NewClient(ctx, sentry.ClientOptions{
    Dsn: "your-dsn-here",
    Tags: map[string]string{"service": "my-app"},
})
if err != nil {
    return err
}
defer client.Close()

// Capture exception with automatic tag enrichment
client.CaptureException(err, &sentry.EventHint{Context: ctx}, nil)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProxyRoundTripper

func NewProxyRoundTripper(
	roundtripper http.RoundTripper,
	url string,
) http.RoundTripper

NewProxyRoundTripper allow overwrite sentry host without modifing the alert content.

func NewSkipErrorAndReport

func NewSkipErrorAndReport(sentryClient Client, action run.Runnable) run.Func

Types

type Client

type Client interface {
	CaptureMessage(
		message string,
		hint *sentry.EventHint,
		scope sentry.EventModifier,
	) *sentry.EventID
	CaptureException(
		exception error,
		hint *sentry.EventHint,
		scope sentry.EventModifier,
	) *sentry.EventID
	Flush(timeout stdtime.Duration) bool
	io.Closer
}

func NewClient

func NewClient(
	ctx context.Context,
	clientOptions sentry.ClientOptions,
	excludeErrors ...ExcludeError,
) (Client, error)

type ExcludeError

type ExcludeError func(err error) bool

type ExcludeErrors

type ExcludeErrors []ExcludeError

func (ExcludeErrors) IsExcluded

func (e ExcludeErrors) IsExcluded(err error) bool

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL