[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor otlp exporter #838

Merged
merged 38 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
63fe6b0
merge otlp exporters
brettmc Oct 6, 2022
726c6c7
tidy
brettmc Oct 6, 2022
bbb685b
use mockery overload instead of prototype clone
brettmc Oct 6, 2022
e4687bf
making all smoke-test examples work
brettmc Oct 6, 2022
d1b7455
removing startBatch
brettmc Oct 7, 2022
1d0e308
tidy
brettmc Oct 7, 2022
78d05f5
tidy
brettmc Oct 7, 2022
09cff4f
Revert "use mockery overload instead of prototype clone"
brettmc Oct 7, 2022
09c0740
tests without mocking protobuf
brettmc Oct 7, 2022
651dcd5
test
brettmc Oct 7, 2022
293bfbe
typo
brettmc Oct 7, 2022
1f6a2f6
reverting FromConnectionStringInterface
brettmc Oct 7, 2022
d7c0f30
grpc headers
brettmc Oct 9, 2022
5680dcb
revert to dumb transports, handle multiple protocols
brettmc Oct 11, 2022
c8092e4
Merge branch 'main' into refactor-otlp-exporter
brettmc Oct 11, 2022
548b84e
Merge branch 'main' into refactor-otlp-exporter
brettmc Oct 12, 2022
b3108f5
tidy, adding initial otlp json support
brettmc Oct 12, 2022
71242d7
self-review
brettmc Oct 12, 2022
2e019e4
linting
brettmc Oct 12, 2022
350d40c
remove redundant interface
brettmc Oct 12, 2022
0bf4581
Revert "remove redundant interface"
brettmc Oct 12, 2022
8b31d8e
fix getFloat
brettmc Oct 12, 2022
9e095f6
move withSignal into otlp-specific interface
brettmc Oct 12, 2022
3764f30
Merge branch 'refactor-otlp-exporter' of github.com:brettmc/opentelem…
brettmc Oct 12, 2022
42e1eeb
moving exporter/transport env handling into a new factory
brettmc Oct 13, 2022
7801ed8
Merge branch 'main' into refactor-otlp-exporter
brettmc Oct 13, 2022
1675f35
linting
brettmc Oct 13, 2022
8e5c043
remove unused code
brettmc Oct 13, 2022
a566a66
tidy
brettmc Oct 13, 2022
c88648b
moving OtlpHttp into Otlp
brettmc Oct 16, 2022
a28097e
Merge branch 'main' into refactor-otlp-exporter
brettmc Oct 16, 2022
b432fcc
removing OtlpTransportFactoryInterface
brettmc Oct 16, 2022
98b9018
fix style
brettmc Oct 16, 2022
167568c
fixing psalm error
brettmc Oct 16, 2022
1006285
addressing review feedback
brettmc Oct 20, 2022
27bd5ff
Merge branch 'main' into refactor-otlp-exporter
brettmc Nov 1, 2022
b9a0ca3
replacing removed code
brettmc Nov 1, 2022
0bc286e
fixing example
brettmc Nov 1, 2022
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
Prev Previous commit
Next Next commit
tidy, adding initial otlp json support
  • Loading branch information
brettmc committed Oct 12, 2022
commit b3108f5aefc6549d673efdd6879bbf1d29157bf5
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN chmod +x /usr/local/bin/install-php-extensions; \
zip \
pcntl \
grpc \
protobuf \
protobuf \
sockets \
intl \
@composer \
Expand Down
4 changes: 1 addition & 3 deletions examples/metrics/features/exporters/otlp_grpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use OpenTelemetry\API\Common\Signal\Signals;
use OpenTelemetry\Contrib\Grpc\GrpcTransportFactory;
use OpenTelemetry\Contrib\Otlp\MetricExporter;
use OpenTelemetry\Contrib\Otlp\Protocols;
use OpenTelemetry\Example\ExampleMetricsGenerator;
use OpenTelemetry\SDK\Common\Time\ClockFactory;
use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader;
Expand All @@ -18,8 +17,7 @@

$reader = new ExportingReader(
new MetricExporter(
(new GrpcTransportFactory())->withSignal(Signals::METRICS)->create('http://collector:4317'),
Protocols::GRPC,
(new GrpcTransportFactory())->withSignal(Signals::METRICS)->create('http://collector:4317')
),
$clock
);
Expand Down
4 changes: 1 addition & 3 deletions examples/metrics/features/exporters/otlp_http.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use OpenTelemetry\API\Common\Signal\Signals;
use OpenTelemetry\Contrib\Otlp\MetricExporter;
use OpenTelemetry\Contrib\Otlp\Protocols;
use OpenTelemetry\Example\ExampleMetricsGenerator;
use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory;
use OpenTelemetry\SDK\Common\Time\ClockFactory;
Expand All @@ -15,8 +14,7 @@
$clock = ClockFactory::getDefault();
$reader = new ExportingReader(
new MetricExporter(
PsrTransportFactory::discover()->withSignal(Signals::METRICS)->create('http://collector:4318/v1/metrics', 'application/json'),
Protocols::HTTP_JSON //or Protocols::HTTP_PROTOBUF
PsrTransportFactory::discover()->withSignal(Signals::METRICS)->create('http://collector:4318/v1/metrics', 'application/json')
),
$clock
);
Expand Down
4 changes: 1 addition & 3 deletions examples/metrics/features/exporters/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
require __DIR__ . '/../../../../vendor/autoload.php';

use OpenTelemetry\Contrib\Otlp\MetricExporter;
use OpenTelemetry\Contrib\Otlp\Protocols;
use OpenTelemetry\Example\ExampleMetricsGenerator;
use OpenTelemetry\SDK\Common\Export\Stream\StreamTransport;
use OpenTelemetry\SDK\Common\Time\ClockFactory;
Expand All @@ -14,8 +13,7 @@
$clock = ClockFactory::getDefault();
$reader = new ExportingReader(
new MetricExporter(
new StreamTransport(STDOUT, 'application/x-ndjson'),
Protocols::HTTP_ND_JSON
new StreamTransport(STDOUT, 'application/x-ndjson')
),
$clock
);
Expand Down
34 changes: 34 additions & 0 deletions examples/traces/features/exporters/otlp_http_json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);
require __DIR__ . '/../../../../vendor/autoload.php';

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use OpenTelemetry\Contrib\Otlp\Protocols;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use OpenTelemetry\Contrib\OtlpHttp\OtlpHttpTransportFactory;
use OpenTelemetry\SDK\Common\Log\LoggerHolder;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;

