Skip to content

Commit 978afb6

Browse files
committed
port dynamodb span link tests
1 parent 55238f7 commit 978afb6

File tree

1 file changed

+40
-49
lines changed

1 file changed

+40
-49
lines changed

dd-java-agent/instrumentation/aws-java-dynamodb-2.0/src/test/groovy/DynamoDbClientTest.groovy

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import datadog.trace.agent.test.AgentTestRunner
22
import datadog.trace.api.DDSpanTypes
3+
import datadog.trace.api.DDTraceId
4+
import datadog.trace.bootstrap.instrumentation.api.SpanAttributes
5+
import datadog.trace.bootstrap.instrumentation.api.SpanLink
36
import datadog.trace.core.tagprocessor.SpanPointersProcessor
4-
import groovy.json.JsonSlurper
57
import org.testcontainers.containers.GenericContainer
68
import org.testcontainers.utility.DockerImageName
79
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials
@@ -23,6 +25,7 @@ import software.amazon.awssdk.services.dynamodb.model.PutItemRequest
2325
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType
2426
import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest
2527
import spock.lang.Shared
28+
2629
import java.time.Duration
2730

2831
class DynamoDbClientTest extends AgentTestRunner {
@@ -188,6 +191,15 @@ class DynamoDbClientTest extends AgentTestRunner {
188191
operationName "aws.http"
189192
resourceName "DynamoDb.UpdateItem"
190193
spanType DDSpanTypes.HTTP_CLIENT
194+
links {
195+
link(DDTraceId.ZERO, 0, SpanLink.DEFAULT_FLAGS, SpanAttributes.builder()
196+
.put("ptr.kind", SpanPointersProcessor.DYNAMODB_PTR_KIND)
197+
.put("ptr.dir", SpanPointersProcessor.DOWN_DIRECTION)
198+
// First 32 chars of SHA256("dynamodb-one-key-table|id|test-id-1||")
199+
.put("ptr.hash", "ca8daaa857b00545ed5186a915cf1ab5")
200+
.put("link.kind", SpanPointersProcessor.LINK_KIND)
201+
.build())
202+
}
191203
tags {
192204
defaultTags()
193205
tag "component", "java-aws-sdk"
@@ -205,18 +217,6 @@ class DynamoDbClientTest extends AgentTestRunner {
205217
tag "span.kind", "client"
206218
tag "aws.requestId", { it != null }
207219
tag "_dd.span_links", { it != null }
208-
// Assert the span links
209-
def spanLinks = tags["_dd.span_links"]
210-
assert spanLinks != null
211-
def links = new JsonSlurper().parseText(spanLinks)
212-
assert links.size() == 1
213-
def link = links[0]
214-
assert link["attributes"] != null
215-
assert link["attributes"]["ptr.kind"] == SpanPointersProcessor.DYNAMODB_PTR_KIND
216-
assert link["attributes"]["ptr.dir"] == SpanPointersProcessor.DOWN_DIRECTION
217-
// First 32 chars of SHA256("dynamodb-one-key-table|id|test-id-1||")
218-
assert link["attributes"]["ptr.hash"] == "ca8daaa857b00545ed5186a915cf1ab5"
219-
assert link["attributes"]["link.kind"] == SpanPointersProcessor.LINK_KIND
220220
}
221221
}
222222
}
@@ -293,6 +293,15 @@ class DynamoDbClientTest extends AgentTestRunner {
293293
operationName "aws.http"
294294
resourceName "DynamoDb.UpdateItem"
295295
spanType DDSpanTypes.HTTP_CLIENT
296+
links {
297+
link(DDTraceId.ZERO, 0, SpanLink.DEFAULT_FLAGS, SpanAttributes.builder()
298+
.put("ptr.kind", SpanPointersProcessor.DYNAMODB_PTR_KIND)
299+
.put("ptr.dir", SpanPointersProcessor.DOWN_DIRECTION)
300+
// First 32 chars of SHA256("dynamodb-two-key-table|primaryKey|customer-123|sortKey|order-456")
301+
.put("ptr.hash", "90922c7899a82ea34406fdcdfb95161e")
302+
.put("link.kind", SpanPointersProcessor.LINK_KIND)
303+
.build())
304+
}
296305
tags {
297306
defaultTags()
298307
tag "component", "java-aws-sdk"
@@ -310,18 +319,6 @@ class DynamoDbClientTest extends AgentTestRunner {
310319
tag "span.kind", "client"
311320
tag "aws.requestId", { it != null }
312321
tag "_dd.span_links", { it != null }
313-
// Assert the span links
314-
def spanLinks = tags["_dd.span_links"]
315-
assert spanLinks != null
316-
def links = new JsonSlurper().parseText(spanLinks)
317-
assert links.size() == 1
318-
def link = links[0]
319-
assert link["attributes"] != null
320-
assert link["attributes"]["ptr.kind"] == SpanPointersProcessor.DYNAMODB_PTR_KIND
321-
assert link["attributes"]["ptr.dir"] == SpanPointersProcessor.DOWN_DIRECTION
322-
// First 32 chars of SHA256("dynamodb-two-key-table|primaryKey|customer-123|sortKey|order-456")
323-
assert link["attributes"]["ptr.hash"] == "90922c7899a82ea34406fdcdfb95161e"
324-
assert link["attributes"]["link.kind"] == SpanPointersProcessor.LINK_KIND
325322
}
326323
}
327324
}
@@ -384,6 +381,15 @@ class DynamoDbClientTest extends AgentTestRunner {
384381
operationName "aws.http"
385382
resourceName "DynamoDb.DeleteItem"
386383
spanType DDSpanTypes.HTTP_CLIENT
384+
links {
385+
link(DDTraceId.ZERO, 0, SpanLink.DEFAULT_FLAGS, SpanAttributes.builder()
386+
.put("ptr.kind", SpanPointersProcessor.DYNAMODB_PTR_KIND)
387+
.put("ptr.dir", SpanPointersProcessor.DOWN_DIRECTION)
388+
// First 32 chars of SHA256("dynamodb-one-key-table|id|delete-test-id||")
389+
.put("ptr.hash", "65031164be5e929fddd274a02cba3f9f")
390+
.put("link.kind", SpanPointersProcessor.LINK_KIND)
391+
.build())
392+
}
387393
tags {
388394
defaultTags()
389395
tag "component", "java-aws-sdk"
@@ -401,18 +407,6 @@ class DynamoDbClientTest extends AgentTestRunner {
401407
tag "span.kind", "client"
402408
tag "aws.requestId", { it != null }
403409
tag "_dd.span_links", { it != null }
404-
// Assert the span links
405-
def spanLinks = tags["_dd.span_links"]
406-
assert spanLinks != null
407-
def links = new JsonSlurper().parseText(spanLinks)
408-
assert links.size() == 1
409-
def link = links[0]
410-
assert link["attributes"] != null
411-
assert link["attributes"]["ptr.kind"] == SpanPointersProcessor.DYNAMODB_PTR_KIND
412-
assert link["attributes"]["ptr.dir"] == SpanPointersProcessor.DOWN_DIRECTION
413-
// First 32 chars of SHA256("dynamodb-one-key-table|id|delete-test-id||")
414-
assert link["attributes"]["ptr.hash"] == "65031164be5e929fddd274a02cba3f9f"
415-
assert link["attributes"]["link.kind"] == SpanPointersProcessor.LINK_KIND
416410
}
417411
}
418412
}
@@ -486,6 +480,15 @@ class DynamoDbClientTest extends AgentTestRunner {
486480
operationName "aws.http"
487481
resourceName "DynamoDb.DeleteItem"
488482
spanType DDSpanTypes.HTTP_CLIENT
483+
links {
484+
link(DDTraceId.ZERO, 0, SpanLink.DEFAULT_FLAGS, SpanAttributes.builder()
485+
.put("ptr.kind", SpanPointersProcessor.DYNAMODB_PTR_KIND)
486+
.put("ptr.dir", SpanPointersProcessor.DOWN_DIRECTION)
487+
// First 32 chars of SHA256("dynamodb-two-key-table|primaryKey|user-789|sortKey|profile")
488+
.put("ptr.hash", "e5ce1148208c6f88041c73ceb9bbbf3a")
489+
.put("link.kind", SpanPointersProcessor.LINK_KIND)
490+
.build())
491+
}
489492
tags {
490493
defaultTags()
491494
tag "component", "java-aws-sdk"
@@ -503,18 +506,6 @@ class DynamoDbClientTest extends AgentTestRunner {
503506
tag "span.kind", "client"
504507
tag "aws.requestId", { it != null }
505508
tag "_dd.span_links", { it != null }
506-
// Assert the span links
507-
def spanLinks = tags["_dd.span_links"]
508-
assert spanLinks != null
509-
def links = new JsonSlurper().parseText(spanLinks)
510-
assert links.size() == 1
511-
def link = links[0]
512-
assert link["attributes"] != null
513-
assert link["attributes"]["ptr.kind"] == SpanPointersProcessor.DYNAMODB_PTR_KIND
514-
assert link["attributes"]["ptr.dir"] == SpanPointersProcessor.DOWN_DIRECTION
515-
// First 32 chars of SHA256("dynamodb-two-key-table|primaryKey|user-789|sortKey|profile")
516-
assert link["attributes"]["ptr.hash"] == "e5ce1148208c6f88041c73ceb9bbbf3a"
517-
assert link["attributes"]["link.kind"] == SpanPointersProcessor.LINK_KIND
518509
}
519510
}
520511
}

0 commit comments

Comments
 (0)