MCPcopy
hub / github.com/grafana/tempo / PushWithTimestampAndLimits

Method PushWithTimestampAndLimits

pkg/livetraces/livetraces.go:86–119  ·  view source on GitHub ↗
(ts time.Time, traceID []byte, batch T, maxLiveTraces, maxTraceSize uint64)

Source from the content-addressed store, hash-verified

84}
85
86func (l *LiveTraces[T]) PushWithTimestampAndLimits(ts time.Time, traceID []byte, batch T, maxLiveTraces, maxTraceSize uint64) error {
87 token := l.token(traceID)
88
89 tr := l.Traces[token]
90 if tr == nil {
91
92 // Before adding this check against max
93 // Zero means no limit
94 if maxLiveTraces > 0 && uint64(len(l.Traces)) >= maxLiveTraces {
95 return ErrMaxLiveTracesExceeded
96 }
97
98 tr = &LiveTrace[T]{
99 ID: traceID,
100 CreatedAt: ts,
101 }
102 l.Traces[token] = tr
103 }
104
105 sz := l.szFunc(batch)
106
107 // Before adding check against max trace size
108 if maxTraceSize > 0 && (tr.sz+sz > maxTraceSize) {
109 l.maxTraceErrorLogger.Log("msg", "max trace size exceeded", "max", maxTraceSize, "reqSize", sz, "totalSize", tr.sz, "trace", util.TraceIDToHexString(traceID))
110 return ErrMaxTraceSizeExceeded
111 }
112
113 tr.sz += sz
114 l.sz += sz
115
116 tr.Batches = append(tr.Batches, batch)
117 tr.LastAppend = ts
118 return nil
119}
120
121func (l *LiveTraces[T]) CutIdle(now time.Time, immediate bool) iter.Seq[*LiveTrace[T]] {
122 idleSince := now.Add(-l.maxIdleTime)

Callers 6

PushMethod · 0.95
AppendTraceMethod · 0.80
pushBytesMethod · 0.80
TestCutIdleDueToIdleTimeFunction · 0.80
TestCutIdleDueToLiveTimeFunction · 0.80

Calls 3

tokenMethod · 0.95
TraceIDToHexStringFunction · 0.92
LogMethod · 0.65

Tested by 3

TestCutIdleDueToIdleTimeFunction · 0.64
TestCutIdleDueToLiveTimeFunction · 0.64