LoggerHolder::set(new Logger('otlp-example', [new StreamHandler('php://stderr')]));

$transport = (new OtlpHttpTransportFactory())->withProtocol(Protocols::HTTP_JSON)->create('http://collector:4318');
$exporter = new SpanExporter($transport);

echo 'Starting OTLP+json example';

$tracerProvider = new TracerProvider(
new SimpleSpanProcessor(
$exporter
)
);
$tracer = $tracerProvider->getTracer('io.opentelemetry.contrib.php');

$root = $span = $tracer->spanBuilder('root')->startSpan();
$root->end();
echo PHP_EOL . 'OTLP+json example complete! ';

echo PHP_EOL;
$tracerProvider->shutdown();
3 changes: 2 additions & 1 deletion src/Contrib/Otlp/ProtobufSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private function __construct(string $contentType)
}

/**
* @param TransportInterface<SUPPORTED_CONTENT_TYPES> $transport
* @psalm-param TransportInterface<SUPPORTED_CONTENT_TYPES> $transport
*/
public static function forTransport(TransportInterface $transport): ProtobufSerializer
{
Expand All @@ -50,6 +50,7 @@ public function serialize(Message $message): string
case self::PROTOBUF:
return $message->serializeToString();
case self::JSON:
//@todo https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md#json-protobuf-encoding
return $message->serializeToJsonString();
case self::NDJSON:
return $message->serializeToJsonString() . "\n";
Expand Down
4 changes: 2 additions & 2 deletions src/Contrib/Otlp/Protocols.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class Protocols
public const GRPC = KnownValues::VALUE_GRPC;
public const HTTP_PROTOBUF = KnownValues::VALUE_HTTP_PROTOBUF;
public const HTTP_JSON = KnownValues::VALUE_HTTP_JSON;
public const HTTP_ND_JSON = KnownValues::VALUE_HTTP_NDJSON;
public const HTTP_NDJSON = KnownValues::VALUE_HTTP_NDJSON;
private const PROTOCOLS = [
self::GRPC => 'application/x-protobuf',
self::HTTP_PROTOBUF => 'application/x-protobuf',
self::HTTP_JSON => 'application/json',
self::HTTP_ND_JSON => 'application/x-ndjson',
self::HTTP_NDJSON => 'application/x-ndjson',
];

public static function validate(string $protocol): void
Expand Down
2 changes: 0 additions & 2 deletions src/SDK/Common/Export/TransportInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
*/
interface TransportInterface
{
public const CONTENT_TYPE_PROTOBUF = 'application/x-protobuf';

public function contentType(): string;

public function send(string $payload, ?CancellationInterface $cancellation = null): FutureInterface;
Expand Down
5 changes: 4 additions & 1 deletion src/SDK/Trace/ExporterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ExporterFactory
'zipkin+http' => '\OpenTelemetry\Contrib\Zipkin\Exporter',
'otlp+grpc' => '\OpenTelemetry\Contrib\Otlp\SpanExporter',
'otlp+http' => '\OpenTelemetry\Contrib\Otlp\SpanExporter',
'otlp+json' => '\OpenTelemetry\Contrib\Otlp\SpanExporter',
'newrelic+http' => '\OpenTelemetry\Contrib\Newrelic\Exporter',
'zipkintonewrelic+http' => '\OpenTelemetry\Contrib\ZipkinToNewrelic\Exporter',
// this entry exists only for testing purposes
Expand All @@ -36,10 +37,12 @@ class ExporterFactory
private const KNOWN_TRANSPORT_FACTORIES = [
'otlp+grpc' => '\OpenTelemetry\Contrib\Grpc\GrpcTransportFactory',
'otlp+http' => '\OpenTelemetry\Contrib\OtlpHttp\OtlpHttpTransportFactory',
'otlp+json' => '\OpenTelemetry\Contrib\OtlpHttp\OtlpHttpTransportFactory',
];
private const KNOWN_TRANSPORT_PROTOCOLS = [
'otlp+grpc' => KnownValues::VALUE_GRPC,
'otlp+http' => KnownValues::VALUE_HTTP_PROTOBUF,
'otlp+json' => KnownValues::VALUE_HTTP_JSON,
];

private const DEFAULT_SERVICE_NAME = 'unknown_service';
Expand Down Expand Up @@ -117,7 +120,7 @@ public function fromEnvironment(): ?SpanExporterInterface
case Values::VALUE_HTTP_PROTOBUF:
return self::buildExporterWithTransport('otlp+http');
case Values::VALUE_HTTP_JSON:
throw new InvalidArgumentException('otlp+http/json not implemented');
return self::buildExporterWithTransport('otlp+json');
default:
throw new InvalidArgumentException('Unknown protocol: ' . $protocol);
}
Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/SDK/Trace/ExporterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public function envProvider(): array
['OTEL_EXPORTER_OTLP_PROTOCOL' => 'grpc'],
Contrib\Otlp\SpanExporter::class,
],
'otlp+json from protocol' => [
'otlp',
['OTEL_EXPORTER_OTLP_PROTOCOL' => 'http/json'],
Contrib\Otlp\SpanExporter::class,
],
'console' => [
'console', [], ConsoleSpanExporter::class,
],
Expand Down Expand Up @@ -149,10 +154,6 @@ public function invalidEnvProvider(): array
'zipkin' => ['zipkin'],
'newrelic' => ['newrelic'],
'zipkintonewrelic' => ['zipkintonewrelic'],
'otlp+http/json' => [
'otlp',
['OTEL_EXPORTER_OTLP_PROTOCOL' => 'http/json'],
],
'otlp+invalid protocol' => [
'otlp',
['OTEL_EXPORTER_OTLP_PROTOCOL' => 'foo'],
Expand Down