-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* merge otlp exporters continuing on from Nevay's work, this removes the individual OtlpHttp and OtlpGrpc exporters, and replaces with Otlp\Exporter using a transport to manage grpc and http/protobuf complexity. * tidy * use mockery overload instead of prototype clone * making all smoke-test examples work * removing startBatch verified that the call attributes have the same values when using TraceServiceClient * tidy * tidy * Revert "use mockery overload instead of prototype clone" This reverts commit bbb685b. Mocking proto-generated files segfaults with ext-protobuf (which is harder to diagnose when running in a child process, which was required for fancy mockery mocking of "new". So, back to the prototype approach, and skip the tests if ext-protobuf enabled. * tests without mocking protobuf * test * typo * reverting FromConnectionStringInterface * grpc headers * revert to dumb transports, handle multiple protocols * tidy, adding initial otlp json support * self-review * linting * remove redundant interface * Revert "remove redundant interface" This reverts commit 350d40c. * fix getFloat Co-authored-by: Tobias Bachert <[email protected]> * move withSignal into otlp-specific interface * moving exporter/transport env handling into a new factory * linting * remove unused code * tidy * moving OtlpHttp into Otlp * removing OtlpTransportFactoryInterface * fix style * fixing psalm error * addressing review feedback * replacing removed code * fixing example Co-authored-by: Tobias Bachert <[email protected]>
- Loading branch information
Showing
64 changed files
with
985 additions
and
1,210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,7 @@ deptrac: | |
Contrib: | ||
- +SDK | ||
- +OtelProto | ||
- Grpc | ||
- Prometheus | ||
- Thrift | ||
- JaegerThrift | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
use OpenTelemetry\API\Common\Signal\Signals; | ||
use OpenTelemetry\Contrib\Grpc\GrpcTransportFactory; | ||
use OpenTelemetry\Contrib\Otlp\MetricExporter; | ||
use OpenTelemetry\Example\ExampleMetricsGenerator; | ||
use OpenTelemetry\SDK\Common\Time\ClockFactory; | ||
use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader; | ||
|
||
\OpenTelemetry\SDK\Common\Log\LoggerHolder::set(new \Monolog\Logger('grpc', [new \Monolog\Handler\StreamHandler('php://stderr')])); | ||
|
||
$clock = ClockFactory::getDefault(); | ||
|
||
$reader = new ExportingReader( | ||
new MetricExporter( | ||
(new GrpcTransportFactory())->withSignal(Signals::METRICS)->create('http://collector:4317') | ||
), | ||
$clock | ||
); | ||
|
||
$metricsGenerator = new ExampleMetricsGenerator($reader, $clock); | ||
$metricsGenerator->generate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
use OpenTelemetry\Contrib\Otlp\MetricExporter; | ||
use OpenTelemetry\Example\ExampleMetricsGenerator; | ||
use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory; | ||
use OpenTelemetry\SDK\Common\Time\ClockFactory; | ||
use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader; | ||
|
||
$clock = ClockFactory::getDefault(); | ||
$reader = new ExportingReader( | ||
new MetricExporter( | ||
PsrTransportFactory::discover()->create('http://collector:4318/v1/metrics', 'application/json') | ||
), | ||
$clock | ||
); | ||
|
||
$metricsGenerator = new ExampleMetricsGenerator($reader, $clock); | ||
$metricsGenerator->generate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../../../../vendor/autoload.php'; | ||
|
||
use OpenTelemetry\Contrib\Otlp\MetricExporter; | ||
use OpenTelemetry\Example\ExampleMetricsGenerator; | ||
use OpenTelemetry\SDK\Common\Export\Stream\StreamTransport; | ||
use OpenTelemetry\SDK\Common\Time\ClockFactory; | ||
use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader; | ||
|
||
$clock = ClockFactory::getDefault(); | ||
$reader = new ExportingReader( | ||
new MetricExporter( | ||
new StreamTransport(STDOUT, 'application/x-ndjson') | ||
), | ||
$clock | ||
); | ||
|
||
$metricsGenerator = new ExampleMetricsGenerator($reader, $clock); | ||
$metricsGenerator->generate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenTelemetry\Example; | ||
|
||
use OpenTelemetry\API\Metrics\ObserverInterface; | ||
use OpenTelemetry\SDK\Common\Attribute\Attributes; | ||
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory; | ||
use OpenTelemetry\SDK\Common\Time\ClockInterface; | ||
use OpenTelemetry\SDK\Metrics\Exemplar\ExemplarFilter\WithSampledTraceExemplarFilter; | ||
use OpenTelemetry\SDK\Metrics\MeterProvider; | ||
use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader; | ||
use OpenTelemetry\SDK\Metrics\StalenessHandler\ImmediateStalenessHandlerFactory; | ||
use OpenTelemetry\SDK\Metrics\View\CriteriaViewRegistry; | ||
use OpenTelemetry\SDK\Resource\ResourceInfoFactory; | ||
|
||
class ExampleMetricsGenerator | ||
{ | ||
private ExportingReader $reader; | ||
private ClockInterface $clock; | ||
|
||
public function __construct(ExportingReader $reader, ClockInterface $clock) | ||
{ | ||
$this->reader = $reader; | ||
$this->clock = $clock; | ||
} | ||
|
||
public function generate(): void | ||
{ | ||
$meterProvider = new MeterProvider( | ||
null, | ||
ResourceInfoFactory::defaultResource(), | ||
$this->clock, | ||
Attributes::factory(), | ||
new InstrumentationScopeFactory(Attributes::factory()), | ||
[$this->reader], | ||
new CriteriaViewRegistry(), | ||
new WithSampledTraceExemplarFilter(), | ||
new ImmediateStalenessHandlerFactory(), | ||
); | ||
|
||
$meter = $meterProvider->getMeter('io.opentelemetry.contrib.php'); | ||
$meter | ||
->createObservableUpDownCounter('process.memory.usage', 'By', 'The amount of physical memory in use.') | ||
->observe(static function (ObserverInterface $observer): void { | ||
$observer->observe(memory_get_usage(true)); | ||
}); | ||
|
||
$serverDuration = $meter | ||
->createHistogram('http.server.duration', 'ms', 'measures the duration inbound HTTP requests'); | ||
|
||
// During the time range (T0, T1]: | ||
$serverDuration->record(50, ['http.method' => 'GET', 'http.status_code' => 200]); | ||
$serverDuration->record(100, ['http.method' => 'GET', 'http.status_code' => 200]); | ||
$serverDuration->record(1, ['http.method' => 'GET', 'http.status_code' => 500]); | ||
$this->reader->collect(); | ||
|
||
// During the time range (T1, T2]: | ||
$this->reader->collect(); | ||
|
||
// During the time range (T2, T3]: | ||
$serverDuration->record(5, ['http.method' => 'GET', 'http.status_code' => 500]); | ||
$serverDuration->record(2, ['http.method' => 'GET', 'http.status_code' => 500]); | ||
$this->reader->collect(); | ||
|
||
// During the time range (T3, T4]: | ||
$serverDuration->record(100, ['http.method' => 'GET', 'http.status_code' => 200]); | ||
$this->reader->collect(); | ||
|
||
// During the time range (T4, T5]: | ||
$serverDuration->record(100, ['http.method' => 'GET', 'http.status_code' => 200]); | ||
$serverDuration->record(30, ['http.method' => 'GET', 'http.status_code' => 200]); | ||
$serverDuration->record(50, ['http.method' => 'GET', 'http.status_code' => 200]); | ||
$this->reader->collect(); | ||
|
||
$meterProvider->shutdown(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.