Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .nix/fnox/wrappers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
gh,
blackfire,
composer,
terraform,
}:

let
Expand Down Expand Up @@ -36,4 +37,16 @@ in
program = "${blackfire}/bin/blackfire";
secrets = [ "BLACKFIRE_CLIENT_ID" "BLACKFIRE_CLIENT_TOKEN" ];
};

terraform = with-secrets "terraform" {
program = "${terraform}/bin/terraform";
secrets = [
"CLOUDFLARE_API_TOKEN"
"TF_VAR_account_id"
"TF_VAR_zone_id"
"AWS_ACCESS_KEY_ID"
"AWS_SECRET_ACCESS_KEY"
"AWS_ENDPOINT_URL_S3"
];
};
}
85 changes: 53 additions & 32 deletions documentation/components/bridges/symfony-telemetry-bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ instruments console commands, and sends data to OpenTelemetry-compatible backend

[PACKAGE_NAV]

Guides that show the bundle at work, step by step:

- [Symfony monitoring with OpenTelemetry: requests, commands and SQL queries](/guides/symfony-monitoring-with-opentelemetry/)
- [Find slow Doctrine queries in Symfony in production](/guides/find-slow-doctrine-queries-in-symfony/)
- [OpenTelemetry Collector for PHP: keep the PHP process light](/guides/opentelemetry-collector-for-php/)

[TOC]

## Installation
Expand All @@ -26,8 +32,8 @@ Bridge](/documentation/components/bridges/telemetry-otlp-bridge.md).
The bundle connects the Flow PHP Telemetry library to Symfony applications. It gives you:

- Automatic resource detection: detects the service name, version, environment, OS, host, and process information
- 8 auto-instrumentation options: HTTP kernel, console, messenger, Twig, HTTP client, PSR-18 client, Doctrine DBAL, and
cache
- 9 auto-instrumentation options: HTTP kernel, security, console, messenger, Twig, HTTP client, PSR-18 client, Doctrine
DBAL, and cache
- Context propagation: W3C TraceContext and Baggage support for distributed tracing
- Configurable exporters: console, memory, void, or OTLP with multiple transport options
- Full Symfony configuration: you configure everything through the Symfony configuration system
Expand Down Expand Up @@ -74,8 +80,7 @@ flow_telemetry:
enabled: true # Enable resource detectors (default: true)
static:
cache:
enabled: true # Cache static attributes (default: true)
path: null # Cache file path (default: sys_get_temp_dir()/flow_telemetry_resource_<env>.cache)
enabled: true # Cache the os, host and git attributes (default: true)
os:
enabled: true # Detect os.type, os.name, os.version, os.description
host:
Expand All @@ -86,6 +91,10 @@ flow_telemetry:
enabled: true # Detect deployment.environment.name from kernel environment
environment:
enabled: true # Read OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES
git:
enabled: false # Detect vcs.ref.head.* and vcs.repository.url.full with the git binary (default: false)
binary: git # Path to the git binary (default: resolved from $PATH)
working_directory: null # Directory to run git in (default: %kernel.project_dir%)
dynamic:
process:
enabled: true # Detect process.pid, process.runtime.*, process.executable.*
Expand All @@ -103,19 +112,22 @@ Detector types:
| `host` | `HostDetector` | static | `host.name`, `host.arch`, `host.id` |
| `service` | `ComposerDetector` | static | `service.name`, `service.version` (from composer.json) |
| `deployment` | `SymfonyDeploymentDetector` | static | `deployment.environment.name` (from kernel environment) |
| `environment` | `EnvironmentDetector` | static | Reads `OTEL_SERVICE_NAME` and `OTEL_RESOURCE_ATTRIBUTES` env vars |
| `git` | `GitDetector` | static | `vcs.ref.head.*`, `vcs.repository.url.full` (off by default) |
| `environment` | `EnvironmentDetector` | dynamic | Reads `OTEL_SERVICE_NAME` and `OTEL_RESOURCE_ATTRIBUTES` env vars |
| `process` | `ProcessDetector` | dynamic | `process.pid`, `process.runtime.*`, `process.executable.*` |

Static detectors are cached by default. Dynamic detectors run on every request and every command.
Only the two detections that cost something are cached:

| Attributes | Cache file | Lifetime |
|------------------|-----------------------------------------------------------|---------------------------------------------|
| `os.*`, `host.*` | `sys_get_temp_dir()/flow_telemetry_resource_host.cache` | the host. All applications share the file |
| `vcs.*` (git) | `%kernel.cache_dir%/flow_telemetry_resource_git.cache` | the release. `cache:clear` removes the file |

