Skip to content

Distributed tracing and other context in logging #1281

Open
@mickeyreiss

Description

The current logging interface does not seem to allow callers to inject structured fields, such as trace ids, into the log lines. While custom loggers are acceptable, only global instances are acceptable, and the logging interface only passes Stripe's log messages as arguments.

In my setup, I use context.Context to pass request ids into my logger, which in turn includes these request ids in the structured log lines that are written to stderr. Systems like OpenCensus/OpenTelemetry/OpenTracing also use context to pass correlation tokens through.

It would be nice if the Stripe SDK had support for this, so that I could more easily correlate Stripe's logging with incoming requests. While it is possible to do this to a certain extent by overriding the http.Transaport, I'd like to take full advantage of the diagnostic logging that is already built into this library.

I am curious if this has already been thought through, or if others have solutions. If not, it would be great to add support for this into the logging interfaces.


The current API, for reference:

stripe-go/stripe.go

Lines 181 to 195 in ebbff36

// LeveledLogger is the logger that the backend will use to log errors,
// warnings, and informational messages.
//
// LeveledLoggerInterface is implemented by LeveledLogger, and one can be
// initialized at the desired level of logging. LeveledLoggerInterface
// also provides out-of-the-box compatibility with a Logrus Logger, but may
// require a thin shim for use with other logging libraries that use less
// standard conventions like Zap.
//
// Defaults to DefaultLeveledLogger.
//
// To set a logger that logs nothing, set this to a stripe.LeveledLogger
// with a Level of LevelNull (simply setting this field to nil will not
// work).
LeveledLogger LeveledLoggerInterface

stripe-go/log.go

Lines 124 to 142 in ebbff36

// LeveledLoggerInterface provides a basic leveled logging interface for
// printing debug, informational, warning, and error messages.
//
// It's implemented by LeveledLogger and also provides out-of-the-box
// compatibility with a Logrus Logger, but may require a thin shim for use with
// other logging libraries that you use less standard conventions like Zap.
type LeveledLoggerInterface interface {
// Debugf logs a debug message using Printf conventions.
Debugf(format string, v ...interface{})
// Errorf logs a warning message using Printf conventions.
Errorf(format string, v ...interface{})
// Infof logs an informational message using Printf conventions.
Infof(format string, v ...interface{})
// Warnf logs a warning message using Printf conventions.
Warnf(format string, v ...interface{})
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions