MCPcopy Create free account
hub / github.com/Azure/peerd / WithContext

Function WithContext

pkg/metrics/interface.go:30–37  ·  view source on GitHub ↗

WithContext returns a new context with a metrics recorder.

(ctx context.Context, name, prefix string)

Source from the content-addressed store, hash-verified

28
29// WithContext returns a new context with a metrics recorder.
30func WithContext(ctx context.Context, name, prefix string) (context.Context, error) {
31 pm := NewPromMetrics(prometheus.DefaultRegisterer, name, prefix)
32 if pm == nil {
33 return nil, errors.New("failed to create prometheus metrics")
34 }
35
36 return context.WithValue(ctx, ctxKey{}, pm), nil
37}
38
39// FromContext returns the metrics recorder from the context.
40func FromContext(ctx context.Context) Metrics {

Callers 6

main_test.goFile · 0.92
root_test.goFile · 0.92
handler_test.goFile · 0.92
initFunction · 0.92
mainFunction · 0.92
TestWithContextFunction · 0.70

Calls 1

NewPromMetricsFunction · 0.85

Tested by 2

initFunction · 0.74
TestWithContextFunction · 0.56