DynamoDB in X-Ray Service Map

1

Hi there,

A little background on my architecture: I have an API Gateway API that invokes a "Event Receiver" Lambda function. The Lambda function persists the event in a DynamoDB table which has DynamoDB Streams enabled. Another "Event Processor" Lambda function is triggered by the DynamoDB Stream which processes the event, i.e. sends notifications to other services based on some rules. My lambdas are written in Kotlin and I am using the AWS Java SDK.

I have a few questions about using X-Ray in this architecture:

I enabled Tracing for API Gateway in my SAM template and I can see the traces in X-Ray console. However, I only see the API Gateway Stage and Lambda in the Service Map. How would I see the downstream segments, e.g. DynamoDB tables, etc.? I have "aws-xray-recorder-sdk-core", "aws-xray-recorder-sdk-aws-sdk" and "aws-xray-recorder-sdk-aws-sdk-instrumentor" libraries added. I have also tried removing the "aws-xray-recorder-sdk-aws-sdk-instrumentor" and building the DynamoDB client using:

AmazonDynamoDBClientBuilder
  .standard()
  .withEndpointConfiguration(EndpointConfiguration(dynamodbEndpoint, dynamodbRegion))
  .withRequestHandlers(TracingHandler(AWSXRay.getGlobalRecorder()))
  .build()

but that did not work either. I have also tried having PassThrough Tracing enabled for the Lambda in my SAM template, but still no luck.

Do I need to enable PassThrough Tracing in my SAM template for the Lambdas?

Would I be able to visualize DynamoDB Streams and the "Event Processor" Lambda in the Service Map and see them in the traces?

I appreciate the help.

Thanks,
Tanvir

Edited by: tanviramit on Jun 4, 2019 3:58 PM

asked 5 years ago3510 views
8 Answers
1

Hi there,

DynamoDB streams right now is not integrated with X-Ray so the streams will not carry the tracing context to the downstream lambda function. If you enable active tracing to the downstream lambda function you should see a new subgraph starts from that lambda function.

Integrating with DynamoDB streams is a popular request and we are evaluating this feature with DynamoDB teams. To better understand your use case, could you provide how many streams you expect to see in a single lambda invoke? Do these streams usually come from a single API Getaway request?

We will provide updates once we make progress. Please stay tuned and thank you for your patience.

Thanks,
Haotian

AWS
answered 5 years ago
1

Hi

Is there any progress with integration of X-RAY with DynamoDB Streams?

My usecase is:
Api Gateway v2 -> lambda –> Store Entity into DynamoDB -> DynamoDB Stream –> Lambda -> Websocket Gateway

