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

Change the way that X-Ray exporter annotation converter work #31732

Merged
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
27 changes: 27 additions & 0 deletions .chloggen/xray_exporter_allow_dot_annotation.yaml
Original file line number Diff line number Diff line change
@@ -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: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: awsxrayexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: change x-ray exporter's translator to make "." split annotation pass as-is

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [31732]

# (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: In the past, X-Ray doesn’t support “.”. So we have a translator in x-ray export to translates it to “_” before sending traces to X-Ray Service. | To match otel naming style, x-ray service team decide to change their service to support both "." type and "" type of naming. In this case the translator that translate "." to "" is no-longer needed. This PR change the way this translator work | X-Ray PMs agree on rolling out this change by using feature-gate

# 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]
12 changes: 12 additions & 0 deletions exporter/awsxrayexporter/internal/translator/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

awsP "github.com/aws/aws-sdk-go/aws"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
conventions "go.opentelemetry.io/collector/semconv/v1.8.0"
Expand Down Expand Up @@ -46,6 +47,15 @@ var (
reInvalidSpanCharacters = regexp.MustCompile(`[^ 0-9\p{L}N_.:/%&#=+,\-@]`)
)

var (
remoteXrayExporterDotConverter = featuregate.GlobalRegistry().MustRegister(
"exporter.xray.allowDot",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("X-Ray Exporter will no longer convert . to _ in annotation keys when this feature gate is enabled. "),
featuregate.WithRegisterFromVersion("v0.97.0"),
)
)

