Skip to content

Commit

Permalink
Merge branch 'main' into feat/otellogr-add-benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Nov 26, 2024
2 parents a3ecacf + 0da64d1 commit 719992b
Show file tree
Hide file tree
Showing 22 changed files with 260 additions and 178 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ linters:
- unconvert
- unparam
- unused
- usestdlibvars

issues:
# Maximum issues count per one linter.
Expand Down Expand Up @@ -68,6 +69,7 @@ issues:
linters:
- gosec
- perfsprint
- usestdlibvars
include:
# revive exported should have comment or be unexported.
- EXC0012
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Fixed

- Fix broken AWS presigned URLs when using instrumentation in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#5975)
- Fixed the value for configuring the OTLP exporter to use `grpc` instead of `grpc/protobuf` in `go.opentelemetry.io/contrib/config`. (#6338)
- Allow marshaling types in `go.opentelemetry.io/contrib/config`. (#6347)

Expand Down
2 changes: 1 addition & 1 deletion detectors/azure/azurevm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (detector *ResourceDetector) getJSONMetadata(ctx context.Context) ([]byte,

client := http.Client{Transport: pTransport}

req, err := http.NewRequestWithContext(ctx, "GET", detector.endpoint, nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, detector.endpoint, nil)
if err != nil {
return nil, false, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ replace (
require (
github.com/aws/aws-lambda-go v1.47.0
github.com/aws/aws-sdk-go-v2/config v1.28.5
github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0
go.opentelemetry.io/contrib/detectors/aws/lambda v0.57.0
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda v0.57.0
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.5 h1:wtpJ4zcwr
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.5/go.mod h1:qu/W9HXQbbQ4+1+JcZp0ZNPV31ym537ZJN+fiS7Ti8E=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.5 h1:P1doBzv5VEg1ONxnJss1Kh5ZG/ewoIE4MQtKKc6Crgg=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.5/go.mod h1:NOP+euMW7W3Ukt28tAxPuoWao4rhhqJD3QEBk7oCg7w=
github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0 h1:bFpcqdwtAEsgpZXvkTxIThFQx/EM0oV6kXmfFIGjxME=
github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0/go.mod h1:ralv4XawHjEMaHOWnTFushl0WRqim/gQWesAMF6hTow=
github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0 h1:Q2ax8S21clKOnHhhr933xm3JxdJebql+R7aNo7p7GBQ=
github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0/go.mod h1:ralv4XawHjEMaHOWnTFushl0WRqim/gQWesAMF6hTow=
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1 h1:39WvSrVq9DD6UHkD+fx5x19P5KpRQfNdtgReDVNbelc=
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1/go.mod h1:3gwPzC9LER/BTQdQZ3r6dUktb1rSjABF1D3Sr6nS7VU=
github.com/aws/aws-sdk-go-v2/service/sso v1.24.6 h1:3zu537oLmsPfDMyjnUS2g+F2vITgy5pB74tHI+JBNoM=
Expand Down
36 changes: 18 additions & 18 deletions instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ func (m otelMiddlewares) initializeMiddlewareAfter(stack *middleware.Stack) erro
middleware.After)
}

func (m otelMiddlewares) finalizeMiddlewareAfter(stack *middleware.Stack) error {
return stack.Finalize.Add(middleware.FinalizeMiddlewareFunc("OTelFinalizeMiddleware", func(
ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
// Propagate the Trace information by injecting it into the HTTP request.
switch req := in.Request.(type) {
case *smithyhttp.Request:
m.propagator.Inject(ctx, propagation.HeaderCarrier(req.Header))
default:
}

return next.HandleFinalize(ctx, in)
}),
middleware.After)
}

func (m otelMiddlewares) deserializeMiddleware(stack *middleware.Stack) error {
return stack.Deserialize.Add(middleware.DeserializeMiddlewareFunc("OTelDeserializeMiddleware", func(
ctx context.Context, in middleware.DeserializeInput, next middleware.DeserializeHandler) (
Expand All @@ -108,23 +125,6 @@ func (m otelMiddlewares) deserializeMiddleware(stack *middleware.Stack) error {
middleware.Before)
}

func (m otelMiddlewares) finalizeMiddleware(stack *middleware.Stack) error {
return stack.Finalize.Add(middleware.FinalizeMiddlewareFunc("OTelFinalizeMiddleware", func(
ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
// Propagate the Trace information by injecting it into the HTTP request.
switch req := in.Request.(type) {
case *smithyhttp.Request:
m.propagator.Inject(ctx, propagation.HeaderCarrier(req.Header))
default:
}

return next.HandleFinalize(ctx, in)
}),
middleware.Before)
}

func spanName(serviceID, operation string) string {
spanName := serviceID
if operation != "" {
Expand Down Expand Up @@ -155,5 +155,5 @@ func AppendMiddlewares(apiOptions *[]func(*middleware.Stack) error, opts ...Opti
propagator: cfg.TextMapPropagator,
attributeSetter: cfg.AttributeSetter,
}
*apiOptions = append(*apiOptions, m.initializeMiddlewareBefore, m.initializeMiddlewareAfter, m.finalizeMiddleware, m.deserializeMiddleware)
*apiOptions = append(*apiOptions, m.initializeMiddlewareBefore, m.initializeMiddlewareAfter, m.finalizeMiddlewareAfter, m.deserializeMiddleware)
}
110 changes: 107 additions & 3 deletions instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import (
"context"
"net/http"
"testing"
"time"

"github.com/aws/smithy-go/middleware"
smithyhttp "github.com/aws/smithy-go/transport/http"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/aws/aws-sdk-go-v2/aws"
awsSignerV4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"

"go.opentelemetry.io/otel/propagation"
)

Expand All @@ -33,7 +37,7 @@ func (p mockPropagator) Fields() []string {
return []string{}
}

func Test_otelMiddlewares_finalizeMiddleware(t *testing.T) {
func Test_otelMiddlewares_finalizeMiddlewareAfter(t *testing.T) {
stack := middleware.Stack{
Finalize: middleware.NewFinalizeStep(),
}
Expand All @@ -47,7 +51,7 @@ func Test_otelMiddlewares_finalizeMiddleware(t *testing.T) {
propagator: propagator,
}

err := m.finalizeMiddleware(&stack)
err := m.finalizeMiddlewareAfter(&stack)
require.NoError(t, err)

input := &smithyhttp.Request{
Expand All @@ -60,7 +64,8 @@ func Test_otelMiddlewares_finalizeMiddleware(t *testing.T) {
return nil, middleware.Metadata{}, nil
})

_, _, _ = stack.Finalize.HandleMiddleware(context.Background(), input, next)
_, _, err = stack.Finalize.HandleMiddleware(context.Background(), input, next)
require.NoError(t, err)

// Assert header has been updated with injected values
key := http.CanonicalHeaderKey(propagator.injectKey)
Expand All @@ -70,6 +75,105 @@ func Test_otelMiddlewares_finalizeMiddleware(t *testing.T) {
assert.Contains(t, input.Header[key], value)
}

func Test_otelMiddlewares_finalizeMiddlewareAfter_Noop(t *testing.T) {
stack := middleware.Stack{
Finalize: middleware.NewFinalizeStep(),
}

propagator := mockPropagator{
injectKey: "mock-key",
injectValue: "mock-value",
}

m := otelMiddlewares{
propagator: propagator,
}

err := m.finalizeMiddlewareAfter(&stack)
require.NoError(t, err)

// Non request input should trigger noop
input := &struct{}{}

next := middleware.HandlerFunc(func(ctx context.Context, input interface{}) (output interface{}, metadata middleware.Metadata, err error) {
return nil, middleware.Metadata{}, nil
})

_, _, err = stack.Finalize.HandleMiddleware(context.Background(), input, next)
assert.NoError(t, err)
}

type mockCredentialsProvider struct{}

func (mockCredentialsProvider) Retrieve(context.Context) (aws.Credentials, error) {
return aws.Credentials{}, nil
}

type mockHTTPPresigner struct{}

func (f mockHTTPPresigner) PresignHTTP(
ctx context.Context, credentials aws.Credentials, r *http.Request,
payloadHash string, service string, region string, signingTime time.Time,
optFns ...func(*awsSignerV4.SignerOptions),
) (
url string, signedHeader http.Header, err error,
) {
return "mock-url", nil, nil
}

func Test_otelMiddlewares_presignedRequests(t *testing.T) {
stack := middleware.Stack{
Finalize: middleware.NewFinalizeStep(),
}

presignedHTTPMiddleware := awsSignerV4.NewPresignHTTPRequestMiddleware(awsSignerV4.PresignHTTPRequestMiddlewareOptions{
CredentialsProvider: mockCredentialsProvider{},
Presigner: mockHTTPPresigner{},
LogSigning: false,
})

err := stack.Finalize.Add(presignedHTTPMiddleware, middleware.After)
require.NoError(t, err)

propagator := mockPropagator{
injectKey: "mock-key",
injectValue: "mock-value",
}

m := otelMiddlewares{
propagator: propagator,
}

err = m.finalizeMiddlewareAfter(&stack)
require.NoError(t, err)

input := &smithyhttp.Request{
Request: &http.Request{
Header: http.Header{},
},
}

next := middleware.HandlerFunc(func(ctx context.Context, input interface{}) (output interface{}, metadata middleware.Metadata, err error) {
return nil, middleware.Metadata{}, nil
})

ctx := awsSignerV4.SetPayloadHash(context.Background(), "mock-hash")
url, _, err := stack.Finalize.HandleMiddleware(ctx, input, next)

// verify we actually went through the presign flow
require.NoError(t, err)
presignedReq, ok := url.(*awsSignerV4.PresignedHTTPRequest)
require.True(t, ok)
require.Equal(t, "mock-url", presignedReq.URL)

// Assert header has NOT been updated with injected values, as the presign middleware should short circuit
key := http.CanonicalHeaderKey(propagator.injectKey)
value := propagator.injectValue

assert.NotContains(t, input.Header, key)
assert.NotContains(t, input.Header[key], value)
}

func Test_Span_name(t *testing.T) {
serviceID1 := ""
serviceID2 := "ServiceID"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/aws/aws-sdk-go-v2 v1.32.5
github.com/aws/aws-sdk-go-v2/config v1.28.5
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.37.1
github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0
github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.32.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.5 h1:wtpJ4zcwr
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.5/go.mod h1:qu/W9HXQbbQ4+1+JcZp0ZNPV31ym537ZJN+fiS7Ti8E=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.5 h1:P1doBzv5VEg1ONxnJss1Kh5ZG/ewoIE4MQtKKc6Crgg=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.5/go.mod h1:NOP+euMW7W3Ukt28tAxPuoWao4rhhqJD3QEBk7oCg7w=
github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0 h1:bFpcqdwtAEsgpZXvkTxIThFQx/EM0oV6kXmfFIGjxME=
github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0/go.mod h1:ralv4XawHjEMaHOWnTFushl0WRqim/gQWesAMF6hTow=
github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0 h1:Q2ax8S21clKOnHhhr933xm3JxdJebql+R7aNo7p7GBQ=
github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0/go.mod h1:ralv4XawHjEMaHOWnTFushl0WRqim/gQWesAMF6hTow=
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1 h1:39WvSrVq9DD6UHkD+fx5x19P5KpRQfNdtgReDVNbelc=
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1/go.mod h1:3gwPzC9LER/BTQdQZ3r6dUktb1rSjABF1D3Sr6nS7VU=
github.com/aws/aws-sdk-go-v2/service/sso v1.24.6 h1:3zu537oLmsPfDMyjnUS2g+F2vITgy5pB74tHI+JBNoM=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
)

require (
github.com/bytedance/sonic v1.12.4 // indirect
github.com/bytedance/sonic v1.12.5 // indirect
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/bytedance/sonic v1.12.4 h1:9Csb3c9ZJhfUWeMtpCDCq6BUoH5ogfDFLUgQ/jG+R0k=
github.com/bytedance/sonic v1.12.4/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic v1.12.5 h1:hoZxY8uW+mT+OpkcUWw4k0fDINtOcVavEsGfzwzFU/w=
github.com/bytedance/sonic v1.12.5/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.2.1 h1:1GgorWTqf12TA8mma4DDSbaQigE2wOgQo7iCjjJv3+E=
github.com/bytedance/sonic/loader v0.2.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
Expand Down
97 changes: 0 additions & 97 deletions instrumentation/github.com/gin-gonic/gin/otelgin/gintrace_test.go

This file was deleted.

Loading

0 comments on commit 719992b

Please sign in to comment.