The cache file is outside the Symfony cache lifecycle on purpose. A Symfony cache build (with `cache:warmup`) at image
build time otherwise freezes runtime attributes, such as `host.name` or `process.pid`, from the build container. The
default location, `sys_get_temp_dir()`, keeps one cache for each runtime and prevents this problem. The default filename
contains the kernel environment (`flow_telemetry_resource_<env>.cache`). Thus, a change of `APP_ENV`, for example from
dev to prod, does not serve an old `deployment.environment.name`. To clear the cached values, delete the cache file or
restart the process. `cache:clear` does not touch the file.
Every other attribute is read in every process. A new `service.version`, a change of `resource.custom` or of an
`OTEL_*` variable applies at once. The host file is outside the Symfony cache on purpose: a cache build at image build
time (`cache:warmup`) does not freeze `host.name` from the build container.

Custom attributes override auto-detected values.
Custom attributes override detected values and the `OTEL_*` variables.

### Clock Configuration

Expand Down Expand Up @@ -1193,9 +1205,9 @@ flow_telemetry:
trace_controller_arguments: false # controller.get_arguments aggregate span (default OFF)
trace_controller_argument_resolvers: false # per-resolver controller.argument_value_resolver spans (default OFF)
exclude_paths:
- path: '/_profiler'
- path: '/_wdt'
- path: '/health'
- path: '#^/_profiler#' # Regex: /_profiler and everything below it
- path: '#^/_wdt#'
- path: '/health' # Exact path
method: GET
- path: '/^\/api\/internal\/.*/' # Regex pattern
```
Expand Down Expand Up @@ -1418,7 +1430,7 @@ flow_telemetry:
trace_blocks: false # Trace block rendering
trace_macros: false # Trace macro execution
exclude_templates:
- '@WebProfiler'
- '/^@WebProfiler\//'
- '/^@Debug\/.*/'
```

Expand Down Expand Up @@ -1491,7 +1503,7 @@ flow_telemetry:
dbal:
enabled: true
max_sql_length: 1000 # Max db.query.text length (0 = no limit)
collect_metrics: true # Emit db.client.operation.duration + db.client.response.returned_rows
collect_metrics: true # Emit the db.client.operation.duration histogram
include_parameters: false # Include bound statement parameters (security consideration)
max_parameters: 10 # Max parameters to include when include_parameters is enabled
max_parameter_length: 100 # Max length per included parameter value
Expand All @@ -1503,6 +1515,9 @@ flow_telemetry:
- 'cache_items'
```

A statement that changes rows (`INSERT`, `UPDATE`, `DELETE`) gets the attribute `flow.db.response.affected_rows`. A
statement that returns a result set gets no row count: the rows are fetched after the span ends.

#### Cache

Traces Symfony Cache operations.
Expand Down Expand Up @@ -1558,10 +1573,10 @@ example `cache_items`.

The cache instrumentation also emits hit and miss counters. To export them, configure a `meter_provider`:

| Metric | Instrument | Unit | Emitted |
|---------------------|------------|--------------|---------------------|
| `flow.cache.hits` | Counter | `operations` | once per cache hit |
| `flow.cache.misses` | Counter | `operations` | once per cache miss |
| Metric | Instrument | Unit | Emitted |
|---------------------|------------|---------------|---------------------|
| `flow.cache.hits` | Counter | `{operation}` | once per cache hit |
| `flow.cache.misses` | Counter | `{operation}` | once per cache miss |

### Web Profiler

Expand Down Expand Up @@ -1659,7 +1674,8 @@ Behavior:
a clear error.
- When `framework_logger` is `null` and Symfony's `logger` service is the default
`Symfony\Component\HttpKernel\Log\Logger`, the bundle automatically aliases `logger` to
`flow.telemetry.default.logger.psr3`.
`flow.telemetry.default.logger.psr3`. For this, `logger_provider` must have a processor other than `void`, or
`console_output` must be on. With the default `void` processor the Symfony logger stays, so no log record is lost.
- When `framework_logger` is `null` and another bundle provides `logger` (for example, Monolog or a custom alias), the
bundle does not change `logger`.

Expand Down Expand Up @@ -1873,11 +1889,16 @@ final class OrderService
{
$tracer = $this->telemetry->tracer('order-service');

$tracer->trace('process_order', function () use ($orderId) {
$span = $tracer->span('process_order');
$span->setAttribute('order.id', $orderId);
$scope = $tracer->activate($span);

try {
// Your order processing logic
}, [
'order.id' => $orderId,
]);
} finally {
$scope->detach();
$tracer->complete($span);
}
}
}
```
Expand Down Expand Up @@ -2007,15 +2028,15 @@ final class CheckoutController extends AbstractController
$meter = $this->telemetry->meter('business-metrics');

