mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
opentracing -> opencensus (#802)
* update vendor directory, add go.opencensus.io * update imports * oops * s/opentracing/opencensus/ & remove prometheus / zipkin stuff & remove old stats * the dep train rides again * fix gin build * deps from last guy * start in on the agent metrics * she builds * remove tags for now, cardinality error is fussing. subscribe instead of register * update to patched version of opencensus to proceed for now TODO switch to a release * meh fix imports * println debug the bad boys * lace it with the tags * update deps again * fix all inconsistent cardinality errors * add our own logger * fix init * fix oom measure * remove bugged removal code * fix s3 measures * fix prom handler nil
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/tag"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
@@ -22,11 +24,35 @@ func Logger(ctx context.Context) logrus.FieldLogger {
|
||||
return l
|
||||
}
|
||||
|
||||
// Attempt at simplifying this whole logger in the context thing
|
||||
// Could even make this take a generic map, then the logger that gets returned could be used just like the stdlib too, since it's compatible
|
||||
// LoggerWithFields returns a child context of the provided parent that
|
||||
// contains a logger with additional fields from the parent's logger, it
|
||||
// returns the new child logger, as well.
|
||||
func LoggerWithFields(ctx context.Context, fields logrus.Fields) (context.Context, logrus.FieldLogger) {
|
||||
l := Logger(ctx)
|
||||
l = l.WithFields(fields)
|
||||
ctx = WithLogger(ctx, l)
|
||||
return ctx, l
|
||||
}
|
||||
|
||||
// BackgroundContext returns a context that is specifically not a child of the
|
||||
// provided parent context wrt any cancellation or deadline of the parent,
|
||||
// returning a context that contains all values only. At present, this is a
|
||||
// best effort as there is not a great way to extract all values, known values:
|
||||
// * logger
|
||||
// * span
|
||||
// * tags
|
||||
// (TODO(reed): we could have our own context.Context implementer that stores
|
||||
// all values from WithValue in a bucket we could extract more easily?)
|
||||
func BackgroundContext(ctx context.Context) context.Context {
|
||||
logger := Logger(ctx)
|
||||
span := trace.FromContext(ctx)
|
||||
tagMap := tag.FromContext(ctx)
|
||||
|
||||
// fresh context
|
||||
ctx = context.Background()
|
||||
|
||||
ctx = tag.NewContext(ctx, tagMap)
|
||||
ctx = trace.WithSpan(ctx, span)
|
||||
ctx = WithLogger(ctx, logger)
|
||||
return ctx
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user