定制 tbachert/otel-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱: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. 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.

Initialization from configuration file

$config = 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 instances on startup.

Initialization from environment variables

$config = Config::loadFromEnv();
Automatic initialization from environment variables

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

Manual SDK initialization

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

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

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.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固