summaryrefslogtreecommitdiff
path: root/vendor/go.opentelemetry.io/otel/sdk/trace/span.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.opentelemetry.io/otel/sdk/trace/span.go')
-rw-r--r--vendor/go.opentelemetry.io/otel/sdk/trace/span.go39
1 files changed, 9 insertions, 30 deletions
diff --git a/vendor/go.opentelemetry.io/otel/sdk/trace/span.go b/vendor/go.opentelemetry.io/otel/sdk/trace/span.go
index 85bc702a0..c44f6b926 100644
--- a/vendor/go.opentelemetry.io/otel/sdk/trace/span.go
+++ b/vendor/go.opentelemetry.io/otel/sdk/trace/span.go
@@ -1,16 +1,5 @@
// Copyright The OpenTelemetry Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+// SPDX-License-Identifier: Apache-2.0
package trace // import "go.opentelemetry.io/otel/sdk/trace"
@@ -20,6 +9,7 @@ import (
"reflect"
"runtime"
rt "runtime/trace"
+ "slices"
"strings"
"sync"
"time"
@@ -208,16 +198,6 @@ func (s *recordingSpan) SetStatus(code codes.Code, description string) {
s.status = status
}
-// ensureAttributesCapacity inlines functionality from slices.Grow
-// so that we can avoid needing to import golang.org/x/exp for go1.20.
-// Once support for go1.20 is dropped, we can use slices.Grow available since go1.21 instead.
-// Tracking issue: https://github.com/open-telemetry/opentelemetry-go/issues/4819.
-func (s *recordingSpan) ensureAttributesCapacity(minCapacity int) {
- if n := minCapacity - cap(s.attributes); n > 0 {
- s.attributes = append(s.attributes[:cap(s.attributes)], make([]attribute.KeyValue, n)...)[:len(s.attributes)]
- }
-}
-
// SetAttributes sets attributes of this span.
//
// If a key from attributes already exists the value associated with that key
@@ -252,7 +232,7 @@ func (s *recordingSpan) SetAttributes(attributes ...attribute.KeyValue) {
// Otherwise, add without deduplication. When attributes are read they
// will be deduplicated, optimizing the operation.
- s.ensureAttributesCapacity(len(s.attributes) + len(attributes))
+ s.attributes = slices.Grow(s.attributes, len(s.attributes)+len(attributes))
for _, a := range attributes {
if !a.Valid() {
// Drop all invalid attributes.
@@ -288,12 +268,8 @@ func (s *recordingSpan) addOverCapAttrs(limit int, attrs []attribute.KeyValue) {
// Now that s.attributes is deduplicated, adding unique attributes up to
// the capacity of s will not over allocate s.attributes.
- if sum := len(attrs) + len(s.attributes); sum < limit {
- // After support for go1.20 is dropped, simplify if-else to min(sum, limit).
- s.ensureAttributesCapacity(sum)
- } else {
- s.ensureAttributesCapacity(limit)
- }
+ sum := len(attrs) + len(s.attributes)
+ s.attributes = slices.Grow(s.attributes, min(sum, limit))
for _, a := range attrs {
if !a.Valid() {
// Drop all invalid attributes.
@@ -653,7 +629,7 @@ func (s *recordingSpan) Resource() *resource.Resource {
return s.tracer.provider.resource
}
-func (s *recordingSpan) addLink(link trace.Link) {
+func (s *recordingSpan) AddLink(link trace.Link) {
if !s.IsRecording() || !link.SpanContext.IsValid() {
return
}
@@ -827,6 +803,9 @@ func (nonRecordingSpan) RecordError(error, ...trace.EventOption) {}
// AddEvent does nothing.
func (nonRecordingSpan) AddEvent(string, ...trace.EventOption) {}
+// AddLink does nothing.
+func (nonRecordingSpan) AddLink(trace.Link) {}
+
// SetName does nothing.
func (nonRecordingSpan) SetName(string) {}