承接 launchdarkly/server-sdk-otel 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

launchdarkly/server-sdk-otel

Composer 安装命令:

composer require launchdarkly/server-sdk-otel

包简介

LaunchDarkly Server-Side SDK for PHP — OpenTelemetry integration

README 文档

README

Run CI Packagist Documentation

LaunchDarkly overview

LaunchDarkly is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. Get started using LaunchDarkly today!

Overview

This package provides an OpenTelemetry integration for the LaunchDarkly PHP Server-Side SDK. It exposes a TracingHook that, when registered with an LDClient, enriches the active OpenTelemetry span with a feature_flag span event for every flag evaluation. The event carries the semantic-convention attributes defined by the OpenTelemetry feature-flag specification and the LaunchDarkly OTEL integration specification (see Attributes emitted).

Reach for this package when you already have OpenTelemetry instrumentation in place and want flag evaluations to show up on the traces that cover them. The hook is a pure consumer of the SDK's hooks API and adds no network or storage dependencies of its own.

Supported PHP versions

This package supports PHP 8.1, 8.2, 8.3, and 8.4. It is safe to use under any PHP SAPI (CLI, PHP-FPM, long-running worker pools); see PHP-FPM and short-lived request lifecycles for guidance on flushing spans in request-response environments.

PHP SAPI Supported Notes
CLI (scripts, workers) yes Nothing to configure.
PHP-FPM / mod_php (web requests) yes See FPM caveats below — span processors must flush before the request ends.
Long-running worker pools (RoadRunner, Swoole, etc.) yes Same rules as CLI; follow your pool's shutdown hooks to flush the tracer provider.

Dependencies

Dependency Version
launchdarkly/server-sdk >=6.8 (first release exposing the evaluation hooks API)
open-telemetry/api ^1.0
psr/log ^1.0, ^2.0, or ^3.0

open-telemetry/api is interface-only. A runtime OpenTelemetry SDK implementation is also required — typically open-telemetry/sdk plus at least one exporter (for example open-telemetry/exporter-otlp for OTLP/HTTP). This package does not pull the SDK in for you, since most applications already configure one.

If you are installing this package from source before launchdarkly/server-sdk has tagged its first hooks-ready release, you may need to track a compatible branch of the parent SDK until that tag lands.

Installation

composer require launchdarkly/server-sdk-otel

Quick start

<?php

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

use LaunchDarkly\LDClient;
use LaunchDarkly\LDContext;
use LaunchDarkly\OpenTelemetry\TracingHook;
use OpenTelemetry\API\Globals;

// Assumes your application has already configured an OpenTelemetry
// TracerProvider and registered it with OpenTelemetry\API\Globals.
$tracer = Globals::tracerProvider()->getTracer('my-app');

$client = new LDClient('sdk-key', [
    'hooks' => [new TracingHook()],
]);

$span = $tracer->spanBuilder('handle-request')->startSpan();
$scope = $span->activate();
try {
    $enabled = $client->variation(
        'my-flag-key',
        LDContext::create('user-123'),
        false,
    );
    // ...
} finally {
    $scope->detach();
    $span->end();
}

When $client->variation(...) runs inside the active span, the hook attaches a feature_flag event to that span. When no span is active, the hook is a no-op.

Configuring TracingHookOptions

TracingHookOptions is an immutable configuration object passed to the TracingHook constructor. All arguments are optional.

Option Type Default Purpose
includeValue bool false When true, attaches the serialized evaluated flag value as feature_flag.result.value. Be mindful of cardinality and sensitivity before enabling this in production.
addSpans bool false Experimental. When true, wraps every variation call in an LDClient.<method> child span in addition to the event. The exact span structure and naming may change in future releases.
environmentId string|null null Emitted as feature_flag.set.id. Takes precedence over the environment ID the LaunchDarkly SDK supplies via EvaluationSeriesContext; leave null to use the SDK-supplied value when one is available. Empty or whitespace-only input is rejected and stored as null (a warning is logged if a logger is supplied).
logger Psr\Log\LoggerInterface|null null Receives construction-time warnings from the options object (for example, an invalid environmentId). When null, no diagnostic output is produced.

