https://github.com/opentelemetry-php/contrib-auto-psr3
[READONLY] OpenTelemetry psr-3 auto-instrumentation
https://github.com/opentelemetry-php/contrib-auto-psr3
Last synced: 7 months ago
JSON representation
[READONLY] OpenTelemetry psr-3 auto-instrumentation
- Host: GitHub
- URL: https://github.com/opentelemetry-php/contrib-auto-psr3
- Owner: opentelemetry-php
- Created: 2023-06-08T23:41:47.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T02:16:47.000Z (8 months ago)
- Last Synced: 2024-10-24T18:51:03.181Z (8 months ago)
- Language: PHP
- Size: 45.9 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://github.com/opentelemetry-php/contrib-auto-psr3/releases)
[](https://github.com/open-telemetry/opentelemetry-php/issues)
[](https://github.com/open-telemetry/opentelemetry-php-contrib/tree/main/src/Instrumentation/Psr3)
[](https://github.com/opentelemetry-php/contrib-auto-psr3)
[](https://packagist.org/packages/open-telemetry/opentelemetry-auto-psr3/)
[](https://packagist.org/packages/open-telemetry/opentelemetry-auto-psr3/)This is a read-only subtree split of https://github.com/open-telemetry/opentelemetry-php-contrib.
# OpenTelemetry PSR-3 auto-instrumentation
Please read https://opentelemetry.io/docs/instrumentation/php/automatic/ for instructions on how to
install and configure the extension and SDK.## Overview
Auto-instrumentation hooks are registered via composer, and depending on the mode, will:* automatically inject trace id and span id into log message context of any psr3 logger; or
* transform the message into the OpenTelemetry LogRecord format, for export to an OpenTelemetry logging-compatible backend## Mode
The package can operate in two modes, controlled by the environment variable `OTEL_PHP_PSR3_MODE`:
### `inject`
Inject `traceId` and `spanId` of the active trace span into the context of each logged message. Depending on the PSR-3 implementation,
the values may be written to the log output, or may be available for interpolation into the log message.For example:
```php
putenv('OTEL_PHP_PSR3_MODE=inject');
require 'vendor/autoload.php';$logger = /* create logger */
$logger->info('traceId={traceId} spanId={spanId}');
```### `export`
The logged output will be processed and emitted by the logger as normal, but the output will also be encoded using
the [OpenTelemetry log model](https://opentelemetry.io/docs/specs/otel/logs/data-model/) and can be
exported to an OpenTelemetry-compatible backend.```php
putenv('OTEL_PHP_PSR3_MODE=export');
putenv('OTEL_PHP_AUTOLOAD_ENABLED=true');
putenv('OTEL_LOGS_EXPORTER=console');
require 'vendor/autoload.php';$logger = /* create logger */
$logger->info('Hello, OTEL');
```## Configuration
The extension can be disabled via [runtime configuration](https://opentelemetry.io/docs/instrumentation/php/sdk/#configuration):
```shell
OTEL_PHP_DISABLED_INSTRUMENTATIONS=psr3
```