ifcastle/open-telemetry 问题修复 & 功能扩展

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

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

ifcastle/open-telemetry

最新稳定版本:v0.1.1

Composer 安装命令:

composer require ifcastle/open-telemetry

包简介

Simplified library for OpenTelemetry.

README 文档

README

An alternative version of the library for the OpenTelemetry standard on PHP.

Why is this needed?

The original library for OpenTelemetry has a complex trace-building architecture, leading to an increase in supporting code. This library offers a simpler and flatter interface for generating telemetry.

Installation

Example

<?php

declare(strict_types=1);

require_once __DIR__ . '/vendor/autoload.php';

use IfCastle\OpenTelemetry\Tracer;

$tracer = new Tracer(...);

$span = $tracer->createSpan('example-span', SpanKindEnum::INTERNAL);

try {
    $span->addEvent('event-name', ['key' => 'value'])
         ->setStatus(StatusCodeEnum::OK);
} catch (Throwable $exception) {
    $span->registerException($exception);
    throw $e;
} finally {
    $span->end();
}

Simplified diagram

The simplified diagram shows the structure used for creating traces:

  • TracerInterface is responsible for aggregating telemetry in the application. It is a factory class that creates a Trace.

  • TraceInterface and SpanInterface represent the Trace and Span structures, according to the OpenTelemetry definitions. They allow manipulating the data within the entities in a convenient way.

  • To record telemetry, you can use only the TracerInterface, or combine it with the SpanInterface.

@startuml class-diagram

  interface "TracerInterface" as TracerInterface {
    +newTelemetryContext()
    +createTrace()
    +endTrace(trace)
    +createSpan(spanName, spanKind, instrumentationScope, attributes)
    +endSpan(span)
    +registerLog(instrumentationScope, level, body, attributes)
    +registerException(throwable, attributes)
  }

  interface "SpanInterface" as SpanInterface {
    +addEvent(name, attributes, timestamp)
    +recordException(exception, attributes)
    +end(endEpochNanos)
    +addLink(link)
  }

  interface "TraceInterface" as TraceInterface {
    +newSpanId()
    +getTraceId()
    +getCurrentSpanId()
    +getCurrentSpan()
    +createSpan(spanName, spanKind, instrumentationScope, attributes)
    +endSpan(span)
    +end()
  }

  TraceInterface ..> SpanInterface
  TracerInterface ..> SpanInterface
  TracerInterface ..> TraceInterface

@enduml

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-24