Skip to content

Commit ff30b4a

Browse files
committed
Add check that parent ID in trace context is correct length
1 parent b84207e commit ff30b4a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

internal/trace/context.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ func convertHexIDToUint64(hexNumber string) (uint64, error) {
185185

186186
// Converts an X-Ray entity ID (hex) to a Datadog parent id (uint64).
187187
func convertXRayEntityIDToAPMParentID(entityID string) (string, error) {
188-
val, err := convertHexIDToUint64(entityID)
188+
if len(entityID) < 16 {
189+
return "0", fmt.Errorf("couldn't convert to trace id, too short")
190+
}
191+
val, err := convertHexIDToUint64(entityID[len(entityID)-16:])
189192
if err != nil {
190193
return "0", fmt.Errorf("couldn't convert entity id to trace id: %v", err)
191194
}

internal/trace/context_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,19 @@ func TestConvertXRayTraceIDIncorrectCharacters(t *testing.T) {
9191
}
9292

9393
func TestConvertXRayEntityID(t *testing.T) {
94-
output, err := convertXRayEntityIDToAPMParentID("779014b90ce44db5e03875")
94+
output, err := convertXRayEntityIDToAPMParentID("0b11cc4230d3e09e")
9595
assert.NoError(t, err)
96-
assert.Equal(t, "8615408872177552821", output)
96+
assert.Equal(t, "797643193680388254", output)
9797
}
9898

9999
func TestConvertXRayEntityIDInvalidFormat(t *testing.T) {
100-
output, err := convertXRayEntityIDToAPMParentID(";79014b90ce44db5e03875")
100+
output, err := convertXRayEntityIDToAPMParentID(";b11cc4230d3e09e")
101+
assert.Error(t, err)
102+
assert.Equal(t, "0", output)
103+
}
104+
105+
func TestConvertXRayEntityIDTooShort(t *testing.T) {
106+
output, err := convertXRayEntityIDToAPMParentID("c4230d3e09e")
101107
assert.Error(t, err)
102108
assert.Equal(t, "0", output)
103109
}

0 commit comments

Comments
 (0)