johnshopkins / sentry-tracing
Installs: 2 656
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=8.1
- sentry/sdk: ^3.3
README
A wrapper library for implementing custom instrumentation of Sentry performance monitoring.
Installation
composer require johnshopkins/sentry-tracing
Basic usage
<?php require __DIR__ . '/vendor/autoload.php'; // create and start a transaction $transaction = new SentryTracing\Transaction('transaction name', 'operation.name'); // record a span $span = new SentryTracing\Span('operation.name'); // do some stuff... $span->end(); // record another span $span = new SentryTracing\Span('operation.name'); // do some more stuff... $span->end(); // end the transaction and send to sentry $transaction->end();
Using the SENTRY_TRACE
constant
To easily enable or disable tracing, define the SENTRY_TRACE
before creating any transactions or spans. If the constant is not defined, it will default to true
. The advantage of using this constant is that if at any point, you wish to turn off tracing, you can toggle the constant instead of removing all references to transactions and spans within your code base.
// enable tracing const SENTRY_TRACE = true;
Connecting services
For traces that begin in the backend, connect the front end pageload
transaction using meta tags.
<html> <head> <meta name="sentry-trace" content="<?= $span->getTraceId() ?>" /> <meta name="baggage" content="<?= $span->getBaggage() ?>" /> <!-- ... --> </head> </html>
The span referenced should be the one that generates the HTML.