// Counter
$meter->counter('orders_processed')
$meter->createCounter('orders_processed')
->add(1, ['status' => 'completed']);

// Histogram
$meter->histogram('order_value')
$meter->createHistogram('order_value')
->record(99.99, ['currency' => 'USD']);

// Gauge
$meter->gauge('active_users')
$meter->createGauge('active_users')
->record(42);
```

Expand Down Expand Up @@ -2119,8 +2140,8 @@ flow_telemetry:
http_kernel:
enabled: true
exclude_paths:
- path: '/_profiler'
- path: '/_wdt'
- path: '#^/_profiler#'
- path: '#^/_wdt#'
- path: '/health'
method: GET
console:
Expand Down
24 changes: 21 additions & 3 deletions documentation/components/libs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ signal type and gives access to Tracers, Meters, and Loggers.
> clean contracts, and no magic.
>
> Our contracts are [here](/documentation/components/libs/telemetry/contracts.md).
>
> Flow Telemetry is not built on the official OpenTelemetry PHP SDK. The differences are
> [here](/documentation/components/libs/telemetry/opentelemetry-sdk.md).

### Basic Setup with Memory Providers (Testing)

Expand Down Expand Up @@ -1003,14 +1006,29 @@ $resource = static_detector([
#### Caching Detection Results

Resource detection can read files, for example `/etc/machine-id` for the host ID. Use `caching_detector()` to cache
the results and not detect again:
the results and not detect again. The cache file never expires, so wrap only the detectors whose values cannot change
on the host:

```php
<?php

use function Flow\Telemetry\DSL\{caching_detector, resource_detector};
use function Flow\Telemetry\DSL\{
caching_detector,
chain_detector,
composer_detector,
environment_detector,
host_detector,
os_detector,
process_detector,
resource_detector,
};

$resource = caching_detector(resource_detector())->detect();
$resource = resource_detector([
caching_detector(chain_detector(os_detector(), host_detector())),
process_detector(),
composer_detector(),
environment_detector(),
])->detect();
```

By default, the cache is in `sys_get_temp_dir()/flow_telemetry_resource.cache`. You can give a custom path as the
Expand Down
92 changes: 92 additions & 0 deletions documentation/components/libs/telemetry/opentelemetry-sdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
seo_title: "Flow Telemetry and the OpenTelemetry PHP SDK: the differences"
seo_description: >
Flow Telemetry is an independent OpenTelemetry implementation for PHP with no C extension. How it differs from the
official OpenTelemetry PHP SDK, and what is the same.
---

# Flow Telemetry and the OpenTelemetry PHP SDK

Flow Telemetry is an independent implementation of OpenTelemetry for PHP. It is not a wrapper around the official
SDK, and it does not use any of its packages. Both send the same OTLP data, so the same collectors and backends
accept it.

[DOC_LINK:/documentation/components/libs/telemetry.md]

[TOC]

## No singletons, no implicit behavior

- There is no global instance. You create a `Telemetry` object and pass it to the code that needs it.
- Composer loads the library and nothing runs. No span, no export and no configuration starts by itself.
- Nothing is read from the environment to build the pipeline. What the code says is what runs.
- Nothing is instrumented until you wrap it. A bridge takes your HTTP client, logger or kernel and returns one of
the same type that records telemetry.

```php ignore
<?php

use function Flow\Bridge\Psr18\Telemetry\DSL\psr18_traceable_client;

$client = psr18_traceable_client($client, $telemetry);
```

## What is different

| Point | OpenTelemetry PHP SDK | Flow Telemetry |
|----------------------|------------------------------------------------------------------------------|--------------------------------------------------------------------|
| Instrumentation | Hooks from the `opentelemetry` C extension | Bridges that wrap a client, a handler or a kernel |
| Extension | The PDO, Symfony and Guzzle instrumentation packages require it | None |
| Entry point | A static `Globals` registry with lazy initializers | A `Telemetry` object that you create and pass to your code |
| Current context | Static storage in the `Context` class | A `ContextStorage` object that you give to the providers |
| Code at autoload | Composer loads six files on each request, and one calls the SDK autoloader | Composer loads one file, and it only defines functions |
| Configuration | Can build itself from `OTEL_*` environment variables | Built in PHP code |
| Composer packages | `open-telemetry/sdk` requires 13 packages, with a PSR-18 client and PSR-17 factories | `psr/clock` and `symfony/polyfill-mbstring` |
| HTTP export | A PSR-18 client found with `php-http/discovery` | A curl transport in the OTLP bridge |
| Protobuf | The OTLP exporter always installs `google/protobuf` | Optional. OTLP over HTTP with JSON needs no package |
| PHP version | 8.2 or newer | 8.3 or newer |

The SDK column describes `open-telemetry/sdk` 1.18.0 and the `open-telemetry/opentelemetry-php-contrib`
instrumentation packages, as read in their source on 2026-12-01.

## What is the same

- The protocol: OTLP for traces, metrics and logs, over HTTP or gRPC.
- The specification: samplers, processors, limits, resources and W3C propagation follow it.
- A new span does not become the current span.
- A batching processor keeps 512 spans by default and sends them inside the request.

## How to start

The setup is one expression. It needs no extension, no environment variable and no network. This example
prints each span to the console:

```php
<?php

