Skip to content

Commit

Permalink
add metrics to capture truncated attributes count
Browse files Browse the repository at this point in the history
  • Loading branch information
ie-pham committed Nov 22, 2024
1 parent e8d1339 commit 47a12c6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion integration/e2e/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const (
configLimitsQuery = "config-limits-query.yaml"
configLimitsPartialError = "config-limits-partial-success.yaml"
configLimits429 = "config-limits-429.yaml"
configLimitsSpanAttr = "config-limits-span-attr.yaml"
)

func TestLimits(t *testing.T) {
Expand Down
11 changes: 9 additions & 2 deletions modules/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ const (
reasonInternalError = "internal_error"
// reasonUnknown indicates a pushByte error at the ingester level not related to GRPC
reasonUnknown = "unknown_error"
// reasonAttrTooLarge indicates that at least one attribute in the span is too large
reasonAttrTooLarge = "attribute_too_large"

distributorRingKey = "distributor"
)
Expand Down Expand Up @@ -115,6 +113,11 @@ var (
Name: "distributor_metrics_generator_clients",
Help: "The current number of metrics-generator clients.",
})
metricAttributesTruncated = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "tempo",
Name: "distributor_attributes_truncated_total",
Help: "The total number of proto bytes received per tenant",
}, []string{"tenant"})

statBytesReceived = usagestats.NewCounter("distributor_bytes_received")
statSpansReceived = usagestats.NewCounter("distributor_spans_received")
Expand Down Expand Up @@ -390,6 +393,7 @@ func (d *Distributor) PushTraces(ctx context.Context, traces ptrace.Traces) (*te

if truncatedAttributeCount > 0 {
level.Warn(d.logger).Log("msg", fmt.Sprintf("truncated %d resource/span attributes when adding spans for tenant %s", truncatedAttributeCount, userID))
metricAttributesTruncated.WithLabelValues(userID).Add(float64(truncatedAttributeCount))
}

err = d.sendToIngestersViaBytes(ctx, userID, spanCount, rebatchedTraces, keys)
Expand Down Expand Up @@ -548,6 +552,8 @@ func requestsByTraceID(batches []*v1.ResourceSpans, userID string, spanCount, ma
for _, ils := range b.ScopeSpans {
for _, span := range ils.Spans {
// check large spans for large attributes
fmt.Printf("span size %d", span.Size())
fmt.Printf("maxSpanAttrSize %d", maxSpanAttrSize)
if span.Size() > maxSpanAttrSize {
processAttributes(span.Attributes, maxSpanAttrSize, &truncatedAttributeCount)
}
Expand Down Expand Up @@ -633,6 +639,7 @@ func processAttributes(attributes []*v1_common.KeyValue, maxAttrSize int, count
switch value := attr.GetValue().Value.(type) {
case *v1_common.AnyValue_StringValue:
if len(value.StringValue) > maxAttrSize {
fmt.Printf("size: %d", len(value.StringValue))
value.StringValue = value.StringValue[:maxAttrSize] + "_truncated"
*count++
}
Expand Down

0 comments on commit 47a12c6

Please sign in to comment.