Skip to content

Commit 04f84d7

Browse files
authored
Add ReadableSpan/ReadWriteSpan interfaces (#403)
* Add ReadableSpan interface * Add ReadWriteSpan interface Remove reading methods from API\Span interface. * Fix code style
1 parent e5e8b74 commit 04f84d7

32 files changed

+230
-104
lines changed

api/Trace/Span.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,6 @@
88

99
interface Span extends SpanStatus, SpanKind
1010
{
11-
public function getSpanName(): string;
12-
public function getContext(): SpanContext;
13-
public function getParent(): ?SpanContext;
14-
15-
/**
16-
* Returns Epoch timestamp value (RealtimeClock) when the Span was created
17-
* @return int
18-
*/
19-
public function getStartEpochTimestamp(): int;
20-
21-
/**
22-
* Returns system time clock value (MonotonicClock) when the Span was created
23-
* @return int
24-
*/
25-
public function getStart(): int;
26-
27-
/**
28-
* Returns system time clock value (MonotonicClock) when the Span was stopped
29-
* @return int|null
30-
*/
31-
public function getEnd(): ?int;
32-
33-
public function getAttributes(): Attributes;
34-
public function getLinks(): Links;
35-
public function getEvents(): Events;
36-
public function getStatus(): SpanStatus;
37-
3811
/**
3912
* Attributes SHOULD preserve the order in which they're set. Setting an attribute with the same key as an existing
4013
* attribute SHOULD overwrite the existing attribute's value.
@@ -90,6 +63,4 @@ public function setSpanStatus(string $code, ?string $description = null): Span;
9063
public function end(int $timestamp = null): Span;
9164

9265
public function isRecording(): bool;
93-
94-
public function isSampled(): bool;
9566
}

api/Trace/SpanOptions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace OpenTelemetry\Trace;
66

7+
use OpenTelemetry\Context\Context;
8+
79
/**
810
* The SpanOptions implementation is intended to be tightly coupled with the Span and Tracer implementations.
911
* Hopefully the Span object can implement SpanOptions so that the toSpan() call is almost a no-op, but prevents
@@ -14,8 +16,7 @@ interface SpanOptions
1416
public function setSpanName(string $name): SpanOptions;
1517
/** should default to INTERNAL if not called */
1618
public function setSpanKind(int $spanKind): SpanOptions;
17-
public function setParentContext(SpanContext $span): SpanOptions;
18-
public function setParentSpan(Span $span): SpanOptions;
19+
public function setParent(Context $parentContext): SpanOptions;
1920
public function addAttributes(Attributes $attributes): SpanOptions;
2021
public function addLinks(Links $links): SpanOptions;
2122

contrib/Newrelic/Exporter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GuzzleHttp\Psr7\HttpFactory;
1010
use InvalidArgumentException;
1111
use OpenTelemetry\Sdk\Trace;
12-
use OpenTelemetry\Trace as API;
1312
use Psr\Http\Client\ClientExceptionInterface;
1413
use Psr\Http\Client\ClientInterface;
1514
use Psr\Http\Client\NetworkExceptionInterface;
@@ -64,7 +63,7 @@ class Exporter implements Trace\Exporter
6463
* @var RequestFactoryInterface
6564
*/
6665
private $requestFactory;
67-
66+
6867
/**
6968
* @var StreamFactoryInterface
7069
*/
@@ -108,7 +107,7 @@ public function __construct(
108107
/**
109108
* Exports the provided Span data via the Newrelic protocol
110109
*
111-
* @param iterable<API\Span> $spans Array of Spans
110+
* @param iterable<Trace\ReadableSpan> $spans Array of Spans
112111
* @return int return code, defined on the Exporter interface
113112
*/
114113
public function export(iterable $spans): int

contrib/Newrelic/SpanConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace OpenTelemetry\Contrib\Newrelic;
66

7-
use OpenTelemetry\Trace\Span;
7+
use OpenTelemetry\Sdk\Trace\ReadableSpan;
88

99
class SpanConverter
1010
{
@@ -21,7 +21,7 @@ public function __construct(string $serviceName)
2121
$this->serviceName = $serviceName;
2222
}
2323

24-
public function convert(Span $span)
24+
public function convert(ReadableSpan $span)
2525
{
2626
$spanParent = $span->getParent();
2727
$row = [

contrib/Otlp/Exporter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use OpenTelemetry\Contrib\OtlpGrpc\Exporter as OtlpGrpcExporter;
1010
use OpenTelemetry\Contrib\OtlpHttp\Exporter as OtlpHttpExporter;
1111
use OpenTelemetry\Sdk\Trace;
12-
use OpenTelemetry\Trace as API;
1312
use Psr\Http\Client\ClientExceptionInterface;
1413
use Psr\Http\Client\ClientInterface;
1514
use Psr\Http\Client\NetworkExceptionInterface;
@@ -72,7 +71,7 @@ class Exporter implements Trace\Exporter
7271
* @var RequestFactoryInterface
7372
*/
7473
private $requestFactory;
75-
74+
7675
/**
7776
* @var StreamFactoryInterface
7877
*/
@@ -108,7 +107,7 @@ public function __construct(
108107
/**
109108
* Exports the provided Span data via the OTLP protocol
110109
*
111-
* @param iterable<API\Span> $spans Array of Spans
110+
* @param iterable<Trace\ReadableSpan> $spans Array of Spans
112111
* @return int return code, defined on the Exporter interface
113112
*/
114113
public function export(iterable $spans): int

contrib/Otlp/SpanConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace OpenTelemetry\Contrib\Otlp;
66

7-
use OpenTelemetry\Trace\Span;
7+
use OpenTelemetry\Sdk\Trace\ReadableSpan;
88

99
class SpanConverter
1010
{
@@ -40,7 +40,7 @@ private function sanitiseTagValue($value)
4040
return (string) $value;
4141
}
4242

43-
public function convert(Span $span)
43+
public function convert(ReadableSpan $span)
4444
{
4545
$spanParent = $span->getParent();
4646
$row = [

contrib/OtlpGrpc/Exporter.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Opentelemetry\Proto\Collector\Trace\V1\ExportTraceServiceRequest;
1010
use Opentelemetry\Proto\Collector\Trace\V1\TraceServiceClient;
1111
use OpenTelemetry\Sdk\Trace;
12-
use OpenTelemetry\Trace as API;
1312

1413
class Exporter implements Trace\Exporter
1514
{
@@ -53,7 +52,7 @@ class Exporter implements Trace\Exporter
5352
private $spanConverter;
5453

5554
private $metadata;
56-
55+
5756
/**
5857
* @var bool
5958
*/
@@ -126,15 +125,15 @@ public function getClientOptions(): array
126125
/**
127126
* Exports the provided Span data via the OTLP protocol
128127
*
129-
* @param iterable<API\Span> $spans Array of Spans
128+
* @param iterable<Trace\ReadableSpan> $spans Array of Spans
130129
* @return int return code, defined on the Exporter interface
131130
*/
132131
public function export(iterable $spans): int
133132
{
134133
if (!$this->running) {
135134
return Exporter::FAILED_NOT_RETRYABLE;
136135
}
137-
136+
138137
if (empty($spans)) {
139138
return Trace\Exporter::SUCCESS;
140139
}

contrib/OtlpGrpc/SpanConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Opentelemetry\Proto\Trace\V1\Span\SpanKind;
1717
use Opentelemetry\Proto\Trace\V1\Status;
1818
use Opentelemetry\Proto\Trace\V1\Status\StatusCode;
19-
use OpenTelemetry\Sdk\Trace\Span;
19+
use OpenTelemetry\Sdk\Trace\ReadableSpan;
2020
use OpenTelemetry\Sdk\Trace\SpanStatus;
2121

2222
class SpanConverter
@@ -78,7 +78,7 @@ public function as_otlp_span_kind($kind): int
7878
return SpanKind::SPAN_KIND_UNSPECIFIED;
7979
}
8080

81-
public function as_otlp_span(Span $span): CollectorSpan
81+
public function as_otlp_span(ReadableSpan $span): CollectorSpan
8282
{
8383
$end_timestamp = ($span->getStartEpochTimestamp() + $span->getDuration());
8484

contrib/OtlpHttp/Exporter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use InvalidArgumentException;
1010
use Opentelemetry\Proto\Collector\Trace\V1\ExportTraceServiceRequest;
1111
use OpenTelemetry\Sdk\Trace;
12-
use OpenTelemetry\Trace as API;
1312
use Psr\Http\Client\ClientExceptionInterface;
1413
use Psr\Http\Client\ClientInterface;
1514
use Psr\Http\Client\NetworkExceptionInterface;
@@ -124,7 +123,7 @@ public function __construct(
124123
/**
125124
* Exports the provided Span data via the OTLP protocol
126125
*
127-
* @param iterable<API\Span> $spans Array of Spans
126+
* @param iterable<Trace\ReadableSpan> $spans Array of Spans
128127
* @return int return code, defined on the Exporter interface
129128
*/
130129
public function export(iterable $spans): int

contrib/OtlpHttp/SpanConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Opentelemetry\Proto\Trace\V1\Span\SpanKind;
1717
use Opentelemetry\Proto\Trace\V1\Status;
1818
use Opentelemetry\Proto\Trace\V1\Status\StatusCode;
19-
use OpenTelemetry\Sdk\Trace\Span;
19+
use OpenTelemetry\Sdk\Trace\ReadableSpan;
2020
use OpenTelemetry\Sdk\Trace\SpanStatus;
2121

2222
class SpanConverter
@@ -76,7 +76,7 @@ public function as_otlp_span_kind($kind): int
7676
return SpanKind::SPAN_KIND_UNSPECIFIED;
7777
}
7878

79-
public function as_otlp_span(Span $span): CollectorSpan
79+
public function as_otlp_span(ReadableSpan $span): CollectorSpan
8080
{
8181
$end_timestamp = ($span->getStartEpochTimestamp() + $span->getDuration());
8282

0 commit comments

Comments
 (0)