Skip to content

Commit

Permalink
[receiver/awsxrayreceiver] Add local namespace support (open-telemetr…
Browse files Browse the repository at this point in the history
…y#31514)

**Description:**
Support local namespace in X-Ray subsegment. The subsegment with local
namespace will be translated into Internal span kind.

**Testing:**
Added unit test case with local namespace.
  • Loading branch information
vastin committed Apr 15, 2024
1 parent 7579382 commit 6876ca7
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .chloggen/xray-local-ns.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: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add support for local namespace in subsegment

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

# (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]
11 changes: 11 additions & 0 deletions internal/aws/xray/testdata/indepSubsegmentWithLocalNamespace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "localNamespaceTest",
"id": "53995c3f42cd8ad8",
"start_time": 1478293361.271,
"end_time": 1478293361.449,
"type": "subsegment",
"trace_id": "1-581cf771-a006649127e371903a2de979",
"parent_id": "defdfd9912dc5a56",
"namespace": "local",
"traced": true
}
4 changes: 3 additions & 1 deletion receiver/awsxrayreceiver/internal/translator/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
const (
validAWSNamespace = "aws"
validRemoteNamespace = "remote"
validLocalNamespace = "local"
)

func addNameAndNamespace(seg *awsxray.Segment, span ptrace.Span) error {
Expand All @@ -29,7 +30,7 @@ func addNameAndNamespace(seg *awsxray.Segment, span ptrace.Span) error {
span.SetKind(ptrace.SpanKindServer)
}

if seg.Namespace == nil {
if seg.Namespace == nil || *seg.Namespace == validLocalNamespace {
if span.Kind() == ptrace.SpanKindUnspecified {
span.SetKind(ptrace.SpanKindInternal)
}
Expand All @@ -49,6 +50,7 @@ func addNameAndNamespace(seg *awsxray.Segment, span ptrace.Span) error {

case validRemoteNamespace:
// no op

default:
return fmt.Errorf("unexpected namespace: %s", *seg.Namespace)
}
Expand Down
45 changes: 45 additions & 0 deletions receiver/awsxrayreceiver/internal/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,51 @@ func TestTranslation(t *testing.T) {
testCase+": translation should've failed")
},
},
{
testCase: "TranslateLocalNamespace",
samplePath: filepath.Join("../../../../internal/aws/xray", "testdata", "indepSubsegmentWithLocalNamespace.txt"),
expectedResourceAttrs: func(seg *awsxray.Segment) map[string]any {
return map[string]any{
conventions.AttributeServiceName: *seg.Name,
conventions.AttributeCloudProvider: "unknown",
}
},
expectedRecord: xray.TelemetryRecord{
SegmentsReceivedCount: aws.Int64(1),
SegmentsRejectedCount: aws.Int64(0),
},
propsPerSpan: func(_ string, _ *testing.T, seg *awsxray.Segment) []perSpanProperties {
attrs := pcommon.NewMap()
assert.NoError(t, attrs.FromRaw(map[string]any{
awsxray.AWSXRayTracedAttribute: true,
}))
res := perSpanProperties{
traceID: *seg.TraceID,
spanID: *seg.ID,
parentSpanID: seg.ParentID,
name: *seg.Name,
startTimeSec: *seg.StartTime,
endTimeSec: seg.EndTime,
spanKind: ptrace.SpanKindInternal,
spanStatus: spanSt{
code: ptrace.StatusCodeUnset,
},
attrs: attrs,
}
return []perSpanProperties{res}
// return nil
},
verification: func(testCase string,
_ *awsxray.Segment,
expectedRs ptrace.ResourceSpans, actualTraces ptrace.Traces, err error) {
assert.NoError(t, err, testCase+": translation should've succeeded")
assert.Equal(t, 1, actualTraces.ResourceSpans().Len(),
testCase+": one segment should translate to 1 ResourceSpans")

actualRs := actualTraces.ResourceSpans().At(0)
assert.NoError(t, ptracetest.CompareResourceSpans(expectedRs, actualRs))
},
},
{
testCase: "TranslateJsonUnmarshallFailed",
expectedUnmarshallFailure: true,
Expand Down

0 comments on commit 6876ca7

Please sign in to comment.