/**
  * Returns the singleton instance of the Tracer.
  *
  * For convenience, this function can be passed the $component_name and
  * $access_token parameters to also initialize the tracer singleton. These
  * values will be ignored on any calls after the first to getInstance().
  *
  * @param $component_name Component name to use for the tracer
  * @param $access_token The project access token
  * @return \LightStepBase\Tracer
  * @throws Exception if the group name or access token is not a valid string
  */
 public static function getInstance($component_name = NULL, $access_token = NULL, $opts = NULL)
 {
     if (!isset(self::$_singleton)) {
         self::$_singleton = self::newTracer($component_name, $access_token, $opts);
     }
     return self::$_singleton;
 }
 public function testGetInstance()
 {
     $inst = LightStep::getInstance("test_group", "1234567890");
     $this->assertInstanceOf("\\LightStepBase\\Client\\ClientTracer", $inst);
     // Is it really a singleton?
     $inst2 = LightStep::getInstance("test_group", "1234567890");
     $this->assertSame($inst, $inst2);
 }
 public function testDisable()
 {
     $runtime = LightStep::newTracer("test_group", "1234567890");
     $runtime->disable();
     $span = $runtime->startSpan("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();
 }
 public function testDeeplyNested()
 {
     $runtime = LightStep::newTracer("test_group", "1234567890");
     $span = $runtime->startSpan('test_span');
     $span->infof("test", $this->_wrapValue("value!", 2));
     $span->infof("test", $this->_wrapValue("value!", 4));
     $span->infof("test", $this->_wrapValue("value!", 8));
     $span->infof("test", $this->_wrapValue("value!", 10));
     $span->infof("test", $this->_wrapValue("value!", 100));
     $span->infof("test", $this->_wrapValue("value!", 1000));
     $span->finish();
 }
 public function testSpanBufferingBeforeInit()
 {
     $runtime = LightStep::newTracer(NULL, NULL);
     $span = $runtime->startSpan("first");
     $span->infof('Hello %s', 'World');
     $span->finish();
     $runtime->options(array('component_name' => 'init_test_group', 'access_token' => '1234567890'));
     $span = $runtime->startSpan("second");
     $span->infof('Hola %s', 'Mundo');
     $span->finish();
     $this->assertEquals(2, count($this->peek($runtime, "_spanRecords")));
     $runtime->flush();
 }
 public function testSpanMaxRecords()
 {
     $runtime = LightStep::newTracer("test_group", "1234567890", array('debug_disable_flush' => TRUE));
     $maxRecords = $this->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("loop_span");
         $span->finish();
         $this->assertEquals($i + 1, count($this->peek($runtime, "_spanRecords")));
     }
     $this->assertEquals($maxRecords, count($this->peek($runtime, "_spanRecords")));
     // After the max has been hit...
     for ($i = 0; $i < 10 * $maxRecords; $i++) {
         $span = $runtime->startSpan("loop_span");
         $span->finish();
         $this->assertEquals($maxRecords, count($this->peek($runtime, "_spanRecords")));
     }
     $runtime->_discard();
     $this->assertEquals(0, count($this->peek($runtime, "_spanRecords")));
 }
 public function testInjectJoin()
 {
     $tracer = LightStep::newTracer("test_group", "1234567890");
     $span = $tracer->startSpan("hello/world");
     $carrier = array();
     $tracer->inject($span, LIGHTSTEP_FORMAT_TEXT_MAP, $carrier);
     $this->assertEquals($carrier['ot-tracer-spanid'], $span->guid());
     $this->assertEquals($carrier['ot-tracer-traceid'], $span->traceGUID());
     $this->assertEquals($carrier['ot-tracer-sampled'], 'true');
     $span->finish();
     $child = $tracer->join('child', LIGHTSTEP_FORMAT_TEXT_MAP, $carrier);
     $this->assertEquals($child->traceGUID(), $span->traceGUID());
     $this->assertEquals($child->getParentGUID(), $span->guid());
     $child->finish();
 }
<?php

require __DIR__ . '/vendor/autoload.php';
LightStep::initGlobalTracer('examples/trivial_process', '{your_access_token}');
$span = LightStep::startSpan("trivial/loop");
for ($i = 0; $i < 10; $i++) {
    $span->logEvent("loop_iteration", $i);
    echo "The current unix time is " . time() . "\n";
    usleep(100000.0);
    $child = LightStep::startSpan("child_span", array(parent => $span));
    usleep(200000.0);
    $child->logEvent("hello world");
    $child->finish();
    usleep(100000.0);
}
$span->finish();
 public function tracer()
 {
     return LightStep::getInstance();
 }