Example:

use LaunchDarkly\OpenTelemetry\TracingHook;
use LaunchDarkly\OpenTelemetry\TracingHookOptions;

$hook = new TracingHook(new TracingHookOptions(
    includeValue: true,
    addSpans: false,
    environmentId: 'your-environment-id',
));

Attributes emitted

The hook emits the following attributes on the feature_flag span event. Attribute names and semantics follow the LaunchDarkly OTEL integration specification.

Required attributes (always emitted when the hook emits an event):

Attribute Value
feature_flag.key The flag key being evaluated.
feature_flag.provider.name The fixed string LaunchDarkly.
feature_flag.context.id The canonical key of the LDContext the flag is being evaluated for.

Optional attributes (emitted only when the corresponding condition is met):

Attribute Emitted when
feature_flag.result.value TracingHookOptions::$includeValue is true. Always serialized to a string; bool becomes "true"/"false", null becomes "null", and arrays/objects are JSON-encoded.
feature_flag.result.variationIndex The evaluation produced a non-null variation index. Emitted as an integer, including the value 0.
feature_flag.result.reason.inExperiment The evaluation reason has inExperiment=true. When false, the attribute is omitted entirely rather than emitted as false.
feature_flag.set.id TracingHookOptions::$environmentId is configured with a non-empty string, or the LaunchDarkly SDK supplies an environment ID on EvaluationSeriesContext. The configured value takes precedence.

When addSpans=true, the wrapper LDClient.<method> span carries only feature_flag.key and feature_flag.context.id; all other attributes remain on the feature_flag event on the caller's surrounding span.

When no span is active on the current OpenTelemetry context, or the active span has an invalid context, the hook emits nothing.

PHP-FPM and short-lived request lifecycles

Under PHP-FPM and similar request-response SAPIs, the PHP process hands control back to the web server as soon as a request completes, which can cut off span exports that a background processor has not yet flushed.

If you use BatchSpanProcessor, its in-memory queue is not guaranteed to flush before the process returns to the pool, and spans emitted late in the request may be lost. You have two straightforward options:

  1. Use SimpleSpanProcessor, which exports each span synchronously on end. This is the simplest correct default for FPM deployments.
  2. Continue using BatchSpanProcessor, but register a shutdown hook that flushes the tracer provider before the process exits:
register_shutdown_function(static function () use ($tracerProvider): void {
    $tracerProvider->shutdown();
});

Worker pools (RoadRunner, Swoole, and similar) keep the PHP process alive across requests, so BatchSpanProcessor works as intended there. Follow your pool's shutdown hooks to call $tracerProvider->shutdown() at process exit.

Known limitations

When addSpans=true, the wrapper span name is built from the PHP SDK method string (variation, variationDetail, migrationVariation), producing LDClient.variation, LDClient.variationDetail, and LDClient.migrationVariation. Aligning the casing with other LaunchDarkly SDKs is a concern for the core PHP Server-Side SDK and is tracked separately.

Contributing

We encourage pull requests and other contributions from the community. Check out our contributing guidelines for instructions on how to contribute to this SDK.

License

Apache 2.0. See LICENSE.txt for the full text.

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the 'gold' plan get access to more features than users in the 'silver' plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read our documentation for a complete list.
  • Explore LaunchDarkly

launchdarkly/server-sdk-otel 适用场景与选型建议

launchdarkly/server-sdk-otel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「launchdarkly」 「launchdarkly php」 「opentelemetry」 「otel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 launchdarkly/server-sdk-otel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 launchdarkly/server-sdk-otel 我们能提供哪些服务?
定制开发 / 二次开发

基于 launchdarkly/server-sdk-otel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2026-04-28