context

package
v6.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package context contains functions to embed data in a context.

There are a few values that we embed in the context that are used, for example, in the log output. This package contains the functions to embed that data in the context, as well as functions to get the data out again and two utility functions to create a logger with the flags already set, and a function to send errors to Sentry with the same flags set.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureError

func CaptureError(ctx context.Context, err error)

CaptureError takes an error and captures the details about it and sends it off to Sentry, if Sentry has been set up.

func ComponentFromContext

func ComponentFromContext(ctx context.Context) (string, bool)

ComponentFromContext returns the component name stored in the context with FromComponent. If no component name was stored in the context, the second argument is false. Otherwise it is true.

func FromComponent

func FromComponent(ctx context.Context, component string) context.Context

FromComponent generates a new context with the given context as its parent and stores the given component name with the context. The component name can be retrieved again using ComponentFromContext.

func FromInstanceID

func FromInstanceID(ctx context.Context, instanceID string) context.Context

FromInstanceID generates a new context with the given context as its parent and stores the given instance ID with the context. The instance ID can be retrieved again using InstanceIDFromContext.

func FromJWT

func FromJWT(ctx context.Context, jwt string) context.Context

FromJWT generates a new context with the given context as its parent and stores the given JWT with the context. The JWT can be retrieved again using JWTFromContext.

func FromJobID

func FromJobID(ctx context.Context, jobID uint64) context.Context

FromJobID generates a new context with the given context as its parent and stores the given job ID with the context. The job ID can be retrieved again using JobIDFromContext.

func FromProcessor

func FromProcessor(ctx context.Context, processor string) context.Context

FromProcessor generates a new context with the given context as its parent and stores the given processor ID with the context. The processor ID can be retrieved again using ProcessorFromContext.

func FromRepository

func FromRepository(ctx context.Context, repository string) context.Context

FromRepository generates a new context with the given context as its parent and stores the given repository name with the context. The repository name can be retrieved again using RepositoryFromContext.

func FromUUID

func FromUUID(ctx context.Context, uuid string) context.Context

FromUUID generates a new context with the given context as its parent and stores the given UUID with the context. The UUID can be retrieved again using UUIDFromContext.

func InstanceIDFromContext

func InstanceIDFromContext(ctx context.Context) (string, bool)

InstanceIDFromContext returns the instance ID stored in the context with FromInstanceID. If no instanceID was stored in the context, the second argument is false. Otherwise it is true.

func JWTFromContext

func JWTFromContext(ctx context.Context) (string, bool)

JWTFromContext returns the jwt stored in the context with FromJWT. If no jwt was stored in the context, the second argument is false. Otherwise it is true.

func JobIDFromContext

func JobIDFromContext(ctx context.Context) (uint64, bool)

JobIDFromContext returns the job ID stored in the context with FromJobID. If no job ID was stored in the context, the second argument is false. Otherwise it is true.

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *logrus.Entry

LoggerFromContext returns a logrus.Entry with the PID of the current process set as a field, and also includes every field set using the From* functions this package.

func LoggerTimingsFromContext

func LoggerTimingsFromContext(ctx context.Context) logrus.Fields

LoggerTimingsFromContext returns a set of logrus fields

func ProcessorFromContext

func ProcessorFromContext(ctx context.Context) (string, bool)

ProcessorFromContext returns the processor name stored in the context with FromProcessor. If no processor name was stored in the context, the second argument is false. Otherwise it is true.

func RepositoryFromContext

func RepositoryFromContext(ctx context.Context) (string, bool)

RepositoryFromContext returns the repository name stored in the context with FromRepository. If no repository name was stored in the context, the second argument is false. Otherwise it is true.

func TimeSince

func TimeSince(ctx context.Context, name string, since time.Time)

TimeSince accumulates timing over the course of a request, it returns "total time this request spent doing X"

func TimingsFromContext

func TimingsFromContext(ctx context.Context) (map[string]time.Duration, bool)

TimingsFromContext returns the timings stored within the context

func UUIDFromContext

func UUIDFromContext(ctx context.Context) (string, bool)

UUIDFromContext returns the UUID stored in the context with FromUUID. If no UUID was stored in the context, the second argument is false. Otherwise it is true.

func WithTimings

func WithTimings(ctx context.Context) context.Context

WithTimings initializes the timings map in the context, to be mutated by TimeSince for accumulated timings per request

Types

This section is empty.

Jump to

Keyboard shortcuts

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