Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
test:
docker:
- image: circleci/php:5-node-browsers
- image: circleci/php:7.1-node-browsers
steps:
- checkout
- restore_cache:
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"description": "LightStep instrumentation API",
"license": "MIT",
"require": {
"ruafozy/mersenne-twister": "^1.3",
"google/protobuf": ">=3.6.1",
"php": "^7.1",
"ext-bcmath": "*",
"psr/log": "^1.0"
"google/protobuf": ">=3.6.1",
"opentracing/opentracing": "^1.0.0-beta6",
"psr/log": "^1.0",
"ruafozy/mersenne-twister": "^1.3"
},
"require-dev": {
"phpdocumentor/phpdocumentor": "^2.8.5",
Expand All @@ -24,4 +26,4 @@
"config": {
"sort-packages": true
}
}
}
41 changes: 28 additions & 13 deletions lib/Client/ClientSpan.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
use Lightstep\Collector\Span;
use Lightstep\Collector\SpanContext;
use Google\Protobuf\Timestamp;
use LightStepBase\Tracer;

require_once(dirname(__FILE__) . "/Util.php");
require_once(dirname(__FILE__) . "/../../thrift/CroutonThrift/Types.php");

class ClientSpan implements \LightStepBase\Span {
class ClientSpan implements \OpenTracing\Span {

protected $_tracer = NULL;

Expand Down Expand Up @@ -76,11 +75,24 @@ public function setEndMicros($start) {
return $this;
}

public function finish() {
$this->_tracer->_finishSpan($this);
public function getOperationName() {
return $this->_operation;
}

public function setOperationName($name) {
public function getContext() {
return new ClientSpanContext(
$this->traceGUID(),
$this->guid(),
true,
$this->getBaggage()
);
}

public function finish($finishTime = NULL) {
$this->_tracer->_finishSpan($this, $finishTime);
}

public function overwriteOperationName($name) {
$this->_operation = $name;
return $this;
}
Expand All @@ -90,11 +102,6 @@ public function addTraceJoinId($key, $value) {
return $this;
}

public function setEndUserId($id) {
$this->addTraceJoinId(LIGHTSTEP_JOIN_KEY_END_USER_ID, $id);
return $this;
}

public function setTags($fields) {
foreach ($fields as $key => $value) {
$this->setTag($key, $value);
Expand All @@ -107,7 +114,7 @@ public function setTag($key, $value) {
return $this;
}

public function setBaggageItem($key, $value) {
public function addBaggageItem($key, $value) {
$this->_baggage[$key] = $value;
return $this;
}
Expand Down Expand Up @@ -153,7 +160,7 @@ public function logEvent($event, $payload = NULL) {
]);
}

public function log($fields) {
public function log(array $fields = [], $timestamp = NULL) {
$record = [
'span_guid' => strval($this->_guid),
];
Expand All @@ -163,7 +170,9 @@ public function log($fields) {
$record['event'] = strval($fields['event']);
}

if (!empty($fields['timestamp'])) {
if ($timestamp) {
$record['timestamp_micros'] = intval(1000 * $timestamp);
} else if (!empty($fields['timestamp'])) {
$record['timestamp_micros'] = intval(1000 * $fields['timestamp']);
}
// no need to verify value of fields['payload'] as it will be checked by _rawLogRecord
Expand Down Expand Up @@ -333,4 +342,10 @@ public function toProto() {
'references' => $references,
]);
}

/** Deprecated */
public function setEndUserId($id) {
$this->addTraceJoinId("LIGHTSTEP_JOIN_KEY_END_USER_ID", $id);
return $this;
}
}
82 changes: 82 additions & 0 deletions lib/Client/ClientSpanContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

namespace LightStepBase\Client;

use ArrayIterator;

class ClientSpanContext implements \OpenTracing\SpanContext {
/**
* @var string
*/
private $traceId;

/**
* @var string
*/
private $spanId;

/**
* @var bool
*/
private $isSampled;

/**
* @var array
*/
private $baggageItems;

public function __construct(string $traceId, string $spanId, bool $isSampled = true, array $baggageItems = [])
{
$this->traceId = $traceId;
$this->spanId = $spanId;
$this->isSampled = $isSampled;
$this->baggageItems = $baggageItems;
}

public function getTraceId(): string
{
return $this->traceId;
}

public function getSpanId(): string
{
return $this->spanId;
}

public function isSampled(): bool
{
return $this->isSampled;
}

public function getBaggage(): array
{
return $this->baggageItems;
}

/**
* {@inheritdoc}
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->baggageItems);
}

/**
* {@inheritdoc}
*/
public function getBaggageItem($key): ?string
{
return array_key_exists($key, $this->baggageItems) ? strval($this->baggageItems[$key]) : null;
}

/**
* {@inheritdoc}
*/
public function withBaggageItem($key, $value): ?SpanContext
{
return new self($this->traceId, $this->spanId, $this->isSampled, array_merge($this->bagaggeItems, [$key => $value]));
}

}
Loading