Documentation ¶
Overview ¶
Package ctx extends standard context to support logging. For context detail, see https://golang.org/pkg/context/
Index ¶
- Constants
- func AddTraceToRequest(context CTX, req *http.Request)
- func GetLogLevel() logrus.Level
- func NewHook(conf *Config) (logrus.Hook, error)
- func SetDebugLevel()
- func SetLogger(configs ...*Config) error
- func SpanContextToString(sc trace.SpanContext) string
- func StringToSpanContext(h string) (sc trace.SpanContext, ok bool)
- type CTX
- func Background() CTX
- func InjectContext(parent context.Context, ctx CTX) CTX
- func StartSpan(parent CTX, name string, o ...trace.StartOption) (CTX, *trace.Span)
- func StartSpanWithRemoteParent(parent CTX, name string, parentSpanContext trace.SpanContext, ...) (CTX, *trace.Span)
- func WithCancel(parent CTX) (CTX, context.CancelFunc)
- func WithTimeout(parent CTX, d time.Duration) (CTX, context.CancelFunc)
- func WithValue(parent CTX, key string, val interface{}) CTX
- func WithValues(parent CTX, kvs map[string]interface{}) CTX
- type Config
- type HTTPFormat
Constants ¶
const (
// TraceHeader is request header for tracing, export so we can use it without http.Request
TraceHeader = `X-Cloud-Trace-Context`
)
Variables ¶
This section is empty.
Functions ¶
func AddTraceToRequest ¶
AddTraceToRequest add `X-Cloud-Trace-Context` header to request
func SpanContextToString ¶
func SpanContextToString(sc trace.SpanContext) string
SpanContextToString convert SpanContext to `X-Cloud-Trace-Context` header propagation format used by Google Cloud products.
func StringToSpanContext ¶
func StringToSpanContext(h string) (sc trace.SpanContext, ok bool)
StringToSpanContext convert `X-Cloud-Trace-Context` header value back to SpanContext.
Types ¶
type CTX ¶
type CTX struct { context.Context logrus.FieldLogger }
CTX extends Google's context to support logging methods.
func Background ¶
func Background() CTX
Background returns a non-nil, empty Context. It is never canceled, has no values, and has no deadline. It is typically used by the main function, initialization, and tests, and as the top-level Context for incoming requests
func InjectContext ¶
InjectContext return a copy of native context
func StartSpanWithRemoteParent ¶
func StartSpanWithRemoteParent(parent CTX, name string, parentSpanContext trace.SpanContext, o ...trace.StartOption) (CTX, *trace.Span)
StartSpanWithRemoteParent returns a copy of parent ctx with parent trace span append
func WithCancel ¶
func WithCancel(parent CTX) (CTX, context.CancelFunc)
WithCancel returns a copy of parent with added cancel function
func WithTimeout ¶
WithTimeout returns a copy of parent with timeout condition and cancel function
func WithValues ¶
WithValues returns a copy of parent in which the values associated with keys are vals.
type Config ¶
type Config struct { Environment string ServiceName string AdapterName string ProjectFolder string LogFormat logrus.Formatter ExportLevel []logrus.Level ExportToFile *string SetAsStdOutput bool }
Config struct define logrus hook setup
type HTTPFormat ¶
type HTTPFormat struct{}
HTTPFormat implements propagation.HTTPFormat to propagate traces in HTTP headers for Google Cloud Platform and Stackdriver Trace. copied from "contrib.go.opencensus.io/exporter/stackdriver/propagation" and modified.
func (*HTTPFormat) SpanContextFromRequest ¶
func (f *HTTPFormat) SpanContextFromRequest(req *http.Request) (sc trace.SpanContext, ok bool)
SpanContextFromRequest extracts a Stackdriver Trace span context from incoming requests.
func (*HTTPFormat) SpanContextToRequest ¶
func (f *HTTPFormat) SpanContextToRequest(sc trace.SpanContext, req *http.Request)
SpanContextToRequest modifies the given request to include a Stackdriver Trace header.