From 23013d39e8d948e9541e3de0407ab38b8a679c8a Mon Sep 17 00:00:00 2001 From: Jonathan Lee <107072447+jj22ee@users.noreply.github.com> Date: Thu, 1 Aug 2024 11:59:25 -0700 Subject: [PATCH] [exporter/awsemf] Update ApplicationSignals log group name and adjust AWS service name (#33798) **Description:** Cherry-picking from downstream: https://github.com/amazon-contributing/opentelemetry-collector-contrib/pull/197 Changes: - unify the log group name to /aws/application-signals/data. - rename Application Signals metric namespace. - removed OTelLib name label from EMF log --------- Co-authored-by: Mengyi Zhou (bjrara) --- ...ppsignals-and-awssdk-name-adjustments.yaml | 27 +++++++++++++++++ exporter/awsemfexporter/config_test.go | 26 ++++++++-------- exporter/awsemfexporter/emf_exporter.go | 4 +-- .../internal/translator/segment.go | 8 +++-- .../internal/translator/segment_test.go | 30 ++++++++++++++++++- internal/aws/cwlogs/cwlog_client_test.go | 11 +++++-- 6 files changed, 86 insertions(+), 20 deletions(-) create mode 100644 .chloggen/appsignals-and-awssdk-name-adjustments.yaml diff --git a/.chloggen/appsignals-and-awssdk-name-adjustments.yaml b/.chloggen/appsignals-and-awssdk-name-adjustments.yaml new file mode 100644 index 000000000000..536df16f4d56 --- /dev/null +++ b/.chloggen/appsignals-and-awssdk-name-adjustments.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 + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: AWS EMF Exporter to update ApplicationSignals log group name and namespace, and adjust AWS service name prefix logic in spans + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [33798] + +# (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/awsemfexporter/config_test.go b/exporter/awsemfexporter/config_test.go index 99dba3d90510..bd7e7710a542 100644 --- a/exporter/awsemfexporter/config_test.go +++ b/exporter/awsemfexporter/config_test.go @@ -271,7 +271,7 @@ func TestNoDimensionRollupFeatureGate(t *testing.T) { _ = featuregate.GlobalRegistry().Set("awsemf.nodimrollupdefault", false) } -func TestIsAppSignalsEnabled(t *testing.T) { +func TestIsApplicationSignalsEnabled(t *testing.T) { tests := []struct { name string metricNameSpace string @@ -279,27 +279,27 @@ func TestIsAppSignalsEnabled(t *testing.T) { expectedResult bool }{ { - "validAppSignalsEMF", - "AppSignals", - "/aws/appsignals/eks", + "validApplicationSignalsEMF", + "ApplicationSignals", + "/aws/application-signals/data", true, }, { - "invalidAppSignalsLogsGroup", - "AppSignals", - "/nonaws/appsignals/eks", + "invalidApplicationSignalsLogsGroup", + "ApplicationSignals", + "/nonaws/application-signals/eks", false, }, { - "invalidAppSignalsMetricNamespace", - "NonAppSignals", - "/aws/appsignals/eks", + "invalidApplicationSignalsMetricNamespace", + "NonApplicationSignals", + "/aws/application-signals/data", false, }, { - "invalidAppSignalsEMF", - "NonAppSignals", - "/nonaws/appsignals/eks", + "invalidApplicationSignalsEMF", + "NonApplicationSignals", + "/nonaws/application-signals/eks", false, }, { diff --git a/exporter/awsemfexporter/emf_exporter.go b/exporter/awsemfexporter/emf_exporter.go index 7b5bda9d8176..67eb53b3356d 100644 --- a/exporter/awsemfexporter/emf_exporter.go +++ b/exporter/awsemfexporter/emf_exporter.go @@ -29,8 +29,8 @@ const ( outputDestinationStdout = "stdout" // AppSignals EMF config - appSignalsMetricNamespace = "AppSignals" - appSignalsLogGroupNamePrefix = "/aws/appsignals/" + appSignalsMetricNamespace = "ApplicationSignals" + appSignalsLogGroupNamePrefix = "/aws/application-signals/" ) type emfExporter struct { diff --git a/exporter/awsxrayexporter/internal/translator/segment.go b/exporter/awsxrayexporter/internal/translator/segment.go index 9460f1ce5c67..9bb8582d14c6 100644 --- a/exporter/awsxrayexporter/internal/translator/segment.go +++ b/exporter/awsxrayexporter/internal/translator/segment.go @@ -770,8 +770,12 @@ func fixAnnotationKey(key string) string { } func trimAwsSdkPrefix(name string, span ptrace.Span) string { - if isAwsSdkSpan(span) && strings.HasPrefix(name, "AWS.SDK.") { - return strings.TrimPrefix(name, "AWS.SDK.") + if isAwsSdkSpan(span) { + if strings.HasPrefix(name, "AWS.SDK.") { + return strings.TrimPrefix(name, "AWS.SDK.") + } else if strings.HasPrefix(name, "AWS::") { + return strings.TrimPrefix(name, "AWS::") + } } return name } diff --git a/exporter/awsxrayexporter/internal/translator/segment_test.go b/exporter/awsxrayexporter/internal/translator/segment_test.go index 8426e2e976ac..8b33edec28eb 100644 --- a/exporter/awsxrayexporter/internal/translator/segment_test.go +++ b/exporter/awsxrayexporter/internal/translator/segment_test.go @@ -1093,7 +1093,7 @@ func TestClientSpanWithAwsRemoteServiceName(t *testing.T) { assert.False(t, strings.Contains(jsonStr, "user")) } -func TestAwsSdkSpanWithAwsRemoteServiceName(t *testing.T) { +func TestAwsSdkSpanWithDeprecatedAwsRemoteServiceName(t *testing.T) { spanName := "DynamoDB.PutItem" parentSpanID := newSegmentID() user := "testingT" @@ -1121,6 +1121,34 @@ func TestAwsSdkSpanWithAwsRemoteServiceName(t *testing.T) { assert.False(t, strings.Contains(jsonStr, "user")) } +func TestAwsSdkSpanWithAwsRemoteServiceName(t *testing.T) { + spanName := "DynamoDB.PutItem" + parentSpanID := newSegmentID() + user := "testingT" + attributes := make(map[string]any) + attributes[conventions.AttributeRPCSystem] = "aws-api" + attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPScheme] = "https" + attributes[conventions.AttributeRPCService] = "DynamoDb" + attributes[awsRemoteService] = "AWS::DynamoDB" + + resource := constructDefaultResource() + span := constructClientSpan(parentSpanID, spanName, 0, "OK", attributes) + + segment, _ := MakeSegment(span, resource, nil, false, nil, false) + assert.Equal(t, "DynamoDB", *segment.Name) + assert.Equal(t, "subsegment", *segment.Type) + + jsonStr, err := MakeSegmentDocumentString(span, resource, nil, false, nil, false) + + assert.NotNil(t, jsonStr) + assert.Nil(t, err) + assert.True(t, strings.Contains(jsonStr, "DynamoDb")) + assert.False(t, strings.Contains(jsonStr, "DynamoDb.PutItem")) + assert.False(t, strings.Contains(jsonStr, user)) + assert.False(t, strings.Contains(jsonStr, "user")) +} + func TestProducerSpanWithAwsRemoteServiceName(t *testing.T) { spanName := "ABC.payment" parentSpanID := newSegmentID() diff --git a/internal/aws/cwlogs/cwlog_client_test.go b/internal/aws/cwlogs/cwlog_client_test.go index 36c5f30004d9..2832251e47e4 100644 --- a/internal/aws/cwlogs/cwlog_client_test.go +++ b/internal/aws/cwlogs/cwlog_client_test.go @@ -600,14 +600,14 @@ func TestUserAgent(t *testing.T) { { "validAppSignalsLogGroupAndAgentString", component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"}, - "/aws/appsignals", + "/aws/application-signals", []ClientOption{WithUserAgentExtras("AppSignals")}, fmt.Sprintf("opentelemetry-collector-contrib/1.0 (%s; AppSignals)", expectedComponentName), }, { "multipleAgentStringExtras", component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"}, - "/aws/appsignals", + "/aws/application-signals", []ClientOption{WithUserAgentExtras("abcde", "vwxyz", "12345")}, fmt.Sprintf("opentelemetry-collector-contrib/1.0 (%s; abcde; vwxyz; 12345)", expectedComponentName), }, @@ -618,6 +618,13 @@ func TestUserAgent(t *testing.T) { []ClientOption{WithUserAgentExtras("extra0", "extra1", "extra2")}, fmt.Sprintf("opentelemetry-collector-contrib/1.0 (%s; extra0; extra1; extra2; ContainerInsights)", expectedComponentName), }, + { + "validAppSignalsEMFEnabled", + component.BuildInfo{Command: "opentelemetry-collector-contrib", Version: "1.0"}, + "/aws/application-signals", + []ClientOption{WithUserAgentExtras("AppSignals")}, + fmt.Sprintf("opentelemetry-collector-contrib/1.0 (%s; AppSignals)", expectedComponentName), + }, } testSession, _ := session.NewSession()