const (
// defaultMetadataNamespace is used for non-namespaced non-indexed attributes.
defaultMetadataNamespace = "default"
Expand Down Expand Up @@ -518,6 +528,8 @@ func fixAnnotationKey(key string) string {
fallthrough
case 'a' <= r && r <= 'z':
return r
case remoteXrayExporterDotConverter.IsEnabled() && r == '.':
return r
default:
return '_'
}
Expand Down
103 changes: 102 additions & 1 deletion exporter/awsxrayexporter/internal/translator/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
conventions "go.opentelemetry.io/collector/semconv/v1.8.0"
Expand Down Expand Up @@ -407,9 +408,30 @@ func TestFixSegmentName(t *testing.T) {
}

func TestFixAnnotationKey(t *testing.T) {
err := featuregate.GlobalRegistry().Set("exporter.xray.allowDot", false)
assert.Nil(t, err)

validKey := "Key_1"
fixedKey := fixAnnotationKey(validKey)
assert.Equal(t, validKey, fixedKey)
validDotKey := "Key.1"
fixedDotKey := fixAnnotationKey(validDotKey)
assert.Equal(t, "Key_1", fixedDotKey)
invalidKey := "Key@1"
fixedKey = fixAnnotationKey(invalidKey)
assert.Equal(t, "Key_1", fixedKey)
}

func TestFixAnnotationKeyWithAllowDot(t *testing.T) {
err := featuregate.GlobalRegistry().Set("exporter.xray.allowDot", true)
assert.Nil(t, err)

validKey := "Key_1"
fixedKey := fixAnnotationKey(validKey)
assert.Equal(t, validKey, fixedKey)
validDotKey := "Key.1"
fixedDotKey := fixAnnotationKey(validDotKey)
assert.Equal(t, validDotKey, fixedDotKey)
invalidKey := "Key@1"
fixedKey = fixAnnotationKey(invalidKey)
assert.Equal(t, "Key_1", fixedKey)
Expand Down Expand Up @@ -562,12 +584,14 @@ func TestSpanWithAttributesSegmentMetadata(t *testing.T) {
}

func TestResourceAttributesCanBeIndexed(t *testing.T) {
err := featuregate.GlobalRegistry().Set("exporter.xray.allowDot", false)
assert.Nil(t, err)

spanName := "/api/locations"
parentSpanID := newSegmentID()
attributes := make(map[string]any)
resource := constructDefaultResource()
span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeError, "OK", attributes)

segment, _ := MakeSegment(span, resource, []string{
"otel.resource.string.key",
"otel.resource.int.key",
Expand All @@ -583,7 +607,39 @@ func TestResourceAttributesCanBeIndexed(t *testing.T) {
assert.Equal(t, int64(10), segment.Annotations["otel_resource_int_key"])
assert.Equal(t, 5.0, segment.Annotations["otel_resource_double_key"])
assert.Equal(t, true, segment.Annotations["otel_resource_bool_key"])
expectedMap := make(map[string]any)
expectedMap["key1"] = int64(1)
expectedMap["key2"] = "value"
// Maps and arrays are not supported for annotations so still in metadata.
assert.Equal(t, expectedMap, segment.Metadata["default"]["otel.resource.map.key"])
expectedArr := []any{"foo", "bar"}
assert.Equal(t, expectedArr, segment.Metadata["default"]["otel.resource.array.key"])
}

func TestResourceAttributesCanBeIndexedWithAllowDot(t *testing.T) {
err := featuregate.GlobalRegistry().Set("exporter.xray.allowDot", true)
assert.Nil(t, err)

spanName := "/api/locations"
parentSpanID := newSegmentID()
attributes := make(map[string]any)
resource := constructDefaultResource()
span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeError, "OK", attributes)
segment, _ := MakeSegment(span, resource, []string{
"otel.resource.string.key",
"otel.resource.int.key",
"otel.resource.double.key",
"otel.resource.bool.key",
"otel.resource.map.key",
"otel.resource.array.key",
}, false, nil, false)

assert.NotNil(t, segment)
assert.Equal(t, 4, len(segment.Annotations))
assert.Equal(t, "string", segment.Annotations["otel.resource.string.key"])
assert.Equal(t, int64(10), segment.Annotations["otel.resource.int.key"])
assert.Equal(t, 5.0, segment.Annotations["otel.resource.double.key"])
assert.Equal(t, true, segment.Annotations["otel.resource.bool.key"])
expectedMap := make(map[string]any)
expectedMap["key1"] = int64(1)
expectedMap["key2"] = "value"
Expand Down Expand Up @@ -615,6 +671,9 @@ func TestResourceAttributesNotIndexedIfSubsegment(t *testing.T) {
}

func TestSpanWithSpecialAttributesAsListed(t *testing.T) {
err := featuregate.GlobalRegistry().Set("exporter.xray.allowDot", false)
assert.Nil(t, err)

spanName := "/api/locations"
parentSpanID := newSegmentID()
attributes := make(map[string]any)
Expand All @@ -631,7 +690,30 @@ func TestSpanWithSpecialAttributesAsListed(t *testing.T) {
assert.Equal(t, "rpc_method_val", segment.Annotations["rpc_method"])
}

func TestSpanWithSpecialAttributesAsListedWithAllowDot(t *testing.T) {
err := featuregate.GlobalRegistry().Set("exporter.xray.allowDot", true)
assert.Nil(t, err)

spanName := "/api/locations"
parentSpanID := newSegmentID()
attributes := make(map[string]any)
attributes[awsxray.AWSOperationAttribute] = "aws_operation_val"
attributes[conventions.AttributeRPCMethod] = "rpc_method_val"
resource := constructDefaultResource()
span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeError, "OK", attributes)

segment, _ := MakeSegment(span, resource, []string{awsxray.AWSOperationAttribute, conventions.AttributeRPCMethod}, false, nil, false)

assert.NotNil(t, segment)
assert.Equal(t, 2, len(segment.Annotations))
assert.Equal(t, "aws_operation_val", segment.Annotations[awsxray.AWSOperationAttribute])
assert.Equal(t, "rpc_method_val", segment.Annotations[conventions.AttributeRPCMethod])
}

func TestSpanWithSpecialAttributesAsListedAndIndexAll(t *testing.T) {
err := featuregate.GlobalRegistry().Set("exporter.xray.allowDot", false)
assert.Nil(t, err)

spanName := "/api/locations"
parentSpanID := newSegmentID()
attributes := make(map[string]any)
Expand All @@ -647,6 +729,25 @@ func TestSpanWithSpecialAttributesAsListedAndIndexAll(t *testing.T) {
assert.Equal(t, "rpc_method_val", segment.Annotations["rpc_method"])
}

func TestSpanWithSpecialAttributesAsListedAndIndexAllWithAllowDot(t *testing.T) {
err := featuregate.GlobalRegistry().Set("exporter.xray.allowDot", true)
assert.Nil(t, err)

spanName := "/api/locations"
parentSpanID := newSegmentID()
attributes := make(map[string]any)
attributes[awsxray.AWSOperationAttribute] = "aws_operation_val"
attributes[conventions.AttributeRPCMethod] = "rpc_method_val"
resource := constructDefaultResource()
span := constructServerSpan(parentSpanID, spanName, ptrace.StatusCodeError, "OK", attributes)

segment, _ := MakeSegment(span, resource, []string{awsxray.AWSOperationAttribute, conventions.AttributeRPCMethod}, true, nil, false)

assert.NotNil(t, segment)
assert.Equal(t, "aws_operation_val", segment.Annotations[awsxray.AWSOperationAttribute])
assert.Equal(t, "rpc_method_val", segment.Annotations[conventions.AttributeRPCMethod])
}

func TestSpanWithSpecialAttributesNotListedAndIndexAll(t *testing.T) {
spanName := "/api/locations"
parentSpanID := newSegmentID()
Expand Down
Loading