use Flow\Telemetry\Provider\Clock\SystemClock;

use function Flow\Telemetry\DSL\{
console_exporter,
memory_context_storage,
pass_through_span_processor,
resource,
telemetry,
tracer_provider,
};

$telemetry = telemetry(
resource(['service.name' => 'my-app']),
tracer_provider(
pass_through_span_processor(console_exporter()),
new SystemClock(),
memory_context_storage(),
),
);

$tracer = $telemetry->tracer('http-handler');
$span = $tracer->span('handle-request');
$tracer->complete($span);
```

To send the data to a collector, read the [OTLP Bridge](/documentation/components/bridges/telemetry-otlp-bridge.md).
10 changes: 8 additions & 2 deletions documentation/contributing/nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ To configure blackfire, create a file `./.nix/php/lib/blackfire.ini` with your b

## Secrets

`gh`, `composer` and `blackfire` in the nix shell run through [fnox](https://fnox.jdx.dev).
`gh`, `composer`, `blackfire` and `terraform` in the nix shell run through [fnox](https://fnox.jdx.dev).

fnox reads the secrets below from the provider that you choose. It gives them to the tool only. Nothing is exported
to the shell.
Expand All @@ -101,11 +101,17 @@ to the shell.
| `GH_TOKEN` | `gh`, `composer` | `GH_TOKEN`, `COMPOSER_AUTH` |
| `BLACKFIRE_CLIENT_ID` | `blackfire` | `BLACKFIRE_CLIENT_ID` |
| `BLACKFIRE_CLIENT_TOKEN` | `blackfire` | `BLACKFIRE_CLIENT_TOKEN` |
| `CLOUDFLARE_API_TOKEN` | `terraform` | `CLOUDFLARE_API_TOKEN` |
| `TF_VAR_account_id` | `terraform` | `TF_VAR_account_id` |
| `TF_VAR_zone_id` | `terraform` | `TF_VAR_zone_id` |
| `AWS_ACCESS_KEY_ID` | `terraform` | `AWS_ACCESS_KEY_ID` |
| `AWS_SECRET_ACCESS_KEY` | `terraform` | `AWS_SECRET_ACCESS_KEY` |
| `AWS_ENDPOINT_URL_S3` | `terraform` | `AWS_ENDPOINT_URL_S3` |

`fnox.toml` names the secrets. Your provider goes into `fnox.local.toml`, which git ignores. Without that file, the
tools run without secrets.

To use them, add a `[providers]` section and the three secrets to `fnox.local.toml`. The
To use them, add a `[providers]` section and the secrets that you need to `fnox.local.toml`. The
[fnox providers](https://fnox.jdx.dev/providers/overview) page shows the configuration of each provider.

An example for 1Password, where each value is `item/field` in the vault:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ composer require flow-php/symfony-telemetry-bundle:~--FLOW_PHP_VERSION--
- [flow-php/psr18-telemetry-bridge](/documentation/installation/packages/psr18-telemetry-bridge.md): for PSR-18 HTTP client tracing
- [flow-php/telemetry-otlp-bridge](/documentation/installation/packages/telemetry-otlp-bridge.md): for OTLP exporter support
- [symfony/messenger](https://packagist.org/packages/symfony/messenger): for Messenger tracing middleware
- [symfony/security-core](https://packagist.org/packages/symfony/security-core): for the authenticated user on the request span
- [symfony/security-http](https://packagist.org/packages/symfony/security-http): for logins that happen in the middle of a request
- [symfony/web-profiler-bundle](https://packagist.org/packages/symfony/web-profiler-bundle): for the Flow Telemetry panel of the web profiler in dev
- [twig/twig](https://packagist.org/packages/twig/twig): for Twig template tracing

## Optional Dependencies
Expand Down
Loading