Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: capture user-agent in metrics #2644

Merged
merged 1 commit into from
May 16, 2024
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
8 changes: 8 additions & 0 deletions .changelog/33f766393bb344b9b26b55846650e8a0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "33f76639-3bb3-44b9-b26b-55846650e8a0",
"type": "feature",
"description": "Capture user agent in internal metrics.",
"modules": [
"."
]
}
1 change: 1 addition & 0 deletions aws/middleware/private/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ type MetricData struct {
OperationName string
PartitionID string
Region string
UserAgent string
RequestContentLength int64
Stream StreamMetrics
Attempts []AttemptMetrics
Expand Down
3 changes: 3 additions & 0 deletions aws/middleware/private/metrics/middleware/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func WithMetricMiddlewares(
if err := timeSigning(stack); err != nil {
return err
}
if err := stack.Build.Add(&captureUserAgent{}, middleware.After); err != nil {
return err
}
return nil
}
}
29 changes: 29 additions & 0 deletions aws/middleware/private/metrics/middleware/user_agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package middleware

import (
"context"
"fmt"

"github.com/aws/aws-sdk-go-v2/aws/middleware/private/metrics"
"github.com/aws/smithy-go/middleware"
smithyhttp "github.com/aws/smithy-go/transport/http"
)

type captureUserAgent struct{}

func (*captureUserAgent) ID() string { return "captureUserAgent" }

func (*captureUserAgent) HandleBuild(
ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler,
) (
out middleware.BuildOutput, md middleware.Metadata, err error,
) {
r, ok := in.Request.(*smithyhttp.Request)
if !ok {
return out, md, fmt.Errorf("unexpected transport type %T", in.Request)
}

mctx := metrics.Context(ctx)
mctx.Data().UserAgent = r.Header.Get("User-Agent")
return next.HandleBuild(ctx, in)
}
Loading