From 778d3e80aabaaa5607295fd0810b9c32e73c27b8 Mon Sep 17 00:00:00 2001 From: Justin Terry Date: Mon, 12 Oct 2026 12:04:26 -0700 Subject: [PATCH] build(deps) bumb go.opentelemetry.io/sdk to 1.47.0 Signed-off-by: Justin Terry --- go.mod | 6 +- go.sum | 16 +- test/go.mod | 4 +- test/go.sum | 12 +- .../grpc/otelgrpc/version.go | 2 +- .../otel/sdk/internal/attrnorm/dedup.go | 546 +++++++++++++++++- .../otel/sdk/internal/attrnorm/truncate.go | 362 +++++++++--- .../otel/sdk/resource/resource.go | 2 +- .../internal/observ/batch_span_processor.go | 6 + .../otel/sdk/trace/internal/observ/tracer.go | 7 + .../otel/sdk/trace/provider.go | 62 +- .../otel/sdk/trace/sampler_env.go | 9 +- .../otel/sdk/trace/simple_span_processor.go | 7 +- .../otel/sdk/trace/snapshot.go | 2 +- .../otel/sdk/trace/span.go | 51 +- .../otel/sdk/trace/span_limits.go | 26 +- .../go.opentelemetry.io/otel/sdk/version.go | 2 +- vendor/modules.txt | 12 +- 18 files changed, 955 insertions(+), 179 deletions(-) diff --git a/go.mod b/go.mod index a5fe4676ca..2d88fbe183 100644 --- a/go.mod +++ b/go.mod @@ -58,9 +58,9 @@ require ( github.com/vishvananda/netlink v1.3.1 github.com/vishvananda/netns v0.0.5 go.etcd.io/bbolt v1.5.0 - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.71.0 + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.72.0 go.opentelemetry.io/otel v1.47.0 - go.opentelemetry.io/otel/sdk v1.46.0 + go.opentelemetry.io/otel/sdk v1.47.0 go.opentelemetry.io/otel/trace v1.47.0 go.uber.org/mock v0.6.0 golang.org/x/net v0.59.0 @@ -136,7 +136,7 @@ require ( golang.org/x/mod v0.41.0 // indirect golang.org/x/text v0.42.0 // indirect golang.org/x/tools v0.49.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc // indirect google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.2 // indirect sigs.k8s.io/yaml v1.6.0 // indirect ) diff --git a/go.sum b/go.sum index 0b144c07c9..e14ad23f8f 100644 --- a/go.sum +++ b/go.sum @@ -1008,8 +1008,8 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.5 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0/go.mod h1:HDBUsEjOuRC0EzKZ1bSaRGZWUBAzo+MhAcUUORSr4D0= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0/go.mod h1:ijPqXp5P6IRRByFVVg9DY8P5HkxkHE5ARIa+86aXPf4= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0/go.mod h1:rg+RlpR5dKwaS95IyyZqj5Wd4E13lk/msnTS0Xl9lJM= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.71.0 h1:B2h3uqicet1CT2N5TOFhS+Gq++9i0/CLmaxvhmhtP5s= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.71.0/go.mod h1:dylvB+ZiiwMvsDij9O84Uy7SijLgHMX4mbkncds+4Sw= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.72.0 h1:Tq+E65HaNbZTeqcLw6QUhsV+/EIWdkfUH2CQzcrlE5M= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.72.0/go.mod h1:A+EVhDakAj1waJBPhmTszZaSr08ww8MRRKy1nB1rqck= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1/go.mod h1:sEGXWArGqc3tVa+ekntsN65DmVbVeW+7lTKTjZF3/Fo= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0/go.mod h1:SK2UL73Zy1quvRPonmOmRDiWk1KBV3LyIeeIxcEApWw= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.48.0/go.mod h1:rdENBZMT2OE6Ne/KLwpiXudnAsbdrdBaqBvTN8M8BgA= @@ -1063,8 +1063,8 @@ go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJC go.opentelemetry.io/otel/sdk v1.33.0/go.mod h1:A1Q5oi7/9XaMlIWzPSxLRWOI8nG3FnzHJNbiENQuihM= go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= go.opentelemetry.io/otel/sdk v1.35.0/go.mod h1:+ga1bZliga3DxJ3CQGg3updiaAJoNECOgJREo9KHGQg= -go.opentelemetry.io/otel/sdk v1.46.0 h1:h5CNQQjEbuQXY/JfZtgt3i7HVFV3aHPO2OAwO2eTYPI= -go.opentelemetry.io/otel/sdk v1.46.0/go.mod h1:GAERFXFt5SYCEB+YiKUbMBeza6UaDH7GmGOZEfh2gSM= +go.opentelemetry.io/otel/sdk v1.47.0 h1:zWXEr4j2lFefG87TU6Yg8a7ngfohIKFZHKp0Hf5hC6I= +go.opentelemetry.io/otel/sdk v1.47.0/go.mod h1:VUc24kiOeoGsxG8G9ULx3fWKvB7jMhnGE8Oi607lgR0= go.opentelemetry.io/otel/sdk/metric v1.28.0/go.mod h1:cWPjykihLAPvXKi4iZc1dpER3Jdq2Z0YLse3moQUCpg= go.opentelemetry.io/otel/sdk/metric v1.29.0/go.mod h1:6zZLdCl2fkauYoZIOn/soQIDSWFmNSRcICarHfuhNJQ= go.opentelemetry.io/otel/sdk/metric v1.30.0/go.mod h1:waS6P3YqFNzeP01kuo/MBBYqaoBJl7efRQHOaydhy1Y= @@ -1072,8 +1072,8 @@ go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ= go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= go.opentelemetry.io/otel/sdk/metric v1.35.0/go.mod h1:is6XYCUMpcKi+ZsOvfluY5YstFnhW0BidkR+gL+qN+w= -go.opentelemetry.io/otel/sdk/metric v1.46.0 h1:0piZ26EG4RBfebb2jhDH6ERCYHoVWduc3kLgPCwSnSE= -go.opentelemetry.io/otel/sdk/metric v1.46.0/go.mod h1:I1PbKrdVc8Qu8HYVDNtqVIwLwjNrhsV/uFuxfwg8mO4= +go.opentelemetry.io/otel/sdk/metric v1.47.0 h1:lfISg2j93VT6yqdk9OfUaZmw/GfcZqCCV3jdXtsPnKw= +go.opentelemetry.io/otel/sdk/metric v1.47.0/go.mod h1:ypLp+mW1Nt2x+Szt3b5/i1syodyts49lMOwxpDI3VGw= go.opentelemetry.io/otel/trace v1.21.0/go.mod h1:LGbsEB0f9LGjN+OZaQQ26sohbOmiMR+BaslueVtS/qQ= go.opentelemetry.io/otel/trace v1.22.0/go.mod h1:RbbHXVqKES9QhzZq/fE5UnOSILqRt40a21sPw2He1xo= go.opentelemetry.io/otel/trace v1.23.0/go.mod h1:GSGTbIClEsuZrGIzoEHqsVfxgn5UkggkflQwDScNUsk= @@ -1933,8 +1933,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4/go. google.golang.org/genproto/googleapis/rpc v0.0.0-20250409194420-de1ac958c67a/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= google.golang.org/genproto/googleapis/rpc v0.0.0-20250414145226-207652e42e2e/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= google.golang.org/genproto/googleapis/rpc v0.0.0-20250425173222-7b384671a197/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 h1:1VUiZAXyC+zmiFYi+WLtBzr68Cj8wOofHjjrA/kkizc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc h1:4bNTbnb44EqGVy9HaQxSY2jnafSUdgV3qHtedvNpDKg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/test/go.mod b/test/go.mod index 70082d5ec1..0e4d8db0d9 100644 --- a/test/go.mod +++ b/test/go.mod @@ -22,7 +22,7 @@ require ( github.com/sirupsen/logrus v1.10.0 github.com/urfave/cli/v2 v2.27.7 go.opentelemetry.io/otel v1.47.0 - go.opentelemetry.io/otel/sdk v1.46.0 + go.opentelemetry.io/otel/sdk v1.47.0 golang.org/x/sync v0.23.0 golang.org/x/sys v0.49.0 google.golang.org/grpc v1.84.0 @@ -117,7 +117,7 @@ require ( golang.org/x/crypto v0.57.0 // indirect golang.org/x/net v0.59.0 // indirect golang.org/x/text v0.42.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc // indirect gotest.tools/v3 v3.5.2 // indirect sigs.k8s.io/yaml v1.6.0 // indirect ) diff --git a/test/go.sum b/test/go.sum index 9927245723..40144dc855 100644 --- a/test/go.sum +++ b/test/go.sum @@ -263,10 +263,10 @@ go.opentelemetry.io/otel/log v1.47.0 h1:cOTS1CcLbSQeZKanGJ+0JpF/+t4PELi3O3bbl2lq go.opentelemetry.io/otel/log v1.47.0/go.mod h1:9byitSQ5pLC6PpqwGXjqdMKya6ZTswHRZh2vvXT33nw= go.opentelemetry.io/otel/metric v1.47.0 h1:4PptaldXx3Eat1XjMZ68pPJEs5wrhlemctZE9a3UdWY= go.opentelemetry.io/otel/metric v1.47.0/go.mod h1:ADGSXxRrXM6bjbvLo535EstVFlPpPYZm4LBKixjDHwU= -go.opentelemetry.io/otel/sdk v1.46.0 h1:h5CNQQjEbuQXY/JfZtgt3i7HVFV3aHPO2OAwO2eTYPI= -go.opentelemetry.io/otel/sdk v1.46.0/go.mod h1:GAERFXFt5SYCEB+YiKUbMBeza6UaDH7GmGOZEfh2gSM= -go.opentelemetry.io/otel/sdk/metric v1.46.0 h1:0piZ26EG4RBfebb2jhDH6ERCYHoVWduc3kLgPCwSnSE= -go.opentelemetry.io/otel/sdk/metric v1.46.0/go.mod h1:I1PbKrdVc8Qu8HYVDNtqVIwLwjNrhsV/uFuxfwg8mO4= +go.opentelemetry.io/otel/sdk v1.47.0 h1:zWXEr4j2lFefG87TU6Yg8a7ngfohIKFZHKp0Hf5hC6I= +go.opentelemetry.io/otel/sdk v1.47.0/go.mod h1:VUc24kiOeoGsxG8G9ULx3fWKvB7jMhnGE8Oi607lgR0= +go.opentelemetry.io/otel/sdk/metric v1.47.0 h1:lfISg2j93VT6yqdk9OfUaZmw/GfcZqCCV3jdXtsPnKw= +go.opentelemetry.io/otel/sdk/metric v1.47.0/go.mod h1:ypLp+mW1Nt2x+Szt3b5/i1syodyts49lMOwxpDI3VGw= go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM= go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -296,8 +296,8 @@ golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI= golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 h1:1VUiZAXyC+zmiFYi+WLtBzr68Cj8wOofHjjrA/kkizc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc h1:4bNTbnb44EqGVy9HaQxSY2jnafSUdgV3qHtedvNpDKg= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc= google.golang.org/grpc v1.84.0 h1:soMyaPJ8pAak5PIQ0DGBUir0XRo2fRoMqhNWMLlLxO0= google.golang.org/grpc v1.84.0/go.mod h1:ljCht0DrxQrXBDRTZp52Qxh3Ffk8CdYm2sj4O2QN2C0= google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= diff --git a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/version.go b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/version.go index 33a07b0b24..bef4014dc3 100644 --- a/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/version.go +++ b/vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/version.go @@ -4,4 +4,4 @@ package otelgrpc // Version is the current release version of the gRPC instrumentation. -const Version = "0.71.0" +const Version = "0.72.0" diff --git a/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/dedup.go b/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/dedup.go index fe9ddc96db..d72cfb3c92 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/dedup.go +++ b/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/dedup.go @@ -28,40 +28,142 @@ type rawValue struct { slice any } -// Value returns value with all map values deduplicated and whether it changed. +type valueChanges uint8 + +const ( + depthLimitChanged valueChanges = 1 << iota + deduplicationChanged +) + +// ValueDedup returns value with all map values deduplicated and whether +// it changed. // // Duplicate map keys are resolved using last-value-wins semantics. -func Value(value attribute.Value) (attribute.Value, bool) { +func ValueDedup(value attribute.Value) (attribute.Value, bool) { switch value.Type() { case attribute.SLICE: - return deduplicateSliceValue(value) + return sliceValueDedup(value) case attribute.MAP: - return deduplicateMapValue(value) + return mapValueDedup(value) default: return value, false } } -// KeyValue returns kv with all map values deduplicated and whether it changed. -func KeyValue(kv attribute.KeyValue) (attribute.KeyValue, bool) { - value, changed := Value(kv.Value) +// ValueDedupLimitDepth returns value with all map values +// deduplicated and all array and map values limited to depthLimit. The boolean +// results report depth limiting and deduplication changes, respectively. +// +// Duplicate map keys are resolved using last-value-wins semantics. Depth +// starts at one for value and increments when descending into an array element +// or map value. An array or map beyond a non-negative depthLimit is replaced by +// an empty value. A negative depthLimit disables depth limiting. +func ValueDedupLimitDepth( + value attribute.Value, + depthLimit int, +) (attribute.Value, bool, bool) { + if depthLimit < 0 { + value, deduplicated := ValueDedup(value) + return value, false, deduplicated + } + + // Keep the common scalar and primitive-array cases in this wrapper. Routing + // them through the recursive, multi-result transform adds measurable + // overhead to the dominant simple attribute path. + switch value.Type() { + case attribute.BOOLSLICE, + attribute.INT64SLICE, + attribute.FLOAT64SLICE, + attribute.STRINGSLICE, + attribute.BYTESLICE: + if depthLimit == 0 { + return attribute.Value{}, true, false + } + return value, false, false + case attribute.SLICE, attribute.MAP: + default: + return value, false, false + } + + value, changes := valueDedupLimitDepth(value, depthLimit) + return value, changes&depthLimitChanged != 0, changes&deduplicationChanged != 0 +} + +// ValueLimitDepth returns value with all array and map values limited to +// depthLimit. Map keys are not deduplicated. +// +// Depth starts at one for value and increments when descending into an array +// element or map value. An array or map beyond a non-negative depthLimit is +// replaced by an empty value. A negative depthLimit disables depth limiting. +func ValueLimitDepth(value attribute.Value, depthLimit int) (attribute.Value, bool) { + if depthLimit < 0 { + return value, false + } + + switch value.Type() { + case attribute.BOOLSLICE, + attribute.INT64SLICE, + attribute.FLOAT64SLICE, + attribute.STRINGSLICE, + attribute.BYTESLICE: + if depthLimit == 0 { + return attribute.Value{}, true + } + return value, false + case attribute.SLICE, attribute.MAP: + default: + return value, false + } + + return valueLimitDepth(value, depthLimit) +} + +// KeyValueDedup returns kv with all map values deduplicated and whether +// it changed. +func KeyValueDedup(kv attribute.KeyValue) (attribute.KeyValue, bool) { + value, changed := ValueDedup(kv.Value) if changed { kv.Value = value } return kv, changed } -// KeyValues returns kvs with all map values deduplicated and whether they changed. +// KeyValueDedupLimitDepth returns kv with all map values +// deduplicated and all array and map values limited to depthLimit. The boolean +// results report depth limiting and deduplication changes, respectively. +func KeyValueDedupLimitDepth( + kv attribute.KeyValue, + depthLimit int, +) (attribute.KeyValue, bool, bool) { + value, depthLimited, deduplicated := ValueDedupLimitDepth(kv.Value, depthLimit) + if depthLimited || deduplicated { + kv.Value = value + } + return kv, depthLimited, deduplicated +} + +// KeyValueLimitDepth returns kv with all array and map values limited to +// depthLimit. Map keys are not deduplicated. +func KeyValueLimitDepth(kv attribute.KeyValue, depthLimit int) (attribute.KeyValue, bool) { + value, changed := ValueLimitDepth(kv.Value, depthLimit) + if changed { + kv.Value = value + } + return kv, changed +} + +// KeyValuesDedup returns kvs with all map values deduplicated and whether +// they changed. // // The returned slice is the original kvs slice if no value needs // deduplication. Top-level keys in kvs are not deduplicated. -func KeyValues(kvs []attribute.KeyValue) ([]attribute.KeyValue, bool) { +func KeyValuesDedup(kvs []attribute.KeyValue) ([]attribute.KeyValue, bool) { // Preserve the caller's slice on the common no-op path. Once a changed // value is found, copy the prior values exactly once and fill the rest in // place as the scan continues. var normalized []attribute.KeyValue for i, kv := range kvs { - kv, changed := KeyValue(kv) + kv, changed := KeyValueDedup(kv) if normalized != nil { normalized[i] = kv continue @@ -80,22 +182,67 @@ func KeyValues(kvs []attribute.KeyValue) ([]attribute.KeyValue, bool) { return normalized, true } -// Set returns set with all map values deduplicated and whether it changed. +// KeyValuesDedupLimitDepth returns kvs with all map values +// deduplicated and all array and map values limited to depthLimit. The boolean +// results report depth limiting and deduplication changes, respectively. +// +// The returned slice is the original kvs slice if no value needs +// normalization. Top-level keys in kvs are not deduplicated. +func KeyValuesDedupLimitDepth( + kvs []attribute.KeyValue, + depthLimit int, +) ([]attribute.KeyValue, bool, bool) { + if depthLimit < 0 { + kvs, deduplicated := KeyValuesDedup(kvs) + return kvs, false, deduplicated + } + + var normalized []attribute.KeyValue + var allChanges valueChanges + for i, kv := range kvs { + value, changes := valueDedupLimitDepth(kv.Value, depthLimit) + allChanges |= changes + if changes != 0 { + kv.Value = value + } + if normalized != nil { + normalized[i] = kv + continue + } + if changes == 0 { + continue + } + + normalized = make([]attribute.KeyValue, len(kvs)) + copy(normalized, kvs[:i]) + normalized[i] = kv + } + if normalized == nil { + return kvs, false, false + } + return normalized, + allChanges&depthLimitChanged != 0, + allChanges&deduplicationChanged != 0 +} + +// SetDedup returns set with all map values deduplicated and whether it +// changed. // // The returned Set is the original set if no value needs deduplication. // Top-level key uniqueness remains attribute.Set's responsibility; this only // normalizes map attribute values. -func Set(set attribute.Set) (attribute.Set, bool) { - if set.Len() == 0 { +func SetDedup(set attribute.Set) (attribute.Set, bool) { + length := set.Len() + if length == 0 { return set, false } // Most attribute sets contain no duplicate map keys. Delay allocation until // the first changed value so the no-op path returns the original Set. var normalized []attribute.KeyValue - for i := range set.Len() { + for i := range length { kv, _ := set.Get(i) - kv, changed := KeyValue(kv) + kv, changed := KeyValueDedup(kv) if normalized != nil { normalized = append(normalized, kv) continue @@ -104,7 +251,7 @@ func Set(set attribute.Set) (attribute.Set, bool) { continue } - normalized = make([]attribute.KeyValue, 0, set.Len()) + normalized = make([]attribute.KeyValue, 0, length) for j := range i { prior, _ := set.Get(j) normalized = append(normalized, prior) @@ -118,7 +265,359 @@ func Set(set attribute.Set) (attribute.Set, bool) { return attribute.NewSet(normalized...), true } -func deduplicateSliceValue(value attribute.Value) (attribute.Value, bool) { +// SetDedupLimitDepth returns set with all map values deduplicated and +// all array and map values limited to depthLimit. The boolean results report +// depth limiting and deduplication changes, respectively. +// +// The returned Set is the original set if no value needs normalization. +// Top-level key uniqueness remains attribute.Set's responsibility; this only +// normalizes attribute values. +func SetDedupLimitDepth( + set attribute.Set, + depthLimit int, +) (attribute.Set, bool, bool) { + if depthLimit < 0 { + set, deduplicated := SetDedup(set) + return set, false, deduplicated + } + length := set.Len() + if length == 0 { + return set, false, false + } + + var normalized []attribute.KeyValue + var allChanges valueChanges + for i := range length { + kv, _ := set.Get(i) + value, changes := valueDedupLimitDepth(kv.Value, depthLimit) + allChanges |= changes + if changes != 0 { + kv.Value = value + } + if normalized != nil { + normalized = append(normalized, kv) + continue + } + if changes == 0 { + continue + } + + normalized = make([]attribute.KeyValue, 0, length) + for j := range i { + prior, _ := set.Get(j) + normalized = append(normalized, prior) + } + normalized = append(normalized, kv) + } + if normalized == nil { + return set, false, false + } + return attribute.NewSet(normalized...), + allChanges&depthLimitChanged != 0, + allChanges&deduplicationChanged != 0 +} + +// SetLimitDepth returns set with all array and map values limited to +// depthLimit. Map keys are not deduplicated. +// +// The returned Set is the original set if no value changes. +func SetLimitDepth(set attribute.Set, depthLimit int) (attribute.Set, bool) { + if depthLimit < 0 { + return set, false + } + length := set.Len() + if length == 0 { + return set, false + } + + var normalized []attribute.KeyValue + for i := range length { + kv, _ := set.Get(i) + value, changed := valueLimitDepth(kv.Value, depthLimit) + if changed { + kv.Value = value + } + if normalized != nil { + normalized = append(normalized, kv) + continue + } + if !changed { + continue + } + + normalized = make([]attribute.KeyValue, 0, length) + for j := range i { + prior, _ := set.Get(j) + normalized = append(normalized, prior) + } + normalized = append(normalized, kv) + } + if normalized == nil { + return set, false + } + return attribute.NewSet(normalized...), true +} + +// valueDedupLimitDepth combines depth limiting with recursive map +// deduplication. remainingDepth is non-negative. It checks the remaining +// budget before reading collection storage and lazily rebuilds only changed +// ancestry. +func valueDedupLimitDepth( + value attribute.Value, + remainingDepth int, +) (attribute.Value, valueChanges) { + switch value.Type() { + case attribute.BOOLSLICE, + attribute.INT64SLICE, + attribute.FLOAT64SLICE, + attribute.STRINGSLICE, + attribute.BYTESLICE: + if remainingDepth == 0 { + return attribute.Value{}, depthLimitChanged + } + case attribute.SLICE: + if remainingDepth == 0 { + return attribute.Value{}, depthLimitChanged + } + return sliceValueDedupLimitDepth(value, remainingDepth) + case attribute.MAP: + if remainingDepth == 0 { + return attribute.Value{}, depthLimitChanged + } + return mapValueDedupLimitDepth(value, remainingDepth) + } + return value, 0 +} + +// valueLimitDepth limits collection depth while preserving duplicate map keys. +func valueLimitDepth( + value attribute.Value, + remainingDepth int, +) (attribute.Value, bool) { + switch value.Type() { + case attribute.BOOLSLICE, + attribute.INT64SLICE, + attribute.FLOAT64SLICE, + attribute.STRINGSLICE, + attribute.BYTESLICE: + if remainingDepth == 0 { + return attribute.Value{}, true + } + case attribute.SLICE: + if remainingDepth == 0 { + return attribute.Value{}, true + } + return sliceValueLimitDepth(value, remainingDepth) + case attribute.MAP: + if remainingDepth == 0 { + return attribute.Value{}, true + } + return mapValueLimitDepth(value, remainingDepth) + } + return value, false +} + +func sliceValueDedupLimitDepth( + value attribute.Value, + remainingDepth int, +) (attribute.Value, valueChanges) { + storage := valueStorage(value) + length := valueLen(storage) + if length <= 1 { + if length == 1 { + elem := valueAt(storage, 0) + newElem, changes := valueDedupLimitDepth( + elem, + remainingDepth-1, + ) + if changes != 0 { + return attribute.SliceValue(newElem), changes + } + } + return value, 0 + } + + var normalized []attribute.Value + var allChanges valueChanges + for i := range length { + elem := valueAt(storage, i) + newElem, changes := valueDedupLimitDepth( + elem, + remainingDepth-1, + ) + allChanges |= changes + if normalized != nil { + normalized[i] = newElem + continue + } + if changes == 0 { + continue + } + + normalized = make([]attribute.Value, length) + for j := range i { + normalized[j] = valueAt(storage, j) + } + normalized[i] = newElem + } + if normalized == nil { + return value, 0 + } + return attribute.SliceValue(normalized...), allChanges +} + +func sliceValueLimitDepth( + value attribute.Value, + remainingDepth int, +) (attribute.Value, bool) { + storage := valueStorage(value) + length := valueLen(storage) + if length <= 1 { + if length == 1 { + elem := valueAt(storage, 0) + newElem, changed := valueLimitDepth(elem, remainingDepth-1) + if changed { + return attribute.SliceValue(newElem), true + } + } + return value, false + } + + var normalized []attribute.Value + for i := range length { + elem := valueAt(storage, i) + newElem, changed := valueLimitDepth(elem, remainingDepth-1) + if normalized != nil { + normalized[i] = newElem + continue + } + if !changed { + continue + } + + normalized = make([]attribute.Value, length) + for j := range i { + normalized[j] = valueAt(storage, j) + } + normalized[i] = newElem + } + if normalized == nil { + return value, false + } + return attribute.SliceValue(normalized...), true +} + +func mapValueDedupLimitDepth( + value attribute.Value, + remainingDepth int, +) (attribute.Value, valueChanges) { + storage := valueStorage(value) + length := keyValueLen(storage) + if length <= 1 { + if length == 1 { + kv := keyValueAt(storage, 0) + newValue, changes := valueDedupLimitDepth( + kv.Value, + remainingDepth-1, + ) + if changes != 0 { + kv.Value = newValue + return attribute.MapValue(kv), changes + } + } + return value, 0 + } + + var normalized []attribute.KeyValue + var allChanges valueChanges + for i := 0; i < length; { + // attribute.MapValue stores key-values sorted by key using a stable + // sort. Only the last entry in an equal-key run survives, so avoid + // traversing values that will be discarded. + first := keyValueAt(storage, i) + j := i + 1 + for j < length && keyValueAt(storage, j).Key == first.Key { + j++ + } + + kv := keyValueAt(storage, j-1) + newValue, changes := valueDedupLimitDepth( + kv.Value, + remainingDepth-1, + ) + if changes != 0 { + kv.Value = newValue + } + if j-i > 1 { + changes |= deduplicationChanged + } + allChanges |= changes + if normalized != nil { + normalized = append(normalized, kv) + } else if changes != 0 { + if i == 0 && j == length { + return attribute.MapValue(kv), allChanges + } + normalized = make([]attribute.KeyValue, 0, length-(j-i-1)) + for k := range i { + normalized = append(normalized, keyValueAt(storage, k)) + } + normalized = append(normalized, kv) + } + i = j + } + if normalized == nil { + return value, 0 + } + return attribute.MapValue(normalized...), allChanges +} + +func mapValueLimitDepth( + value attribute.Value, + remainingDepth int, +) (attribute.Value, bool) { + storage := valueStorage(value) + length := keyValueLen(storage) + if length <= 1 { + if length == 1 { + kv := keyValueAt(storage, 0) + newValue, changed := valueLimitDepth(kv.Value, remainingDepth-1) + if changed { + kv.Value = newValue + return attribute.MapValue(kv), true + } + } + return value, false + } + + var normalized []attribute.KeyValue + for i := range length { + kv := keyValueAt(storage, i) + newValue, changed := valueLimitDepth(kv.Value, remainingDepth-1) + if changed { + kv.Value = newValue + } + if normalized != nil { + normalized[i] = kv + continue + } + if !changed { + continue + } + + normalized = make([]attribute.KeyValue, length) + for j := range i { + normalized[j] = keyValueAt(storage, j) + } + normalized[i] = kv + } + if normalized == nil { + return value, false + } + return attribute.MapValue(normalized...), true +} + +func sliceValueDedup(value attribute.Value) (attribute.Value, bool) { storage := valueStorage(value) length := valueLen(storage) @@ -127,7 +626,7 @@ func deduplicateSliceValue(value attribute.Value) (attribute.Value, bool) { var normalized []attribute.Value for i := range length { elem := valueAt(storage, i) - elem, changed := Value(elem) + elem, changed := ValueDedup(elem) if normalized != nil { normalized[i] = elem continue @@ -148,14 +647,14 @@ func deduplicateSliceValue(value attribute.Value) (attribute.Value, bool) { return attribute.SliceValue(normalized...), true } -func deduplicateMapValue(value attribute.Value) (attribute.Value, bool) { +func mapValueDedup(value attribute.Value) (attribute.Value, bool) { storage := valueStorage(value) length := keyValueLen(storage) if length <= 1 { // A single map entry cannot duplicate its own key, but its value might // contain a map or slice that needs recursive normalization. if length == 1 { - kv, changed := KeyValue(keyValueAt(storage, 0)) + kv, changed := KeyValueDedup(keyValueAt(storage, 0)) if changed { return attribute.MapValue(kv), true } @@ -174,13 +673,16 @@ func deduplicateMapValue(value attribute.Value) (attribute.Value, bool) { j++ } - kv, nestedChanged := KeyValue(keyValueAt(storage, j-1)) + kv, nestedChanged := KeyValueDedup(keyValueAt(storage, j-1)) // j-i > 1 means the current key run contained duplicates. changed := nestedChanged || j-i > 1 if normalized != nil { normalized = append(normalized, kv) } else if changed { - normalized = make([]attribute.KeyValue, 0, length) + if i == 0 && j == length { + return attribute.MapValue(kv), true + } + normalized = make([]attribute.KeyValue, 0, length-(j-i-1)) for k := range i { normalized = append(normalized, keyValueAt(storage, k)) } diff --git a/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/truncate.go b/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/truncate.go index c8341599b3..db7c5388ca 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/truncate.go +++ b/vendor/go.opentelemetry.io/otel/sdk/internal/attrnorm/truncate.go @@ -7,7 +7,7 @@ package attrnorm import ( - "slices" + "reflect" "strings" "unicode/utf8" @@ -26,43 +26,24 @@ func Truncate(limit int, attr attribute.KeyValue) attribute.KeyValue { if limit < 0 { return attr } + + // Keep scalar cases in this wrapper. Routing them through the recursive, + // multi-result transform adds measurable overhead to the dominant simple + // attribute path. switch attr.Value.Type() { case attribute.STRING: - v := attr.Value.AsString() - return attr.Key.String(truncate(limit, v)) - case attribute.STRINGSLICE: - v := attr.Value.AsStringSlice() - for i := range v { - v[i] = truncate(limit, v[i]) - } - return attr.Key.StringSlice(v) + attr.Value = attribute.StringValue(truncate(limit, attr.Value.AsString())) case attribute.BYTESLICE: - v := attr.Value.AsString() - if len(v) > limit { - return attr.Key.ByteSlice([]byte(v[:limit])) + s := attr.Value.AsString() + if len(s) > limit { + attr.Value = attribute.ByteSliceValue([]byte(s[:limit])) } - return attr + case attribute.STRINGSLICE: + attr.Value, _ = truncateStringSliceValue(limit, attr.Value) case attribute.SLICE: - v := attr.Value.AsSlice() - if !slices.ContainsFunc(v, func(e attribute.Value) bool { return needsTruncation(limit, e) }) { - return attr - } - newV := make([]attribute.Value, len(v)) - for i, elem := range v { - newV[i] = TruncateValue(limit, elem) - } - return attr.Key.Slice(newV...) + attr.Value, _ = truncateSliceValue(limit, attr.Value) case attribute.MAP: - v := attr.Value.AsMap() - if !slices.ContainsFunc(v, func(kv attribute.KeyValue) bool { return needsTruncation(limit, kv.Value) }) { - return attr - } - newV := make([]attribute.KeyValue, len(v)) - for i, elem := range v { - elem.Value = TruncateValue(limit, elem.Value) - newV[i] = elem - } - return attr.Key.Map(newV...) + attr.Value, _ = truncateMapValue(limit, attr.Value) } return attr } @@ -76,85 +57,275 @@ func TruncateValue(limit int, v attribute.Value) attribute.Value { return v } + // Match Truncate's direct scalar path to avoid paying for the recursive, + // multi-result transform when no composite traversal is needed. switch v.Type() { case attribute.STRING: return attribute.StringValue(truncate(limit, v.AsString())) + case attribute.BYTESLICE: + s := v.AsString() + if len(s) > limit { + return attribute.ByteSliceValue([]byte(s[:limit])) + } case attribute.STRINGSLICE: - ss := v.AsStringSlice() - for i := range ss { - ss[i] = truncate(limit, ss[i]) + v, _ = truncateStringSliceValue(limit, v) + case attribute.SLICE: + v, _ = truncateSliceValue(limit, v) + case attribute.MAP: + v, _ = truncateMapValue(limit, v) + } + return v +} + +// truncateValue traverses composite values once and rebuilds them lazily on +// the first changed child. Recursion provides O(depth) temporary stack space +// without forcing a heap allocation on the common no-op path. +func truncateValue(limit int, v attribute.Value) (attribute.Value, bool) { + switch v.Type() { + case attribute.STRING: + s := v.AsString() + truncated := truncate(limit, s) + if truncated != s { + return attribute.StringValue(truncated), true } - return attribute.StringSliceValue(ss) + case attribute.STRINGSLICE: + return truncateStringSliceValue(limit, v) case attribute.BYTESLICE: // len(v.AsString()) is identical to len(v.AsByteSlice()) but // avoids allocating the full slice before truncation. s := v.AsString() - if limit >= 0 && len(s) > limit { - return attribute.ByteSliceValue([]byte(s[:limit])) + if len(s) > limit { + return attribute.ByteSliceValue([]byte(s[:limit])), true } case attribute.SLICE: - sl := v.AsSlice() - if !slices.ContainsFunc(sl, func(e attribute.Value) bool { return needsTruncation(limit, e) }) { - return v + return truncateSliceValue(limit, v) + case attribute.MAP: + return truncateMapValue(limit, v) + } + return v, false +} + +func truncateStringSliceValue(limit int, value attribute.Value) (attribute.Value, bool) { + storage := valueStorage(value) + switch values := storage.(type) { + case [0]string: + return value, false + case [1]string: + return truncateStrings(limit, value, values[:]) + case [2]string: + return truncateStrings(limit, value, values[:]) + case [3]string: + return truncateStrings(limit, value, values[:]) + default: + array := reflect.ValueOf(storage) + if array.Kind() != reflect.Array || array.Type().Elem() != stringType { + return value, false } - newSl := make([]attribute.Value, len(sl)) - for i, elem := range sl { - newSl[i] = TruncateValue(limit, elem) + return truncateStringArray(limit, value, array) + } +} + +func truncateStrings(limit int, value attribute.Value, values []string) (attribute.Value, bool) { + var truncated []string + for i, s := range values { + newS := truncate(limit, s) + if truncated != nil { + truncated[i] = newS + continue } - return attribute.SliceValue(newSl...) - case attribute.MAP: - m := v.AsMap() - if !slices.ContainsFunc(m, func(kv attribute.KeyValue) bool { return needsTruncation(limit, kv.Value) }) { - return v + if newS == s { + continue } - newM := make([]attribute.KeyValue, len(m)) - for i, elem := range m { - elem.Value = TruncateValue(limit, elem.Value) - newM[i] = elem + + truncated = make([]string, len(values)) + copy(truncated, values[:i]) + truncated[i] = newS + } + if truncated == nil { + return value, false + } + return attribute.StringSliceValue(truncated), true +} + +func truncateStringArray(limit int, value attribute.Value, values reflect.Value) (attribute.Value, bool) { + var truncated []string + for i := range values.Len() { + s := values.Index(i).String() + newS := truncate(limit, s) + if truncated != nil { + truncated[i] = newS + continue + } + if newS == s { + continue + } + + truncated = make([]string, values.Len()) + for j := range i { + truncated[j] = values.Index(j).String() } - return attribute.MapValue(newM...) + truncated[i] = newS } - return v + if truncated == nil { + return value, false + } + return attribute.StringSliceValue(truncated), true } -// stringNeedsTruncation reports whether s would be modified by truncate for the -// given limit. -func stringNeedsTruncation(limit int, s string) bool { - if limit < 0 || len(s) <= limit { - return false +func truncateSliceValue(limit int, value attribute.Value) (attribute.Value, bool) { + storage := valueStorage(value) + switch values := storage.(type) { + case [0]attribute.Value: + return value, false + case [1]attribute.Value: + return truncateValueSlice(limit, value, values[:]) + case [2]attribute.Value: + return truncateValueSlice(limit, value, values[:]) + case [3]attribute.Value: + return truncateValueSlice(limit, value, values[:]) + case [4]attribute.Value: + return truncateValueSlice(limit, value, values[:]) + case [5]attribute.Value: + return truncateValueSlice(limit, value, values[:]) + default: + array := reflect.ValueOf(storage) + if array.Kind() != reflect.Array || array.Type().Elem() != valueType { + return value, false + } + return truncateValueArray(limit, value, array) } - return utf8.RuneCountInString(s) > limit || !utf8.ValidString(s) } -// needsTruncation reports whether v would be modified by TruncateValue for the -// given limit. -func needsTruncation(limit int, v attribute.Value) bool { - switch v.Type() { - case attribute.STRING: - return stringNeedsTruncation(limit, v.AsString()) - case attribute.BYTESLICE: - // len(v.AsString()) is identical to len(v.AsByteSlice()) but - // avoids memory allocation. - if limit >= 0 && len(v.AsString()) > limit { - return true +func truncateValueSlice(limit int, value attribute.Value, values []attribute.Value) (attribute.Value, bool) { + var truncated []attribute.Value + for i, elem := range values { + newElem, changed := truncateValue(limit, elem) + if truncated != nil { + truncated[i] = newElem + continue } - case attribute.STRINGSLICE: - for _, s := range v.AsStringSlice() { - if stringNeedsTruncation(limit, s) { - return true - } + if !changed { + continue } - case attribute.SLICE: - return slices.ContainsFunc(v.AsSlice(), func(e attribute.Value) bool { return needsTruncation(limit, e) }) - case attribute.MAP: - return slices.ContainsFunc( - v.AsMap(), - func(kv attribute.KeyValue) bool { return needsTruncation(limit, kv.Value) }, - ) + + truncated = make([]attribute.Value, len(values)) + copy(truncated, values[:i]) + truncated[i] = newElem + } + if truncated == nil { + return value, false + } + return attribute.SliceValue(truncated...), true +} + +func truncateValueArray(limit int, value attribute.Value, values reflect.Value) (attribute.Value, bool) { + var truncated []attribute.Value + for i := range values.Len() { + elem := values.Index(i).Interface().(attribute.Value) + newElem, changed := truncateValue(limit, elem) + if truncated != nil { + truncated[i] = newElem + continue + } + if !changed { + continue + } + + truncated = make([]attribute.Value, values.Len()) + for j := range i { + truncated[j] = values.Index(j).Interface().(attribute.Value) + } + truncated[i] = newElem + } + if truncated == nil { + return value, false + } + return attribute.SliceValue(truncated...), true +} + +func truncateMapValue(limit int, value attribute.Value) (attribute.Value, bool) { + storage := valueStorage(value) + switch keyValues := storage.(type) { + case [0]attribute.KeyValue: + return value, false + case [1]attribute.KeyValue: + return truncateKeyValueSlice(limit, value, keyValues[:]) + case [2]attribute.KeyValue: + return truncateKeyValueSlice(limit, value, keyValues[:]) + case [3]attribute.KeyValue: + return truncateKeyValueSlice(limit, value, keyValues[:]) + case [4]attribute.KeyValue: + return truncateKeyValueSlice(limit, value, keyValues[:]) + case [5]attribute.KeyValue: + return truncateKeyValueSlice(limit, value, keyValues[:]) + default: + array := reflect.ValueOf(storage) + if array.Kind() != reflect.Array || array.Type().Elem() != keyValueType { + return value, false + } + return truncateKeyValueArray(limit, value, array) + } +} + +func truncateKeyValueSlice( + limit int, + value attribute.Value, + keyValues []attribute.KeyValue, +) (attribute.Value, bool) { + var truncated []attribute.KeyValue + for i, kv := range keyValues { + newValue, changed := truncateValue(limit, kv.Value) + if changed { + kv.Value = newValue + } + if truncated != nil { + truncated[i] = kv + continue + } + if !changed { + continue + } + + truncated = make([]attribute.KeyValue, len(keyValues)) + copy(truncated, keyValues[:i]) + truncated[i] = kv + } + if truncated == nil { + return value, false } - return false + return attribute.MapValue(truncated...), true } +func truncateKeyValueArray(limit int, value attribute.Value, keyValues reflect.Value) (attribute.Value, bool) { + var truncated []attribute.KeyValue + for i := range keyValues.Len() { + kv := keyValues.Index(i).Interface().(attribute.KeyValue) + newValue, changed := truncateValue(limit, kv.Value) + if changed { + kv.Value = newValue + } + if truncated != nil { + truncated[i] = kv + continue + } + if !changed { + continue + } + + truncated = make([]attribute.KeyValue, keyValues.Len()) + for j := range i { + truncated[j] = keyValues.Index(j).Interface().(attribute.KeyValue) + } + truncated[i] = kv + } + if truncated == nil { + return value, false + } + return attribute.MapValue(truncated...), true +} + +var stringType = reflect.TypeFor[string]() + // truncate returns a version of s truncated according to limit. // // If limit is negative, it returns the original string. @@ -168,7 +339,7 @@ func truncate(limit int, s string) string { // This prioritizes performance in the following order based on the most // common expected use cases. // - // - Values shorter than the default limit (128). + // - Values whose byte length does not exceed the limit. // - Strings with valid encodings that exceed the limit. // - No limit. // - Strings with invalid encodings that exceed the limit. @@ -188,14 +359,27 @@ func truncate(limit int, s string) string { continue } + // A zero limit also truncates a leading invalid byte or U+FFFD. + if limit == 0 { + return "" + } + // Range reports RuneError for both an invalid byte and a valid U+FFFD. + // Only a size-1 decoding indicates invalid UTF-8. _, size := utf8.DecodeRuneInString(s[i:]) if size == 1 { - // Invalid encoding. + // Removing this byte makes len(s)-1 an upper bound for a rebuilt + // result. Keep the valid prefix before rescanning s[i:]. b.Grow(len(s) - 1) _, _ = b.WriteString(s[:i]) s = s[i:] break } + + // A valid U+FFFD still consumes one character of the limit. + count++ + if count > limit { + return s[:i] + } } // Fast-path, no invalid input. @@ -203,7 +387,9 @@ func truncate(limit int, s string) string { return s } - // Truncate while validating UTF-8. + // The builder holds the valid prefix before the first invalid byte, and + // count includes its runes. Skip malformed bytes without counting them + // while copying the remaining valid runes up to the limit. for i := 0; i < len(s) && count < limit; { c := s[i] if c < utf8.RuneSelf { diff --git a/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go b/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go index dcd7280ac9..1ab929a3ab 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go +++ b/vendor/go.opentelemetry.io/otel/sdk/resource/resource.go @@ -90,7 +90,7 @@ func NewSchemaless(attrs ...attribute.KeyValue) *Resource { return &Resource{} } - attrs, _ = attrnorm.KeyValues(attrs) + attrs, _ = attrnorm.KeyValuesDedup(attrs) // Ensure attributes comply with the specification: // https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/common/README.md#attribute diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/batch_span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/batch_span_processor.go index 896ed517f0..b55750a844 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/batch_span_processor.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/batch_span_processor.go @@ -47,6 +47,8 @@ type BSP struct { processedQueueFullOpts []metric.AddOption } +// NewBSP creates new instrumentation for a BatchSpanProcessor. +// It returns nil if observability is not enabled. func NewBSP(id int64, qLen func() int64, qMax int64) (*BSP, error) { if !x.Observability.Enabled() { return nil, nil @@ -108,12 +110,16 @@ func NewBSP(id int64, qLen func() int64, qMax int64) (*BSP, error) { }, err } +// Shutdown unregisters the callbacks registered by NewBSP. func (b *BSP) Shutdown() error { return b.reg.Unregister() } +// Processed records n spans as having finished processing successfully. func (b *BSP) Processed(ctx context.Context, n int64) { b.processed.Add(ctx, n, b.processedOpts...) } +// ProcessedQueueFull records n spans as having finished processing with a +// queue-full error. func (b *BSP) ProcessedQueueFull(ctx context.Context, n int64) { b.processed.Add(ctx, n, b.processedQueueFullOpts...) } diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/tracer.go b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/tracer.go index 3428aa8949..16fad3c43d 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/tracer.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/internal/observ/tracer.go @@ -30,6 +30,8 @@ type Tracer struct { started metric.Int64Counter } +// NewTracer creates new instrumentation for a Tracer. +// It returns an empty, disabled Tracer if observability is not enabled. func NewTracer() (Tracer, error) { if !x.Observability.Enabled() { return Tracer{}, nil @@ -52,8 +54,11 @@ func NewTracer() (Tracer, error) { return Tracer{enabled: true, live: l.Inst(), started: s.Inst()}, err } +// Enabled returns whether observability is enabled for t. func (t Tracer) Enabled() bool { return t.enabled } +// SpanStarted records the start of span, which was created with psc as its +// parent span context. func (t Tracer) SpanStarted(ctx context.Context, psc trace.SpanContext, span trace.Span) { if !t.started.Enabled(ctx) { return @@ -84,10 +89,12 @@ func (t Tracer) SpanStarted(ctx context.Context, psc trace.SpanContext, span tra t.started.Add(ctx, 1, opts...) } +// SpanLive records span as a live span. func (t Tracer) SpanLive(ctx context.Context, span trace.Span) { t.spanLive(ctx, 1, span) } +// SpanEnded records span as no longer being live. func (t Tracer) SpanEnded(ctx context.Context, span trace.Span) { t.spanLive(ctx, -1, span) } diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go b/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go index 6b2368413a..ce615a1b02 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/provider.go @@ -150,7 +150,10 @@ func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.T return noop.NewTracerProvider().Tracer(name, opts...) } c := trace.NewTracerConfig(opts...) - attrs, _ := attrnorm.Set(c.InstrumentationAttributes()) + attrs, _, _ := attrnorm.SetDedupLimitDepth( + c.InstrumentationAttributes(), + p.spanLimits.AttributeValueDepthLimit, + ) if name == "" { name = defaultTracerName } @@ -255,13 +258,14 @@ func (p *TracerProvider) UnregisterSpanProcessor(sp SpanProcessor) { idx = i } } - if stopOnce != nil { - stopOnce.state.Do(func() { - if err := sp.Shutdown(context.Background()); err != nil { - otel.Handle(err) - } - }) + if stopOnce == nil { + return } + stopOnce.state.Do(func() { + if err := sp.Shutdown(context.Background()); err != nil { + otel.Handle(err) + } + }) if len(spss) > 1 { copy(spss[idx:], spss[idx+1:]) } @@ -429,6 +433,29 @@ func WithSampler(s Sampler) TracerProviderOption { }) } +// WithAttributeValueDepthLimit sets the maximum allowed depth for attribute +// values. Depth starts at one for the top-level value and increments when +// descending into an array element or map value. An array or map beyond this +// depth is replaced by an empty value. +// +// This limit applies to span, event, link, and instrumentation scope +// attributes processed by this TracerProvider. It does not apply to Resource +// attributes. +// +// Setting this to zero means the default limit of 64 is used. Setting this to +// a negative value means no limit is applied. +// +// There is no environment variable for this limit. +func WithAttributeValueDepthLimit(limit int) TracerProviderOption { + if limit == 0 { + limit = DefaultAttributeValueDepthLimit + } + return traceProviderOptionFunc(func(cfg tracerProviderConfig) tracerProviderConfig { + cfg.spanLimits.AttributeValueDepthLimit = limit + return cfg + }) +} + // WithSpanLimits returns a TracerProviderOption that configures a // TracerProvider to use the SpanLimits sl. These SpanLimits bound any Span // created by a Tracer from the TracerProvider. @@ -448,6 +475,9 @@ func WithSpanLimits(sl SpanLimits) TracerProviderOption { if sl.AttributeValueLengthLimit <= 0 { sl.AttributeValueLengthLimit = DefaultAttributeValueLengthLimit } + if sl.AttributeValueDepthLimit <= 0 { + sl.AttributeValueDepthLimit = DefaultAttributeValueDepthLimit + } if sl.AttributeCountLimit <= 0 { sl.AttributeCountLimit = DefaultAttributeCountLimit } @@ -473,13 +503,14 @@ func WithSpanLimits(sl SpanLimits) TracerProviderOption { // TracerProvider to use these limits. These limits bound any Span created by // a Tracer from the TracerProvider. // -// The limits will be used as-is. Zero or negative values will not be changed -// to the default value like WithSpanLimits does. Setting a limit to zero will -// effectively disable the related resource it limits and setting to a -// negative value will mean that resource is unlimited. Consequentially, this -// means that the zero-value SpanLimits will disable all span resources. -// Because of this, limits should be constructed using NewSpanLimits and -// updated accordingly. +// The limits will be used as-is, except that an AttributeValueDepthLimit of +// zero means the default limit is used. Other zero or negative values will not +// be changed to the default value like WithSpanLimits does. Setting a limit to +// zero will effectively disable the related resource it limits and setting to +// a negative value will mean that resource is unlimited. Consequentially, the +// zero-value SpanLimits will disable all span resources except the attribute +// value depth limit. Because of this, limits should be constructed using +// NewSpanLimits and updated accordingly. // // If this or WithSpanLimits are not provided, the TracerProvider will use the // limits defined by environment variables, or the defaults if unset. Refer to @@ -525,5 +556,8 @@ func ensureValidTracerProviderConfig(cfg tracerProviderConfig) tracerProviderCon if cfg.resource == nil { cfg.resource = resource.Default() } + if cfg.spanLimits.AttributeValueDepthLimit == 0 { + cfg.spanLimits.AttributeValueDepthLimit = DefaultAttributeValueDepthLimit + } return cfg } diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/sampler_env.go b/vendor/go.opentelemetry.io/otel/sdk/trace/sampler_env.go index b0fa94ed2d..76cca5cd5b 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/sampler_env.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/sampler_env.go @@ -46,14 +46,13 @@ func (e samplerArgParseError) Unwrap() error { } func samplerFromEnv() (Sampler, error) { - sampler, ok := os.LookupEnv(tracesSamplerKey) - if !ok { + sampler := strings.ToLower(strings.TrimSpace(os.Getenv(tracesSamplerKey))) + if sampler == "" { return nil, nil } - sampler = strings.ToLower(strings.TrimSpace(sampler)) - samplerArg, hasSamplerArg := os.LookupEnv(tracesSamplerArgKey) - samplerArg = strings.TrimSpace(samplerArg) + samplerArg := strings.TrimSpace(os.Getenv(tracesSamplerArgKey)) + hasSamplerArg := samplerArg != "" switch sampler { case samplerAlwaysOn: diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go b/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go index 97985c4988..1e6be12486 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go @@ -104,10 +104,15 @@ func (ssp *simpleSpanProcessor) Shutdown(ctx context.Context) error { // span would need to be exported. Meaning, OnEnd would be called and // try acquiring the lock that is held here. ssp.exporterMu.Lock() - done, shutdown := stopFunc(ssp.exporter) + exp := ssp.exporter ssp.exporter = nil ssp.exporterMu.Unlock() + if exp == nil { + return + } + + done, shutdown := stopFunc(exp) go shutdown() // Wait for the exporter to shut down or the deadline to expire. diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/snapshot.go b/vendor/go.opentelemetry.io/otel/sdk/trace/snapshot.go index 8893dc39f1..6e0c06be5e 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/snapshot.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/snapshot.go @@ -12,7 +12,7 @@ import ( "go.opentelemetry.io/otel/trace" ) -// snapshot is an record of a spans state at a particular checkpointed time. +// snapshot is a record of a span's state at a particular checkpointed time. // It is used as a read-only representation of that state. type snapshot struct { name string diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span.go index aae9773145..05920ab872 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/span.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/span.go @@ -278,8 +278,11 @@ func (s *recordingSpan) SetAttributes(attributes ...attribute.KeyValue) { s.addDroppedAttr(1) continue } - a = dedupAttr(a) - a = attrnorm.Truncate(s.tracer.provider.spanLimits.AttributeValueLengthLimit, a) + a = normAttr( + a, + s.tracer.provider.spanLimits.AttributeValueDepthLimit, + s.tracer.provider.spanLimits.AttributeValueLengthLimit, + ) s.attributes = append(s.attributes, a) s.attributesDirty = true } @@ -353,8 +356,11 @@ func (s *recordingSpan) addOverCapAttrs(limit int, attrs []attribute.KeyValue) { if idx, ok := exists[a.Key]; ok { // Perform all updates before dropping, even when at capacity. - a = dedupAttr(a) - a = attrnorm.Truncate(s.tracer.provider.spanLimits.AttributeValueLengthLimit, a) + a = normAttr( + a, + s.tracer.provider.spanLimits.AttributeValueDepthLimit, + s.tracer.provider.spanLimits.AttributeValueLengthLimit, + ) s.attributes[idx] = a continue } @@ -364,22 +370,27 @@ func (s *recordingSpan) addOverCapAttrs(limit int, attrs []attribute.KeyValue) { // updates are checked and performed. s.addDroppedAttr(1) } else { - a = dedupAttr(a) - a = attrnorm.Truncate(s.tracer.provider.spanLimits.AttributeValueLengthLimit, a) + a = normAttr( + a, + s.tracer.provider.spanLimits.AttributeValueDepthLimit, + s.tracer.provider.spanLimits.AttributeValueLengthLimit, + ) s.attributes = append(s.attributes, a) exists[a.Key] = len(s.attributes) - 1 } } } -func dedupAttr(attr attribute.KeyValue) attribute.KeyValue { +func normAttr(attr attribute.KeyValue, depthLimit, lengthLimit int) attribute.KeyValue { switch attr.Value.Type() { case attribute.SLICE, attribute.MAP: - attr, _ = attrnorm.KeyValue(attr) - return attr - default: - return attr + if depthLimit < 0 { + attr, _ = attrnorm.KeyValueDedup(attr) + } else { + attr, _, _ = attrnorm.KeyValueDedupLimitDepth(attr, depthLimit) + } } + return attrnorm.Truncate(lengthLimit, attr) } // End ends the span. This method does nothing if the span is already ended or @@ -483,9 +494,7 @@ func (s *recordingSpan) RecordError(err error, opts ...trace.EventOption) { return } - s.mu.Lock() - defer s.mu.Unlock() - if !s.isRecording() { + if !s.IsRecording() { return } @@ -501,7 +510,7 @@ func (s *recordingSpan) RecordError(err error, opts ...trace.EventOption) { )) } - s.addEvent(semconv.ExceptionEventName, opts...) + s.AddEvent(semconv.ExceptionEventName, opts...) } func typeStr(i any) string { @@ -540,7 +549,10 @@ func (s *recordingSpan) AddEvent(name string, o ...trace.EventOption) { // This method assumes s.mu.Lock is held by the caller. func (s *recordingSpan) addEvent(name string, o ...trace.EventOption) { c := trace.NewEventConfig(o...) - attrs, _ := attrnorm.KeyValues(c.Attributes()) + attrs, _, _ := attrnorm.KeyValuesDedupLimitDepth( + c.Attributes(), + s.tracer.provider.spanLimits.AttributeValueDepthLimit, + ) e := Event{Name: name, Attributes: attrs, Time: c.Timestamp()} // Discard attributes over limit. @@ -580,7 +592,7 @@ func (s *recordingSpan) Name() string { return s.name } -// Name returns the SpanContext of this span's parent span. +// Parent returns the SpanContext of this span's parent span. func (s *recordingSpan) Parent() trace.SpanContext { s.mu.Lock() defer s.mu.Unlock() @@ -720,7 +732,10 @@ func (s *recordingSpan) AddLink(link trace.Link) { return } - attrs, _ := attrnorm.KeyValues(link.Attributes) + attrs, _, _ := attrnorm.KeyValuesDedupLimitDepth( + link.Attributes, + s.tracer.provider.spanLimits.AttributeValueDepthLimit, + ) l := Link{SpanContext: link.SpanContext, Attributes: attrs} // Discard attributes over limit. diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span_limits.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span_limits.go index 5ee15a8848..3069e22692 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/trace/span_limits.go +++ b/vendor/go.opentelemetry.io/otel/sdk/trace/span_limits.go @@ -10,6 +10,10 @@ const ( // attribute value length, unlimited. DefaultAttributeValueLengthLimit = -1 + // DefaultAttributeValueDepthLimit is the default maximum allowed depth for + // nested attribute values. + DefaultAttributeValueDepthLimit = 64 + // DefaultAttributeCountLimit is the default maximum number of attributes // a span can have. DefaultAttributeCountLimit = 128 @@ -43,6 +47,20 @@ type SpanLimits struct { // Setting this to a negative value means no limit is applied. AttributeValueLengthLimit int + // AttributeValueDepthLimit is the maximum allowed depth for an attribute + // value. Depth starts at one for the top-level value and increments when + // descending into an array element or map value. An array or map beyond this + // depth is replaced by an empty value. + // + // This limit applies to span, event, link, and instrumentation scope + // attributes processed by a TracerProvider. It does not apply to Resource + // attributes. + // + // Setting this to zero means the default limit is used. + // + // Setting this to a negative value means no limit is applied. + AttributeValueDepthLimit int + // AttributeCountLimit is the maximum allowed span attribute count. Any // attribute added to a span once this limit is reached will be dropped. // @@ -88,12 +106,15 @@ type SpanLimits struct { AttributePerLinkCountLimit int } -// NewSpanLimits returns a SpanLimits with all limits set to the value their -// corresponding environment variable holds, or the default if unset. +// NewSpanLimits returns a SpanLimits with all limits set to their default. +// Limits with a corresponding environment variable are set from the +// environment when the variable is defined. // // • AttributeValueLengthLimit: OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT // (default: unlimited) // +// • AttributeValueDepthLimit: default 64 (no environment variable) +// // • AttributeCountLimit: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT (default: 128) // // • EventCountLimit: OTEL_SPAN_EVENT_COUNT_LIMIT (default: 128) @@ -107,6 +128,7 @@ type SpanLimits struct { func NewSpanLimits() SpanLimits { return SpanLimits{ AttributeValueLengthLimit: env.SpanAttributeValueLength(DefaultAttributeValueLengthLimit), + AttributeValueDepthLimit: DefaultAttributeValueDepthLimit, AttributeCountLimit: env.SpanAttributeCount(DefaultAttributeCountLimit), EventCountLimit: env.SpanEventCount(DefaultEventCountLimit), LinkCountLimit: env.SpanLinkCount(DefaultLinkCountLimit), diff --git a/vendor/go.opentelemetry.io/otel/sdk/version.go b/vendor/go.opentelemetry.io/otel/sdk/version.go index 621d6d7e62..2335ebdd76 100644 --- a/vendor/go.opentelemetry.io/otel/sdk/version.go +++ b/vendor/go.opentelemetry.io/otel/sdk/version.go @@ -6,5 +6,5 @@ package sdk // Version is the current release version of the OpenTelemetry SDK in use. func Version() string { - return "1.46.0" + return "1.47.0" } diff --git a/vendor/modules.txt b/vendor/modules.txt index a240e4c66b..8be07415ea 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -583,8 +583,8 @@ go.etcd.io/bbolt/internal/freelist ## explicit; go 1.24.0 go.opentelemetry.io/auto/sdk go.opentelemetry.io/auto/sdk/internal/telemetry -# go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.71.0 -## explicit; go 1.25.0 +# go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.72.0 +## explicit; go 1.26.0 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal # go.opentelemetry.io/otel v1.47.0 @@ -616,8 +616,8 @@ go.opentelemetry.io/otel/log/embedded go.opentelemetry.io/otel/metric go.opentelemetry.io/otel/metric/embedded go.opentelemetry.io/otel/metric/noop -# go.opentelemetry.io/otel/sdk v1.46.0 -## explicit; go 1.25.0 +# go.opentelemetry.io/otel/sdk v1.47.0 +## explicit; go 1.26.0 go.opentelemetry.io/otel/sdk go.opentelemetry.io/otel/sdk/instrumentation go.opentelemetry.io/otel/sdk/internal/attrnorm @@ -714,8 +714,8 @@ golang.org/x/tools/internal/pkgbits golang.org/x/tools/internal/stdlib golang.org/x/tools/internal/typesinternal golang.org/x/tools/internal/versions -# google.golang.org/genproto/googleapis/rpc v0.0.0-20260825221802-da73d73af1c5 -## explicit; go 1.25.0 +# google.golang.org/genproto/googleapis/rpc v0.0.0-20260928230214-8a89bd6388cc +## explicit; go 1.26.0 google.golang.org/genproto/googleapis/rpc/status # google.golang.org/grpc v1.84.0 ## explicit; go 1.25.0