Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- The deprecated `SemVersion` function is removed in `go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho/test`, use `Version` function instead. (#7090)
- The deprecated `SemVersion` function is removed in `go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful`, use `Version` function instead. (#7091)
- The deprecated `SemVersion` function is removed in `go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful/test`, use `Version` function instead. (#7092)
- The deprecated `SemVersion` function is removed in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`, use `Version` function instead. (#7154)
- The deprecated `UnaryServerInterceptor` in `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` is removed, use `NewServerHandler` instead. (#7115)
- The deprecated `AttributeSetter` function is removed in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`, use the `AttributeBuilder` function instead. (#7137)
- The deprecated `SemVersion` function is removed in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`, use `Version` function instead. (#7154)

<!-- Released section -->
<!-- Don't change this section unless doing release -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ const (

type spanTimestampKey struct{}

// AttributeSetter returns an array of KeyValue pairs, it can be used to set custom attributes.
//
// Deprecated: Use AttributeBuilder instead. This will be removed in a future release.
type AttributeSetter func(context.Context, middleware.InitializeInput) []attribute.KeyValue

// AttributeBuilder returns an array of KeyValue pairs, it can be used to set custom attributes.
type AttributeBuilder func(ctx context.Context, in middleware.InitializeInput, out middleware.InitializeOutput) []attribute.KeyValue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
package otelaws // import "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws"

import (
"context"

"github.com/aws/smithy-go/middleware"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
Expand Down Expand Up @@ -52,19 +47,6 @@ func WithTextMapPropagator(propagator propagation.TextMapPropagator) Option {
})
}

// WithAttributeSetter specifies an attribute setter function for setting service specific attributes.
// If none is specified, the service will be determined by the DefaultAttributeBuilder function and the corresponding attributes will be included.
func WithAttributeSetter(attributesetters ...AttributeSetter) Option {
var attributeBuilders []AttributeBuilder
for _, setter := range attributesetters {
attributeBuilders = append(attributeBuilders, func(ctx context.Context, in middleware.InitializeInput, out middleware.InitializeOutput) []attribute.KeyValue {
return setter(ctx, in)
})
}

return WithAttributeBuilder(attributeBuilders...)
}

// WithAttributeBuilder specifies an attribute setter function for setting service specific attributes.
// If none is specified, the service will be determined by the DefaultAttributeBuilder function and the corresponding attributes will be included.
func WithAttributeBuilder(attributeBuilders ...AttributeBuilder) Option {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,90 +105,6 @@ func TestDynamodbTags(t *testing.T) {
})
}

//nolint:staticcheck // Tests for deprecated AttributeSetter that will be removed in the future release.
func TestDynamodbTagsCustomSetter(t *testing.T) {
cases := struct {
responseStatus int
expectedRegion string
expectedStatusCode int
expectedError codes.Code
}{
responseStatus: http.StatusOK,
expectedRegion: "us-west-2",
expectedStatusCode: http.StatusOK,
}

server := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(cases.responseStatus)
}))
defer server.Close()

t.Run("dynamodb tags", func(t *testing.T) {
sr := tracetest.NewSpanRecorder()
provider := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr))

svc := dynamodb.New(dynamodb.Options{
Region: cases.expectedRegion,
BaseEndpoint: &server.URL,
AuthSchemeResolver: &dynamoDBAuthResolver{},
Retryer: aws.NopRetryer{},
})

mycustomsetter := otelaws.AttributeSetter(func(context.Context, middleware.InitializeInput) []attribute.KeyValue {
customAttributes := []attribute.KeyValue{
{
Key: "customattribute2key",
Value: attribute.StringValue("customattribute2value"),
},
{
Key: "customattribute1key",
Value: attribute.StringValue("customattribute1value"),
},
}

return customAttributes
})

_, err := svc.GetItem(context.Background(), &dynamodb.GetItemInput{
TableName: aws.String("table1"),
ConsistentRead: aws.Bool(false),
ProjectionExpression: aws.String("test"),
Key: map[string]dtypes.AttributeValue{
"id": &dtypes.AttributeValueMemberS{Value: "test"},
},
}, func(options *dynamodb.Options) {
otelaws.AppendMiddlewares(
&options.APIOptions, otelaws.WithAttributeSetter(otelaws.DynamoDBAttributeSetter, mycustomsetter), otelaws.WithTracerProvider(provider))
})

if cases.expectedError == codes.Unset {
assert.NoError(t, err)
} else {
assert.Error(t, err)
}

spans := sr.Ended()
require.Len(t, spans, 1)
span := spans[0]

assert.Equal(t, "DynamoDB.GetItem", span.Name())
assert.Equal(t, trace.SpanKindClient, span.SpanKind())
attrs := span.Attributes()
assert.Contains(t, attrs, attribute.Int("http.status_code", cases.expectedStatusCode))
assert.Contains(t, attrs, attribute.String("rpc.service", "DynamoDB"))
assert.Contains(t, attrs, attribute.String("aws.region", cases.expectedRegion))
assert.Contains(t, attrs, attribute.String("rpc.method", "GetItem"))
assert.Contains(t, attrs, attribute.StringSlice(
"aws.dynamodb.table_names", []string{"table1"},
))
assert.Contains(t, attrs, attribute.String("aws.dynamodb.projection", "test"))
assert.Contains(t, attrs, attribute.Bool("aws.dynamodb.consistent_read", false))
assert.Contains(t, attrs, attribute.String("customattribute2key", "customattribute2value"))
assert.Contains(t, attrs, attribute.String("customattribute1key", "customattribute1value"))
})
}

func TestDynamodbTagsCustomBuilder(t *testing.T) {
cases := struct {
responseStatus int
Expand Down