andreybrigunet/sentry-tracing

1.4.3 2023-04-25 16:37 UTC

This package is auto-updated.

Last update: 2024-09-25 19:47:11 UTC


README

一个用于实现 自定义性能监控 的包装库,针对 Sentry 性能监控

安装

composer require andreybrigunet/sentry-tracing

基本用法

<?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();

使用 SENTRY_TRACE 常量

为了轻松启用或禁用跟踪,在创建任何事务或跨度之前定义 SENTRY_TRACE。如果常量未定义,则默认为 true。使用此常量的优点是,如果您在任何时候想关闭跟踪,您可以通过切换常量而不是从代码库中删除所有事务和跨度的引用来实现。

// enable tracing
const SENTRY_TRACE = true;

连接服务

对于从后端开始跟踪,使用 元标签 连接前端 pageload 事务。

<html>
  <head>
    <meta name="sentry-trace" content="<?= $span->getTraceId() ?>" />
    <meta name="baggage" content="<?= $span->getBaggage() ?>" />
    <!-- ... -->
  </head>
</html>

引用的跨度应该是生成 HTML 的那个。