// extractHandlerContext extracts the context and optionally the wrapped handler when it's the same container.
508351
func extractHandlerContext(handler Handler) ([]interface{}, Handler) {
	var kvs []interface{}

	if c, ok := handler.(*contextualHandler); ok {
		handler = c.handler
		kvs = c.keyvals
	}

	return kvs, handler
}
1037304
func CopyToContext(target, source context.Context) context.Context {
	// Copy logger
	if l, ok := logger.FromContext(source); ok {
		target = logger.WithLogger(target, l)
	}

	// Copy reporter
	if r, ok := reporter.FromContext(source); ok {
		target = reporter.WithReporter(target, r)
	}

	// Copy request id
	target = httpx.WithRequestID(target, httpx.RequestID(source))

	// Copy trace span
	if span := opentracing.SpanFromContext(source); span != nil {
		target = opentracing.ContextWithSpan(target, span)
	}

	return target
}
1198398
func ToContext(ctx context.Context, logger *zap.Logger) context.Context {
	l := &ctxLogger{
		logger: logger,
	}
	return context.WithValue(ctx, ctxMarkerKey, l)
}
419190
func FromContext(ctx context.Context) (*Tracing, error) {
	if ctx == nil {
		panic("nil context")
	}

	tracer, ok := ctx.Value(tracingKey).(*Tracing)
	if !ok {
		return nil, errors.New("unable to find tracing in the context")
	}
	return tracer, nil
}
790491
func (o *FindParams) WithContext(ctx context.Context) *FindParams {
	o.SetContext(ctx)
	return o
}
460994
func Context(err error) []interface{} {
	type contextor interface {
		Context() []interface{}
	}

	var kvs []interface{}

	ForEachCause(err, func(err error) bool {
		if cerr, ok := err.(contextor); ok {
			kvs = append(cerr.Context(), kvs...)
		}

		return true
	})

	return kvs
}
293207
func (p *TextMapPropagator) Extract(abstractCarrier interface{}) (SpanContext, error) {
	textMapReader, ok := abstractCarrier.(opentracing.TextMapReader)
	if !ok {
		return emptyContext, opentracing.ErrInvalidCarrier
	}
	var ctx SpanContext
	var baggage map[string]string
	err := textMapReader.ForeachKey(func(rawKey, value string) error {
		key := strings.ToLower(rawKey) // TODO not necessary for plain TextMap
		if key == p.headerKeys.TraceContextHeaderName {
			var err error
			safeVal := p.decodeValue(value)
			if ctx, err = ContextFromString(safeVal); err != nil {
				return err
			}
		} else if key == p.headerKeys.JaegerDebugHeader {
			ctx.debugID = p.decodeValue(value)
		} else if key == p.headerKeys.JaegerBaggageHeader {
			if baggage == nil {
				baggage = make(map[string]string)
			}
			for k, v := range p.parseCommaSeparatedMap(value) {
				baggage[k] = v
			}
		} else if strings.HasPrefix(key, p.headerKeys.TraceBaggageHeaderPrefix) {
			if baggage == nil {
				baggage = make(map[string]string)
			}
			safeKey := p.removeBaggageKeyPrefix(key)
			safeVal := p.decodeValue(value)
			baggage[safeKey] = safeVal
		}
		return nil
	})
	if err != nil {
		p.metrics.DecodingErrors.Inc(1)
		return emptyContext, err
	}
	if !ctx.traceID.IsValid() && ctx.debugID == "" && len(baggage) == 0 {
		return emptyContext, opentracing.ErrSpanContextNotFound
	}
	ctx.baggage = baggage
	return ctx, nil
}
1041165
func (c *Ctx) WithContext(ctx context.Context) {
	c.request = c.request.WithContext(ctx)
}
244763
func (f *fs) getContext() context.Context {
	// TODO: Make timeout configurable
	c, _ := context.WithTimeout(context.Background(), 10*time.Second)
	c = metadata.NewContext(
		c,
		metadata.Pairs("fsid", f.fsid),
	)
	return c
}
1235036
func (w *Ware) CreateContext() *context {
	c := &context{inject.New(), w.handlers, w.action, nil, 0}
	c.SetParent(w)
	c.MapTo(c, (*Context)(nil))
	return c
}
1305949
func (h *RequestID) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	e := h.Extractor
	if e == nil {
		e = DefaultRequestIDExtractor
	}
	requestID := e(r)

	ctx = httpx.WithRequestID(ctx, requestID)
	r = r.WithContext(ctx)

	return h.handler.ServeHTTPContext(ctx, w, r)
}
169466
func (c *Client) StopContainerWithContext(id string, timeout uint, ctx context.Context) error {
	return c.stopContainer(id, timeout, doOptions{context: ctx})
}
502721
func GetContext(sp *Spider, req *request.Request) *Context {
	ctx := contextPool.Get().(*Context)
	ctx.spider = sp
	ctx.Request = req
	return ctx
}
407013
func Handler(h func(*Context)) iris.Handler {
	return func(original iris.Context) {
		ctx := acquire(original)
		h(ctx)
		release(ctx)
	}
}
292853
func (ml *MockRouteCountLogger) GetContext(key string) (interface{}, bool) {
	return ml.logger.GetContext(key)
}
1044667
func (r *Region) GetContext() *kvrpcpb.Context {
	return &kvrpcpb.Context{
		RegionId:    r.meta.Id,
		RegionEpoch: r.meta.RegionEpoch,
		Peer:        r.peer,
	}
}
41017
func ContextHandlerFunc(h http.HandlerFunc, cap int) http.HandlerFunc {
	return ContextHandler(h, cap)
}