fido-id / php-xray

php xray
Other
4 stars 0 forks source link

Traces not showing at AWS X-ray #36

Open wtfoong opened 1 year ago

wtfoong commented 1 year ago

Hi, i am currently working on a website with AWS web services and would like to test its performance using AWS x-ray. I copied ur example to test out the library, the code works fine and trace id are provided, but there is no results shown at AWS x-ray.

image

this is the code

<?php
require_once(__DIR__ . '/vendor/autoload.php');
//use Pkerrigan\Xray\Trace;
require_once 'Thrower.php';
use Fido\PHPXray\Cause;
use Fido\PHPXray\DynamoSegment;
use Fido\PHPXray\HttpSegment;
use Fido\PHPXray\Segment;
use Fido\PHPXray\Submission\DaemonSegmentSubmitter;
use Fido\PHPXray\Trace;
use Fido\PHPXray\TraceSingletonAccessor;
use GuzzleHttp\Client;

$client = new Client();

$trace = new Trace(\uniqid("a_trace_name_"));
TraceSingletonAccessor::setInstance($trace);

$main = new Segment(\uniqid("segment_main_"));

$httpSegment = new HttpSegment(
    name: \uniqid("http_segment_post_500_"),
    url: 'ifconfig.me/ua',
    method: 'GET'
);
$httpSegment->closeWithPsrResponse($client->get('ifconfig.me/ua'));

$genericSubSegment = new Segment(\uniqid("generic_sub_segment_"));
$dynamoDBSubSegment = new DynamoSegment(
    name: \uniqid("dynamo_db_sub_segment_"),
    tableName: "a_table_name",
    operation: 'query',
    requestId: 'a_request_id'
);

try {

    try {
        new Thrower('42', 42, new \stdClass(), ['42',42]);
    } catch (\Throwable $e) {
        throw new \Exception('wrapper', 0, $e);
    }

} catch (\Throwable $t) {
    $exception = $t;

}

$genericSubSegmentWithException = new Segment(\uniqid("segment_main_"));
$genericSubSegmentWithException->setError(true);
$genericSubSegmentWithException->setCause(Cause::fromThrowable($exception));

$main->addSubsegment($genericSubSegment);
$main->addSubsegment($httpSegment);
$main->addSubsegment($dynamoDBSubSegment);
$main->addSubsegment($genericSubSegmentWithException);
TraceSingletonAccessor::getInstance()->addSubsegment($main);

TraceSingletonAccessor::getInstance()->end();
(new DaemonSegmentSubmitter())->submitSegment(TraceSingletonAccessor::getInstance());

print_r("https://us-east-1.console.aws.amazon.com/xray/home?region=us-east-1#/traces/" . $trace->getTraceId() . "\n");

?>

<h1>test</h1>

could i know i did wrong, tqvm....

sanfo commented 1 year ago

Hi @wtfoong,

We currently updated our library. Can you try with the latest version and let us know?