From acaf06e9a6386f3ecdbe0730708febafab62a36c Mon Sep 17 00:00:00 2001 From: Carol Abadeer <60774943+carolabadeer@users.noreply.github.com> Date: Wed, 1 Feb 2023 17:09:56 -0800 Subject: [PATCH] User-agent redesign - add additional information to user-agent (#188) * Added additional information to user-agent string * Update CHANGELOG --------- Co-authored-by: William Armiros <54150514+willarmiros@users.noreply.github.com> --- CHANGELOG.md | 1 + pkg/conn/xray_client.go | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c6d8d..bf254b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## 3.3.6 (2023-02-01) +- User-agent redesign - add additional information to user-agent [PR #188](https://github.com/aws/aws-xray-daemon/pull/188) - Remove custom backoff logic for sending segments [PR #186](https://github.com/aws/aws-xray-daemon/pull/186) ## 3.3.5 (2022-09-22) diff --git a/pkg/conn/xray_client.go b/pkg/conn/xray_client.go index c0f81fb..1bf67ba 100644 --- a/pkg/conn/xray_client.go +++ b/pkg/conn/xray_client.go @@ -11,20 +11,25 @@ package conn import ( "os" + "runtime" "strconv" "strings" "time" - "github.com/aws/aws-xray-daemon/pkg/cfg" - "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/xray" + "github.com/aws/aws-xray-daemon/pkg/cfg" log "github.com/cihub/seelog" ) +// Constant prefixes used to identify information in user-agent +const agentPrefix = "xray-agent/xray-daemon/" +const execEnvPrefix = " exec-env/" +const osPrefix = " OS/" + // XRay defines X-Ray api call structure. type XRay interface { PutTraceSegments(input *xray.PutTraceSegmentsInput) (*xray.PutTraceSegmentsOutput, error) @@ -51,9 +56,16 @@ func NewXRay(awsConfig *aws.Config, s *session.Session) XRay { x := xray.New(s, awsConfig) log.Debugf("Using Endpoint: %s", x.Endpoint) + execEnv := os.Getenv("AWS_EXECUTION_ENV") + if execEnv == "" { + execEnv = "UNKNOWN" + } + + osInformation := runtime.GOOS + "-" + runtime.GOARCH + x.Handlers.Build.PushBackNamed(request.NamedHandler{ Name: "tracing.XRayVersionUserAgentHandler", - Fn: request.MakeAddToUserAgentHandler("xray", cfg.Version, os.Getenv("AWS_EXECUTION_ENV")), + Fn: request.MakeAddToUserAgentFreeFormHandler(agentPrefix + cfg.Version + execEnvPrefix + execEnv + osPrefix + osInformation), }) x.Handlers.Sign.PushFrontNamed(request.NamedHandler{