Skip to content

Conversation

@aran112000
Copy link

AWS fails to capture trace when payload contains a multibyte char as the length results in a truncated, malformed payload

AWS fails to capture trace when payload contains a multibyte char as the length results in a truncated, malformed payload
@patrickkerrigan
Copy link
Owner

Thanks for the PR!

Please would you be able to post a minimal example script that reproduces this issue along with the truncated/malformed payload you're seeing? I've so far been unable to reproduce this using unicode strings. For example, the following script produces a valid payload:

<?php

use Pkerrigan\Xray\Segment;
use Pkerrigan\Xray\Submission\DaemonSegmentSubmitter;
use Pkerrigan\Xray\Trace;

require 'vendor/autoload.php';

Trace::getInstance()
    ->setSampled(true)
    ->setName('app.example.com')
    ->setUrl('/')
    ->setMethod('POST')
    ->begin();

Trace::getInstance()
    ->getCurrentSegment()
    ->addSubsegment(
        (new Segment())
        ->setName('')
        ->begin()
        ->end()
    );

Trace::getInstance()
    ->end()
    ->setResponseCode(200)
    ->submit(new DaemonSegmentSubmitter());
{"format":"json","version":1}
{"id":"27a40a8b5087b239","trace_id":"1-6422933f-953cbc5bb4c6bb17ea506580","name":"app.example.com","start_time":1679987519.139496,"end_time":1679987519.139515,"subsegments":[{"id":"99c65c12994a9c9a","name":"\u2603","start_time":1679987519.13951,"end_time":1679987519.139511}],"http":{"request":{"url":"\/","method":"POST"},"response":{"status":200}}}

Note that PHP's json_encode function by default escapes the unicode character as \u2603, so no multibyte characters are actually getting sent. Out of interest I added the JSON_UNESCAPED_UNICODE flag to json_encode to disable this behaviour, and am still seeing a valid payload on master:

{"format":"json","version":1}
{"id":"cb7c017cd352b1db","trace_id":"1-642298c9-17dad89e227daaa14a288d51","name":"app.example.com","start_time":1679988937.957084,"end_time":1679988937.957098,"subsegments":[{"id":"5bb59e0978eed7f8","name":"☃","start_time":1679988937.957094,"end_time":1679988937.957095}],"http":{"request":{"url":"\/","method":"POST"},"response":{"status":200}}}

However, after applying the change in this PR I get a truncated payload (which I'd expect as mb_strlen returns the character length of the string which no longer matches the byte length):

{"format":"json","version":1}
{"id":"5c107933d19998f8","trace_id":"1-64229918-6e4eb1e51fe6d8e2de484590","name":"app.example.com","start_time":1679989016.182225,"end_time":1679989016.182243,"subsegments":[{"id":"f65cfadfd3438889","name":"☃","start_time":1679989016.182239,"end_time":1679989016.18224}],"http":{"request":{"url":"\/","method":"POST"},"response":{"status":200}

My immediate suspicion is that it may actually be that AWS doesn't expect characters to be escaped, but given you mentioned the payload is getting truncated I'm keen to get to the bottom of that before testing with x-ray itself.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants