Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uptrace/uptrace-php
OpenTelemetry PHP distribution for Uptrace
https://github.com/uptrace/uptrace-php
distributed-tracing opentelemetry php tracing uptrace
Last synced: 9 days ago
JSON representation
OpenTelemetry PHP distribution for Uptrace
- Host: GitHub
- URL: https://github.com/uptrace/uptrace-php
- Owner: uptrace
- License: apache-2.0
- Created: 2022-10-14T10:04:44.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-14T10:44:25.000Z (5 months ago)
- Last Synced: 2024-08-22T11:47:22.176Z (5 months ago)
- Topics: distributed-tracing, opentelemetry, php, tracing, uptrace
- Language: PHP
- Homepage: https://uptrace.dev/get/opentelemetry-php.html
- Size: 170 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Uptrace for PHP
[![Documentation](https://img.shields.io/badge/uptrace-documentation-informational)](https://uptrace.dev/get/opentelemetry-php.html)
[![Chat](https://img.shields.io/badge/-telegram-red?color=white&logo=telegram&logoColor=black)](https://t.me/uptrace)## Introduction
uptrace-php is a thing wrapper over OpenTelemery PHP that configures Otel SDK to export
[traces](https://uptrace.dev/opentelemetry/distributed-tracing.html) and
[metrics](https://uptrace.dev/opentelemetry/metrics.html) to Uptrace.## Quickstart
First, install Composer using the
[installation instructions](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos)
and add the following line to your project's `composer.json` file, as this library has not reached a
stable release status yet:```json
"minimum-stability": "dev"
```Then, you can install uptrace-php:
```bash
composer require uptrace/uptrace
```Run the [basic example](example/basic) below using the DSN from the Uptrace project settings page.
```php
setDsn('https://@uptrace.dev/')
->setServiceName('myservice')
->setServiceVersion('1.0.0')
->buildAndRegisterGlobal();// Create a tracer. Usually, tracer is a global variable.
$tracer = \OpenTelemetry\API\Globals::tracerProvider()->getTracer('app_or_package_name');// Create a root span (a trace) to measure some operation.
$main = $tracer->spanBuilder('main-operation')->startSpan();
// Future spans will be parented to the currently active span.
$mainScope = $main->activate();$child1 = $tracer->spanBuilder('GET /posts/:id')
->setSpanKind(SpanKind::KIND_SERVER)
->startSpan();
$child1Scope = $child1->activate();
$child1->setAttribute('http.method"', 'GET');
$child1->setAttribute('http.route"', '/posts/:id');
$child1->setAttribute('http.url', 'http://localhost:8080/posts/123');
$child1->setAttribute('http.status_code', 200);
try {
throw new \Exception('Some error message');
} catch (\Exception $exc) {
$child1->setStatus('error', $exc->getMessage());
$child1->recordException($exc);
}
$child1Scope->detach();
$child1->end();$child2 = $tracer->spanBuilder('child2-of-main')->startSpan();
$child2Scope = $child1->activate();
$child2->setAttributes([
'db.system' => 'mysql',
'db.statement' => 'SELECT * FROM posts LIMIT 100',
]);
$child2Scope->detach();
$child2->end();// End the span and detached context when the operation we are measuring is done.
$mainScope->detach();
$main->end();echo $uptrace->traceUrl($main) . PHP_EOL;
```## Links
- [Examples](example)
- [Get started with OpenTelemetry PHP](https://uptrace.dev/get/opentelemetry-php.html)