tbachert/otel-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tbachert/otel-sdk

Composer 安装命令:

composer require tbachert/otel-sdk

包简介

OpenTelemetry SDK

README 文档

README

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__ . '/sdk-config.yaml');
Automatic initialization from configuration file

The OTEL_EXPERIMENTAL_CONFIG_FILE environment variable can be set to initialize the global instrumentation instances on startup.

Initialization from environment variables

$result = Env::load();
Automatic initialization from environment variables

The OTEL_PHP_AUTOLOAD_ENABLED environment variable can be set to true to initialize the global instrumentation instances on startup.

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.

统计信息

  • 总下载量: 57
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2024-05-06