MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / SpanTimer

Function SpanTimer

x/x.go:990–1033  ·  view source on GitHub ↗

SpanTimer returns a function used to record the duration of the given span. It supports both OpenCensus and OpenTelemetry spans

(spanInterface interface{}, name string)

Source from the content-addressed store, hash-verified

988// SpanTimer returns a function used to record the duration of the given span.
989// It supports both OpenCensus and OpenTelemetry spans
990func SpanTimer(spanInterface interface{}, name string) func() {
991 // OpenCensus span case
992 if span, ok := spanInterface.(*trace.Span); ok && span != nil {
993 uniq := int64(rand.Int31()) //nolint:gosec // unique id for tracing does not require cryptographic precision
994 attrs := trace.WithAttributes(
995 attribute.Int64("funcId", uniq),
996 attribute.String("funcName", name),
997 )
998 (*span).AddEvent("Start", attrs)
999 start := time.Now()
1000
1001 return func() {
1002 (*span).AddEvent("End", trace.WithAttributes(
1003 attribute.Int64("funcId", uniq),
1004 attribute.String("funcName", name),
1005 attribute.String("duration", time.Since(start).String()),
1006 ))
1007 // TODO: We can look into doing a latency record here.
1008 }
1009 }
1010
1011 // OpenTelemetry span case
1012 if span, ok := spanInterface.(trace.Span); ok {
1013 uniq := int64(rand.Int31()) //nolint:gosec // unique id for tracing does not require cryptographic precision
1014 attrs := trace.WithAttributes(
1015 attribute.Int64("funcId", uniq),
1016 attribute.String("funcName", name),
1017 )
1018 span.AddEvent("Start", attrs)
1019 start := time.Now()
1020
1021 return func() {
1022 span.AddEvent("End", trace.WithAttributes(
1023 attribute.Int64("funcId", uniq),
1024 attribute.String("funcName", name),
1025 attribute.String("duration", time.Since(start).String()),
1026 ))
1027 // TODO: We can look into doing a latency record here.
1028 }
1029 }
1030
1031 // Fall back for nil or unknown span type
1032 return func() {}
1033}
1034
1035// CloseFunc needs to be called to close all the client connections.
1036type CloseFunc func()

Callers 15

proposeAndWaitMethod · 0.92
processSortFunction · 0.92
proposeAndWaitMethod · 0.92
handleValuePostingsMethod · 0.92
handleUidPostingsMethod · 0.92
processTaskFunction · 0.92
handleRegexFunctionMethod · 0.92
handleCompareFunctionMethod · 0.92
handleMatchFunctionMethod · 0.92
filterGeoFunctionMethod · 0.92
handleHasFunctionMethod · 0.92
expandSubgraphFunction · 0.92

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…