### Install slog-sentry Go library Source: https://github.com/samber/slog-sentry/blob/main/README.md This command installs the `slog-sentry` Go module, allowing you to use it in your Go projects. It fetches the latest version from the module proxy. ```Shell go get github.com/samber/slog-sentry/v2 ``` -------------------------------- ### Go slog-sentry Basic Usage Example Source: https://github.com/samber/slog-sentry/blob/main/README.md Provides a complete Go example demonstrating Sentry initialization, `slog-sentry` handler configuration, and logging of error and informational messages with custom attributes, including structured user and request data. ```Go import ( "github.com/getsentry/sentry-go" slogsentry "github.com/samber/slog-sentry/v2" "log/slog" ) func main() { err := sentry.Init(sentry.ClientOptions{ Dsn: myDSN, EnableTracing: false, }) if err != nil { log.Fatal(err) } defer sentry.Flush(2 * time.Second) logger := slog.New(slogsentry.Option{Level: slog.LevelDebug}. ``` -------------------------------- ### Install Development Tools and Run Tests Source: https://github.com/samber/slog-sentry/blob/main/README.md This snippet provides commands to install necessary development dependencies and execute project tests using `make` commands. It includes options for standard testing and continuous watch-mode testing. ```bash # Install some dev dependencies make tools # Run tests make test # or make watch-test ``` -------------------------------- ### Go slog.Group Example for Sentry User and Tags Source: https://github.com/samber/slog-sentry/blob/main/README.md Demonstrates how to structure `slog.Group` attributes for 'user' and 'tags' fields. These are specifically interpreted by `slog-sentry` to populate Sentry's user and tag contexts. ```Go slog.Group("user", slog.String("id", "user-123"), slog.String("username", "samber"), slog.Time("created_at", time.Now()), ) ``` -------------------------------- ### Go slog-sentry Global Configuration Parameters Source: https://github.com/samber/slog-sentry/blob/main/README.md Illustrates global variables in `slogsentry` that define keys for source, context, error attributes, and a mapping of `slog` levels to Sentry levels for event processing. ```Go slogsentry.SourceKey = "source" slogsentry.ContextKey = "extra" slogsentry.ErrorKeys = []string{"error", "err"} slogsentry.LogLevels = map[slog.Level]sentry.Level{...} ``` -------------------------------- ### Go slog-sentry Handler Option Struct Definition Source: https://github.com/samber/slog-sentry/blob/main/README.md Defines the `Option` struct for configuring the `slog-sentry` handler. It includes fields for log level, Sentry Hub, custom converters, context attribute extraction, source inclusion, attribute replacement, and pre-send event modification. ```Go type Option struct { // Level sets the minimum log level to capture and send to Sentry. // Logs at this level and above will be processed. The default level is debug. Level slog.Leveler // Hub specifies the Sentry Hub to use for capturing events. // If not provided, the current Hub is used by default. Hub *sentry.Hub // Converter is an optional function that customizes how log records // are converted into Sentry events. By default, the DefaultConverter is used. Converter Converter // AttrFromContext is an optional slice of functions that extract attributes // from the context. These functions can add additional metadata to the log entry. AttrFromContext []func(ctx context.Context) []slog.Attr // AddSource is an optional flag that, when set to true, includes the source // information (such as file and line number) in the Sentry event. // This can be useful for debugging purposes. AddSource bool // ReplaceAttr is an optional function that allows for the modification or // replacement of attributes in the log record. This can be used to filter // or transform attributes before they are sent to Sentry. ReplaceAttr func(groups []string, a slog.Attr) slog.Attr // BeforeSend is an optional function that allows for the modification of // the Sentry event before it is sent to the server. This can be used to add // additional context or modify the event payload. BeforeSend func(event *sentry.Event) *sentry.Event } ``` -------------------------------- ### APIDOC: slog-sentry DefaultConverter Supported Attributes Source: https://github.com/samber/slog-sentry/blob/main/README.md Documents attributes interpreted by `slogsentry.DefaultConverter` for mapping `slog` attributes to Sentry event fields. It lists attribute names, `slog.Kind`, and underlying types, noting special handling for 'tags' and 'user' as `slog.Group`. ```APIDOC | Atribute name | `slog.Kind` | Underlying type | | ---------------- | ----------------- | --------------- | | "dist" | string | | | "environment" | string | | | "event_id" | string | | | "platform" | string | | | "release" | string | | | "server_name" | string | | | "tags" | group (see below) | | | "transaction" | string | | | "user" | group (see below) | | | "error" | any | `error` | | "request" | any | `*http.Request` | | "fingerprint" | any | `[]string` | | other attributes | * | | Other attributes will be injected in `context` Sentry field. The Sentry agent is responsible for collecting `modules`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.