# README
APM
Wrapper around Sentry and zerolog to provide a simple way to instrument your Go applications.
Features
- Painless transactions and spans -
apm.StartSpan()
- Context-aware logging and error handling -
apm.NewContext()
,apm.NewLogger()
- Automatic HTTP client instrumentation -
apm.WrapClient()
,apm.WrapRoundTripper()
Usage
package main
// configure APM on your app initialization
apm.SetName("my-app")
apm.SetLogLevel("debug")
apm.SetSentryDSN("https://sentry.io/your-dsn")
// optionally, if you have gitlab.com/etke.cc/go/healthchecks client
apm.SetHealthchecks(healthchecksClient)
// thats it! you are ready to go
// create a new context with correct sentry hub and logger
ctx := apm.NewContext()
// or instrument an existing context
ctx = apm.NewContext(context.Background())
// wrap your http client
client := apm.WrapClient() // wraps http.DefaultClient when no client is provided
// automatic request instrumentation and retries for 5xx errors
client.Do(req)
// work with transactions and spans. No transaction in context? Will be created automatically!
span := apm.StartSpan(ctx, "my-span")
# Functions
EchoLogger is a wrapper around the zerolog logger (without sentry) that implements the echo.Logger interface.
Error captures the error and sends it to sentry and healthchecks.
Flush sends the events to sentry.
GetHub returns the hub from the context (if context is provided and has a hub) or the current hub.
HealthcheckFail sends a healthcheck fail event (if healthchecks are configured).
Log returns a logger with the context provided, if no context is provided, it will return a logger with a new context.
NewContext creates a new context with a logger and sentry hub.
NewLogger returns a new logger with sentry integration (if possible).
NewLoggerPlain returns a new logger without sentry integration.
Recover sends the error to sentry.
SetHealthchecks sets the healthchecks client.
SetLogLevel sets the log level.
SetName sets the name of the application.
SetSentryDSN sets the sentry DSN and initializes it.
StartSpan starts a new span, and if there is no transaction, it starts a new transaction.
WithMaxRetries sets the maximum number of retries for http requests, otherwise defaults to 5.
WithRetryDelay sets the delay between retries for http requests, otherwise defaults to 5 seconds.
WithSentry is a middleware that creates a new transaction for each request.
WrapClient wraps an http.Client with APM instrumentation and retry logic.
WrapRoundTripper wraps an http.RoundTripper with APM instrumentation and retry logic.
# Structs
RoundTripper is an http.RoundTripper that instruments http requests.
# Interfaces
Healthchecks is the interface for gitlab.com/etke.cc/go/healthchecks, to avoid direct dependecy on the package for project where it is not needed.
# Type aliases
RoundTripperOption is a function that configures an APMRoundTripper.