processAttributes finds and truncates attribute keys/values that exceed maxAttrSize.
(attributes []*v1_common.KeyValue, maxAttrSize int, truncationExample *truncatedAttrInfo, scope string)
| 787 | |
| 788 | // processAttributes finds and truncates attribute keys/values that exceed maxAttrSize. |
| 789 | func processAttributes(attributes []*v1_common.KeyValue, maxAttrSize int, truncationExample *truncatedAttrInfo, scope string) int { |
| 790 | count := 0 |
| 791 | for _, attr := range attributes { |
| 792 | if len(attr.Key) > maxAttrSize { |
| 793 | origSize := len(attr.Key) |
| 794 | attr.Key = attr.Key[:maxAttrSize] |
| 795 | if truncationExample != nil && truncationExample.origSize == 0 { // only capture the first truncation |
| 796 | // name is the truncated prefix; origSize records the full original length. |
| 797 | *truncationExample = truncatedAttrInfo{scope: scope, name: attr.Key, field: "key", origSize: origSize} |
| 798 | } |
| 799 | count++ |
| 800 | } |
| 801 | |
| 802 | switch value := attr.GetValue().Value.(type) { |
| 803 | case *v1_common.AnyValue_StringValue: |
| 804 | if len(value.StringValue) > maxAttrSize { |
| 805 | if truncationExample != nil && truncationExample.origSize == 0 { // only capture the first truncation |
| 806 | *truncationExample = truncatedAttrInfo{scope: scope, name: attr.Key, field: "value", origSize: len(value.StringValue)} |
| 807 | } |
| 808 | value.StringValue = value.StringValue[:maxAttrSize] |
| 809 | count++ |
| 810 | } |
| 811 | default: |
| 812 | continue |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | return count |
| 817 | } |
| 818 | |
| 819 | func metricSpans(batches []*v1.ResourceSpans, tenantID string, cfg *MetricReceivedSpansConfig) { |
| 820 | for _, b := range batches { |