johnshopkins/sentry-tracing

该软件包最新版本(1.3.1)没有可用的许可信息。

1.3.1 2023-02-02 18:26 UTC

This package is auto-updated.

Last update: 2024-08-30 01:32:33 UTC


README

这是一个用于实现自定义性能监控的包装库。

安装

composer require johnshopkins/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的那个。