diff --git a/.chloggen/cwlogs_useragent.yaml b/.chloggen/cwlogs_useragent.yaml new file mode 100755 index 000000000000..ad05889023e7 --- /dev/null +++ b/.chloggen/cwlogs_useragent.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: awsemfexporter/awscloudwatchlogsexporter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add component name to user agent header for outgoing put log even requests + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [29595] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/exporter/awscloudwatchlogsexporter/exporter.go b/exporter/awscloudwatchlogsexporter/exporter.go index bd9467b7e981..f7c8c14fbf58 100644 --- a/exporter/awscloudwatchlogsexporter/exporter.go +++ b/exporter/awscloudwatchlogsexporter/exporter.go @@ -22,6 +22,7 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "go.uber.org/zap" + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awscloudwatchlogsexporter/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs" ) @@ -60,7 +61,7 @@ func newCwLogsPusher(expConfig *Config, params exp.CreateSettings) (*cwlExporter } // create CWLogs client with aws session config - svcStructuredLog := cwlogs.NewClient(params.Logger, awsConfig, params.BuildInfo, expConfig.LogGroupName, expConfig.LogRetention, expConfig.Tags, session) + svcStructuredLog := cwlogs.NewClient(params.Logger, awsConfig, params.BuildInfo, expConfig.LogGroupName, expConfig.LogRetention, expConfig.Tags, session, metadata.Type) collectorIdentifier, err := uuid.NewRandom() if err != nil { diff --git a/exporter/awsemfexporter/emf_exporter.go b/exporter/awsemfexporter/emf_exporter.go index 4b482399affc..bd4719977e0c 100644 --- a/exporter/awsemfexporter/emf_exporter.go +++ b/exporter/awsemfexporter/emf_exporter.go @@ -18,6 +18,7 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs" ) @@ -55,7 +56,7 @@ func newEmfExporter(config *Config, set exporter.CreateSettings) (*emfExporter, } // create CWLogs client with aws session config - svcStructuredLog := cwlogs.NewClient(set.Logger, awsConfig, set.BuildInfo, config.LogGroupName, config.LogRetention, config.Tags, session) + svcStructuredLog := cwlogs.NewClient(set.Logger, awsConfig, set.BuildInfo, config.LogGroupName, config.LogRetention, config.Tags, session, metadata.Type) collectorIdentifier, err := uuid.NewRandom() if err != nil { diff --git a/internal/aws/cwlogs/cwlog_client.go b/internal/aws/cwlogs/cwlog_client.go index 4c58fe80065d..07da718a3fb3 100644 --- a/internal/aws/cwlogs/cwlog_client.go +++ b/internal/aws/cwlogs/cwlog_client.go @@ -45,10 +45,10 @@ func newCloudWatchLogClient(svc cloudwatchlogsiface.CloudWatchLogsAPI, logRetent } // NewClient create Client -func NewClient(logger *zap.Logger, awsConfig *aws.Config, buildInfo component.BuildInfo, logGroupName string, logRetention int64, tags map[string]*string, sess *session.Session) *Client { +func NewClient(logger *zap.Logger, awsConfig *aws.Config, buildInfo component.BuildInfo, logGroupName string, logRetention int64, tags map[string]*string, sess *session.Session, componentName string) *Client { client := cloudwatchlogs.New(sess, awsConfig) client.Handlers.Build.PushBackNamed(handler.RequestStructuredLogHandler) - client.Handlers.Build.PushFrontNamed(newCollectorUserAgentHandler(buildInfo, logGroupName)) + client.Handlers.Build.PushFrontNamed(newCollectorUserAgentHandler(buildInfo, logGroupName, componentName)) return newCloudWatchLogClient(client, logRetention, tags, logger) } @@ -175,10 +175,10 @@ func (client *Client) CreateStream(logGroup, streamName *string) error { return nil } -func newCollectorUserAgentHandler(buildInfo component.BuildInfo, logGroupName string) request.NamedHandler { - fn := request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version) +func newCollectorUserAgentHandler(buildInfo component.BuildInfo, logGroupName string, componentName string) request.NamedHandler { + fn := request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version, componentName) if matchContainerInsightsPattern(logGroupName) { - fn = request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version, "ContainerInsights") + fn = request.MakeAddToUserAgentHandler(buildInfo.Command, buildInfo.Version, componentName, "ContainerInsights") } return request.NamedHandler{ Name: "otel.collector.UserAgentHandler", diff --git a/internal/aws/cwlogs/cwlog_client_test.go b/internal/aws/cwlogs/cwlog_client_test.go index 8694799822a4..919d1f59607f 100644 --- a/internal/aws/cwlogs/cwlog_client_test.go +++ b/internal/aws/cwlogs/cwlog_client_test.go @@ -533,7 +533,7 @@ func TestLogUnknownError(t *testing.T) { func TestUserAgent(t *testing.T) { logger := zap.NewNop() - + expectedComponentName := "mockComponentName" tests := []struct { name string buildInfo component.BuildInfo @@ -544,44 +544,44 @@ func TestUserAgent(t *testing.T) { "emptyLogGroup", component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"}, "", - "opentelemetry-collector-contrib/1.0", + fmt.Sprintf("opentelemetry-collector-contrib/1.0 (%s)", expectedComponentName), }, { "buildInfoCommandUsed", component.BuildInfo{Command: "test-collector-contrib", Version: "1.0"}, "", - "test-collector-contrib/1.0", + fmt.Sprintf("test-collector-contrib/1.0 (%s)", expectedComponentName), }, { "non container insights", component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.1"}, "test-group", - "opentelemetry-collector-contrib/1.1", + fmt.Sprintf("opentelemetry-collector-contrib/1.1 (%s)", expectedComponentName), }, { "container insights EKS", component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"}, "/aws/containerinsights/eks-cluster-name/performance", - "opentelemetry-collector-contrib/1.0 (ContainerInsights)", + fmt.Sprintf("opentelemetry-collector-contrib/1.0 (%s; ContainerInsights)", expectedComponentName), }, { "container insights ECS", component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"}, "/aws/ecs/containerinsights/ecs-cluster-name/performance", - "opentelemetry-collector-contrib/1.0 (ContainerInsights)", + fmt.Sprintf("opentelemetry-collector-contrib/1.0 (%s; ContainerInsights)", expectedComponentName), }, { "container insights prometheus", component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"}, "/aws/containerinsights/cluster-name/prometheus", - "opentelemetry-collector-contrib/1.0 (ContainerInsights)", + fmt.Sprintf("opentelemetry-collector-contrib/1.0 (%s; ContainerInsights)", expectedComponentName), }, } - session, _ := session.NewSession() + testSession, _ := session.NewSession() for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - cwlog := NewClient(logger, &aws.Config{}, tc.buildInfo, tc.logGroupName, 0, map[string]*string{}, session) + cwlog := NewClient(logger, &aws.Config{}, tc.buildInfo, tc.logGroupName, 0, map[string]*string{}, testSession, expectedComponentName) logClient := cwlog.svc.(*cloudwatchlogs.CloudWatchLogs) req := request.New(aws.Config{}, metadata.ClientInfo{}, logClient.Handlers, nil, &request.Operation{