0

I am trying to set up XRAY tracing for postgres DB . I keep getting Segment Not found error I following the instructions in this link https://docs.aws.amazon.com/xray/latest/devguide/scorekeep-workerthreads.html

 def save(event: EventRow): IO[Int] = {
    AWSXRay.getGlobalRecorder.setTraceEntity(segment)
    sql"insert into events (id, name, data, created) values (${event.id}, ${event.name}, ${event.data}, ${event.created})".update.run
      .transact(xs)
  }
Balaji V
  • 918
  • 3
  • 10
  • 28
  • Are you constructing the segment earlier, e.g. with `Segment segment = AWSXRay.beginSegment('name');` and closing it with `AWSXRay.endSegment()`? What line exactly are you seeing this error on? – William Armiros Apr 24 '20 at 16:26
  • @WilliamArmiros The problem is the ExecutionContext used by Doobie . There is no way to pass on the segment context to the execution context – Balaji V Apr 25 '20 at 07:22

1 Answers1

0

This might be an unavoidable consequence of X-Ray not having support for Doobie. You can remove the postgres instrumentation library for X-Ray and that will prevent the segment not found errors. As a workaround to trace your queries, you can try this:

Subsegment sub = AWSXRay.beginSubsegment('doobieCall');
sql"insert into events (id, name, data, created) values (${event.id}, ${event.name}, ${event.data}, ${event.created})".update.run
      .transact(xs)
Map<String, Object> sqlMap = new HashMap<>();
// Add desired metadata
sub.putAllSql(sqlMap);
AWSXRay.endSubsegment();

Where metadata can be any of the whitelisted SQL fields. Since Doobie is a scala library and we do not officially support Scala, we do not plan to add support for it at this time.

William Armiros
  • 267
  • 1
  • 10
  • Hey William , thanks for your suggestion . In general most of these things are working for frameworks which follow one thread one request concept and not for aync frameworks like play which work on actor based concurrency pattern. What is your suggestion on this – Balaji V Apr 28 '20 at 11:55