コード例 #1
0
ファイル: RuntimeTest.php プロジェクト: srspnda/api-php
 public function testSpanMaxRecords()
 {
     $runtime = Traceguide::newRuntime("test_group", "1234567890");
     $maxRecords = peek($runtime, "_options")["max_span_records"];
     // Sanity check that the default is not abnormally small (or more
     // likely that the internal variable named hasn't been changed and
     // invalidated this test!)
     $this->assertGreaterThan(10, $maxRecords);
     // Before the max is hit...
     for ($i = 0; $i < $maxRecords; $i++) {
         $span = $runtime->startSpan();
         $span->setOperation("loop_span");
         $span->finish();
         $this->assertEquals($i + 1, count(peek($runtime, "_spanRecords")));
     }
     // After the max has been hit...
     for ($i = 0; $i < 10 * $maxRecords; $i++) {
         $span = $runtime->startSpan();
         $span->setOperation("loop_span");
         $span->finish();
         $this->assertEquals($maxRecords, count(peek($runtime, "_spanRecords")));
     }
     $runtime->_discard();
     $this->assertEquals(0, count(peek($runtime, "_spanRecords")));
 }
コード例 #2
0
ファイル: Traceguide.php プロジェクト: traceguide/api-php
 /**
  * Returns the singleton instance of the Runtime.
  *
  * For convenience, this function can be passed the  $group_name and
  * $access_token parameters to also initialize the runtime singleton. These
  * values will be ignored on any calls after the first to getInstance().
  *
  * @param $group_name Group name to use for the runtime
  * @param $access_token The project access token
  * @return \TraceguideBase\Runtime
  * @throws Exception if the group name or access token is not a valid string
  */
 public static function getInstance($group_name = NULL, $access_token = NULL, $opts = NULL)
 {
     if (!isset(self::$_singleton)) {
         self::$_singleton = self::newRuntime($group_name, $access_token, $opts);
     }
     return self::$_singleton;
 }
コード例 #3
0
ファイル: TraceguideTest.php プロジェクト: traceguide/api-php
 public function testGetInstance()
 {
     $inst = Traceguide::getInstance("test_group", "1234567890");
     $this->assertInstanceOf("\\TraceguideBase\\Client\\ClientRuntime", $inst);
     // Is it really a singleton?
     $inst2 = Traceguide::getInstance("test_group", "1234567890");
     $this->assertSame($inst, $inst2);
 }
コード例 #4
0
ファイル: PayloadsTest.php プロジェクト: traceguide/api-php
 public function testDeeplyNested()
 {
     $runtime = Traceguide::newRuntime("test_group", "1234567890");
     $runtime->infof("test", $this->_wrapValue("value!", 2));
     $runtime->infof("test", $this->_wrapValue("value!", 4));
     $runtime->infof("test", $this->_wrapValue("value!", 8));
     $runtime->infof("test", $this->_wrapValue("value!", 10));
     $runtime->infof("test", $this->_wrapValue("value!", 100));
     $runtime->infof("test", $this->_wrapValue("value!", 1000));
 }
コード例 #5
0
 public function testMultipleInitCalls()
 {
     $runtime = Traceguide::newRuntime(NULL, NULL);
     for ($i = 0; $i < 100; $i++) {
         $runtime->infof("log%03d", 3 * $i);
         // Redundant calls are fine as long as the configuration
         // is the same
         $runtime->options(array('group_name' => 'init_test_group', 'access_token' => '1234567890'));
         $runtime->infof("log%03d", 7 * $i);
     }
 }
コード例 #6
0
 public function testSpanBufferingBeforeInit()
 {
     $runtime = Traceguide::newRuntime(NULL, NULL);
     $span = $runtime->startSpan();
     $span->setOperation("first");
     $span->infof('Hello %s', 'World');
     $span->finish();
     $runtime->options(array('group_name' => 'init_test_group', 'access_token' => '1234567890'));
     $span = $runtime->startSpan();
     $span->setOperation("second");
     $span->infof('Hola %s', 'Mundo');
     $span->finish();
     $this->assertEquals(2, count(peek($runtime, "_spanRecords")));
     $runtime->flush();
 }
コード例 #7
0
ファイル: SpanTest.php プロジェクト: traceguide/api-php
 public function testSpanThriftRecord()
 {
     $runtime = Traceguide::newRuntime("test_group", "1234567890");
     $span = $runtime->startSpan();
     $span->setOperation("hello/world");
     $span->setEnduserId("dinosaur_sr");
     $span->finish();
     // Transform the object into a associative array
     $arr = json_decode(json_encode($span->toThrift()), TRUE);
     $this->assertTrue(is_string($arr["span_guid"]));
     $this->assertTrue(is_string($arr["runtime_guid"]));
     $this->assertTrue(is_string($arr["span_name"]));
     $this->assertEquals(1, count($arr["join_ids"]));
     $this->assertTrue(is_string($arr["join_ids"][0]["TraceKey"]));
     $this->assertTrue(is_string($arr["join_ids"][0]["Value"]));
 }
コード例 #8
0
 public function testDisable()
 {
     $runtime = Traceguide::newRuntime("test_group", "1234567890");
     $runtime->disable();
     $runtime->infof("Shouldn't do anything");
     $runtime->warnf("Shouldn't do anything");
     $runtime->errorf("Shouldn't do anything");
     $runtime->fatalf("Shouldn't do anything");
     $span = $runtime->startSpan();
     $span->setOperation("noop_call");
     $span->setEndUserId("ignored_user");
     $span->addTraceJoinId("key_to_an", "unused_value");
     $span->warnf("Shouldn't do anything");
     $span->errorf("Shouldn't do anything");
     $span->finish();
 }
コード例 #9
0
ファイル: index.php プロジェクト: bcronin/simple-php
<?php

// Explicitly include the local pacakge for development purposes
// (i.e. don't put Traceguide in composer.json)
require __DIR__ . '/vendor/autoload.php';
$start = microtime(TRUE);
Traceguide::initialize('simple-php', 'XXX_warbler_token', array('service_host' => 'api-meta.traceguide.io'));
Traceguide::infof("Simple string");
$span = Traceguide::startSpan();
$span->setOperation("quick/infof");
$span->setEndUserId("quick_php");
for ($i = 0; $i < 10; $i++) {
    $inner = Traceguide::startSpan();
    $inner->setOperation("quick/inner");
    $inner->setParent($span);
    $span->infof("Loop iteration %d", $i);
    $inner->finish();
    //usleep(1e5);
}
$span->finish();
$end = microtime(TRUE);
echo "Time: " . sprintf("%.2f", $end - $start) . " ms\n";