(I didn`t implemented websocket yet)

For now I can see two separated graphs in X-RAY console:

  1. for http event: client -> AWS Lambda -> AWS Lambda function -> DynamoDB
  2. for ddb event: client -> AWS Lambda -> AWS Lambda function
answered 4 years ago
1

Any updates on the availability of tracing via DynamoDB streams?

Thanks,
Olja

Olja
answered 3 years ago
0

Hi @MichalPospisil
We are still in talks with the DDB team to iron out details of the integration with X-Ray. It's on our roadmap.
Thanks for providing the flow of your use case. I'm not sure if you noticed that you're missing the client -> API Gateway -> AWS Lambda flow in your first service map. This is because you're using API Gateway V2 and unlike V1, it's not supported with X-Ray yet. Any particular reason to use the V2?

We'll post updates about the support for DDB stream as soon as possible. Thanks for your patience.

Regards,
Prashant

AWS
answered 4 years ago
  • Hi Prashant, are there any updates available about this feature?

0

Hi Haotian,

Thank you for your reply. Let's go step-by-step.

  1. First use case:
API Gateway -> Lambda -> DynamoDB "Events" Table

I enabled tracing on API Gateway stage, but I only see API Gateway stage and Lambda in Service Map. What do I need to do to see the DynamoDB Table in the Service Map, similar to how you can see it here: https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-servicegraph ?

  1. I am not sure what you mean by "how many streams". The "Events" Table I mentioned above has one DynamoDB stream that triggers another "Event Processor" Lambda function.

I appreciate the help!

Thanks,
Tanvir

answered 5 years ago
0

Hi, what is the SDK version? Could you also provide a code snippet that calls your "Event" table so we can take a further look at?

Thanks,
Haotian

AWS
answered 5 years ago
0

Hi Haotian,

I tried manually creating a subsegment but still no luck. Here's a snippet of my code:

// DynamoDBClient class

private val client: AmazonDynamoDB =
  AmazonDynamoDBClientBuilder
    .standard()
    .withEndpointConfiguration(EndpointConfiguration(dynamodbEndpoint, dynamodbRegion))
    .withRequestHandlers(TracingHandler(AWSXRay.getGlobalRecorder()))
    .build()

fun publishEvent(notificationEvent: notificationEvent) {
  val mapperConfig: DynamoDBMapperConfig =
    DynamoDBMapperConfig
      .builder()
      .withTableNameOverride(DynamoDBMapperConfig.TableNameOverride(eventsTableName))
      .build()
  val mapper = DynamoDBMapper(client, mapperConfig)
  val expectedAttributes = mapOf("AlertIdentifier" to ExpectedAttributeValue(false))
  val subsegment: Subsegment = AWSXRay.beginSubsegment("DynamoDBClient.publishEvent")

  try {
    mapper.save(notificationEvent, DynamoDBSaveExpression().withExpected(expectedAttributes))
  } catch (ex: Exception) {
    subsegment.addException(ex)
    throw ex
  } finally {
    logger.debug("Parent segment name: ${subsegment.parentSegment.name}")
    logger.debug("Parent segment id: ${subsegment.parentSegment.id}")
    subsegment.end()
  }
}

// Some other class

DynamoDBClient.publishEvent(notificationEvent)

Here is a subset of my build.gradle file where you can see the SDK versions:

dependencyManagement {
  imports {
    mavenBom('com.amazonaws:aws-java-sdk-bom:1.11.559')
    mavenBom('com.amazonaws:aws-xray-recorder-sdk-bom:2.2.1')
  }
}

ext {
  kotlinVersion = '1.3.31'
}

dependencies {
  implementation(
      'org.jetbrains.kotlin:kotlin-stdlib-jdk8',
      'org.jetbrains.kotlin:kotlin-reflect',
      'org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.11.0',
      'ch.qos.logback:logback-classic:1.2.3',
      'com.amazonaws:aws-java-sdk-core',
      'com.amazonaws:aws-java-sdk-dynamodb',
      'com.amazonaws:aws-lambda-java-core:1.2.0',
      'com.amazonaws:aws-lambda-java-events:2.2.6',
      'com.amazonaws:aws-xray-recorder-sdk-core',
      'com.amazonaws:aws-xray-recorder-sdk-aws-sdk',
      'ch.qos.logback:logback-classic:1.2.3',
      'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.7'
  )
}

Thanks,
Tanvir

answered 5 years ago
0

Hi Haotian,

I think I figured it out.

Turns out that the instrumentation works if I exclude the SDK Instrumentor submodule (aws-xray-recorder-sdk-aws-sdk-instrumentor), and I don't even need to manually create subsegments for the DynamoDB calls.

Just adding these two dependencies is enough for me:

'com.amazonaws:aws-xray-recorder-sdk-core',
'com.amazonaws:aws-xray-recorder-sdk-aws-sdk'

Perhaps, the documentation needs to be updated. Anyway, the only thing I'm missing right now is to record the segment in the Lambda triggered from a DynamoDB stream, but I suppose I can persist the Trace ID and Segment ID in DynamoDB and use them to manually create another segment, as a workaround. Any update on whether support for DynamoDB Streams is in the roadmap?

Thanks,
Tanvir

answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions