Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ie-pham committed Jan 2, 2025
1 parent 928ccc4 commit f0b1ae8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/sources/tempo/configuration/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ distributor:

# Optional
# Configures the max size an attribute can be. Any key or value that exceeds this limit will be truncated before storing
# Setting this parameter to '0' would disable this check against attribute size
[max_span_attr_byte: <int> | default = '2048']

# Optional.
Expand Down
22 changes: 14 additions & 8 deletions modules/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var (
metricAttributesTruncated = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "tempo",
Name: "distributor_attributes_truncated_total",
Help: "The total number of proto bytes received per tenant",
Help: "The total number of attribute keys or values truncated per tenant",
}, []string{"tenant"})

statBytesReceived = usagestats.NewCounter("distributor_bytes_received")
Expand Down Expand Up @@ -544,15 +544,18 @@ func requestsByTraceID(batches []*v1.ResourceSpans, userID string, spanCount, ma
for _, b := range batches {
spansByILS := make(map[uint32]*v1.ScopeSpans)
// check for large resources for large attributes
if b.Resource.Size() > maxSpanAttrSize {
processAttributes(b.Resource.Attributes, maxSpanAttrSize, &truncatedAttributeCount)
if maxSpanAttrSize > 0 {
fmt.Println("checking size")
resourceAttrTruncatedCount := processAttributes(b.Resource.Attributes, maxSpanAttrSize)
truncatedAttributeCount += resourceAttrTruncatedCount
}

for _, ils := range b.ScopeSpans {
for _, span := range ils.Spans {
// check large spans for large attributes
if span.Size() > maxSpanAttrSize {
processAttributes(span.Attributes, maxSpanAttrSize, &truncatedAttributeCount)
if maxSpanAttrSize > 0 {
spanAttrTruncatedCount := processAttributes(span.Attributes, maxSpanAttrSize)
truncatedAttributeCount += spanAttrTruncatedCount
}
traceID := span.TraceId
if !validation.ValidTraceID(traceID) {
Expand Down Expand Up @@ -626,23 +629,26 @@ func requestsByTraceID(batches []*v1.ResourceSpans, userID string, spanCount, ma
}

// find and truncate the span attributes that are too large
func processAttributes(attributes []*v1_common.KeyValue, maxAttrSize int, count *int) {
func processAttributes(attributes []*v1_common.KeyValue, maxAttrSize int) int {
count := 0
for _, attr := range attributes {
if len(attr.Key) > maxAttrSize {
attr.Key = attr.Key[:maxAttrSize]
*count++
count++
}

switch value := attr.GetValue().Value.(type) {
case *v1_common.AnyValue_StringValue:
if len(value.StringValue) > maxAttrSize {
value.StringValue = value.StringValue[:maxAttrSize]
*count++
count++
}
default:
continue
}
}

return count
}

// discardedPredicate determines if a trace is discarded based on the number of successful replications.
Expand Down

0 comments on commit f0b1ae8

Please sign in to comment.