feat: support batched traces

This commit is contained in:
2025-05-06 18:42:38 +02:00
parent bf09c0e32e
commit f74dcd4ed3
2 changed files with 59 additions and 5 deletions

View File

@@ -89,15 +89,27 @@ func (tp *LogSamplerProcessor) Capabilities() consumer.Capabilities {
}
/**
* For each trace, record the trace id in a buffer.
* Every trace's trace id that is processed by the processor is being remembered.
*/
func (tp *LogSamplerProcessor) ConsumeTraces(ctx context.Context, td ptrace.Traces) error {
traceId := td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).TraceID()
for i := range td.ResourceSpans().Len() {
resourceSpans := td.ResourceSpans().At(i)
if !traceId.IsEmpty() {
tp.traceIdTtlMap.Add(hex.EncodeToString(traceId[:]))
for j := range resourceSpans.ScopeSpans().Len() {
scopeSpans := resourceSpans.ScopeSpans().At(j)
tp.logger.Debug("Trace added to buffer", zap.String("traceId", hex.EncodeToString(traceId[:])))
for k := range scopeSpans.Spans().Len() {
span := scopeSpans.Spans().At(k)
traceId := span.TraceID()
if !traceId.IsEmpty() {
traceIdStr := hex.EncodeToString(traceId[:])
tp.traceIdTtlMap.Add(traceIdStr)
tp.logger.Debug("Trace added to buffer", zap.String("traceId", traceIdStr))
}
}
}
}
return tp.nextTracesConsumer.ConsumeTraces(ctx, td)