Skip to content

Nevay/otel-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

OpenTelemetry SDK

Asynchronous OpenTelemetry SDK based on Revolt.

This metapackage contains the basic components that are required for creating traces/metrics/logs through the official OpenTelemetry API and sending them to an OTLP/HTTP compatible collector1. Additional components (e.g. resource detectors, non-OTLP exporters) can be installed as separate packages.

Projects using ReactPHP libraries can use this SDK together with revolt/event-loop-adapter-react.

Installation

composer require tbachert/otel-sdk

Usage

Refer to the official OpenTelemetry documentation for general usage of the OpenTelemetry API.

Manual SDK initialization

$resource = Resource::detect()
    ->merge(Resource::create(['foo' => 'bar']));

$tracerProvider = (new TracerProviderBuilder())
    ->addResource($resource)
    ->addSpanProcessor(new BatchSpanProcessor(new OtlpStreamSpanExporter(getStdout())))
    ->build($logger);
$meterProvider = (new MeterProviderBuilder())
    ->addResource($resource)
    ->addMetricReader(new PeriodicExportingMetricReader(new OtlpStreamMetricExporter(getStdout())))
    ->build($logger);
$loggerProvider = (new LoggerProviderBuilder())
    ->addResource($resource)
    ->addLogRecordProcessor(new BatchLogRecordProcessor(new OtlpStreamLogRecordExporter(getStdout())))
    ->build($logger);
awaitAll([
    async($tracerProvider->shutdown(...)),
    async($meterProvider->shutdown(...)),
    async($loggerProvider->shutdown(...)),
]);

Initialization from configuration file

$result = Config::loadFile(__DIR__ . '/kitchen-sink.yaml');

Initialization from environment variables

See also PHP SDK configuration.

$result = Env::load();

Footnotes

  1. It is highly recommended to install the ext-protobuf extension if using one of the OTLP exporters due to its significantly better performance.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published