sentry-php-sdk

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
All Skills > SDK Setup > PHP SDK
所有技能 > SDK 配置 > PHP SDK

Sentry PHP SDK

Sentry PHP SDK

Opinionated wizard that scans your PHP project and guides you through complete Sentry setup.
这是一套开箱即用的配置向导,可以扫描你的PHP项目,引导你完成Sentry的全流程配置。

Invoke This Skill When

适用场景

  • User asks to "add Sentry to PHP" or "setup Sentry" in a PHP app
  • User wants error monitoring, tracing, profiling, logging, metrics, or crons in PHP
  • User mentions
    sentry/sentry
    ,
    sentry/sentry-laravel
    ,
    sentry/sentry-symfony
    , or Sentry + any PHP framework
  • User wants to monitor Laravel routes, Symfony controllers, queues, scheduled tasks, or plain PHP scripts
Note: SDK versions and APIs below reflect Sentry docs at time of writing (sentry/sentry 4.x, sentry/sentry-laravel 4.x, sentry/sentry-symfony 5.x). Always verify against docs.sentry.io/platforms/php/ before implementing.

  • 用户要求给PHP应用「添加Sentry」或「配置Sentry」
  • 用户需要在PHP中实现错误监控、链路追踪、性能剖析、日志记录、指标统计或定时任务监控
  • 用户提到
    sentry/sentry
    sentry/sentry-laravel
    sentry/sentry-symfony
    ,或者Sentry搭配任意PHP框架的需求
  • 用户需要监控Laravel路由、Symfony控制器、队列、定时任务或原生PHP脚本
注意: 下文提到的SDK版本和API对应编写时的Sentry官方文档(sentry/sentry 4.x、sentry/sentry-laravel 4.x、sentry/sentry-symfony 5.x)。 实施前请务必参考 docs.sentry.io/platforms/php/ 确认最新规范。

Phase 1: Detect

阶段1:项目检测

Run these commands to understand the project before making recommendations:
bash
undefined
在给出配置建议前,先运行以下命令了解项目情况:
bash
undefined

Check existing Sentry

检查是否已安装Sentry

grep -i sentry composer.json composer.lock 2>/dev/null
grep -i sentry composer.json composer.lock 2>/dev/null

Detect framework

检测使用的框架

cat composer.json | grep -E '"laravel/framework"|"symfony/framework-bundle"|"illuminate/'
cat composer.json | grep -E '"laravel/framework"|"symfony/framework-bundle"|"illuminate/'

Confirm framework via filesystem markers

通过文件系统标记确认框架

ls artisan 2>/dev/null && echo "Laravel detected" ls bin/console 2>/dev/null && echo "Symfony detected"
ls artisan 2>/dev/null && echo "检测到Laravel" ls bin/console 2>/dev/null && echo "检测到Symfony"

Detect queue systems

检测队列系统

grep -E '"laravel/horizon"|"symfony/messenger"' composer.json 2>/dev/null
grep -E '"laravel/horizon"|"symfony/messenger"' composer.json 2>/dev/null

Detect AI libraries

检测AI相关库

grep -E '"openai-php|"openai/|anthropic|llm' composer.json 2>/dev/null
grep -E '"openai-php|"openai/|anthropic|llm' composer.json 2>/dev/null

Check for companion frontend

检查是否有配套前端项目

ls frontend/ resources/js/ assets/ 2>/dev/null cat package.json 2>/dev/null | grep -E '"react"|"svelte"|"vue"|"next"'

**What to note:**
- Is `sentry/sentry` (or `-laravel` / `-symfony`) already in `composer.json`? If yes, check if the init call exists — may just need feature config.
- Framework detected? **Laravel** (has `artisan` + `laravel/framework` in composer.json), **Symfony** (has `bin/console` + `symfony/framework-bundle`), or **plain PHP**.
- Queue system? (Laravel Queue / Horizon, Symfony Messenger need queue worker configuration.)
- AI libraries? (No PHP AI auto-instrumentation yet — document manually if needed.)
- Companion frontend? (Triggers Phase 4 cross-link.)

---
ls frontend/ resources/js/ assets/ 2>/dev/null cat package.json 2>/dev/null | grep -E '"react"|"svelte"|"vue"|"next"'

**需要记录的信息:**
- `composer.json` 中是否已经存在 `sentry/sentry`(或对应 `-laravel` / `-symfony` 包)?如果已存在,检查是否有初始化调用,可能只需要补充功能配置即可。
- 检测到的框架类型:**Laravel**(composer.json存在`laravel/framework`且有`artisan`文件)、**Symfony**(composer.json存在`symfony/framework-bundle`且有`bin/console`文件),或是**原生PHP**。
- 是否使用队列系统?(Laravel Queue/Horizon、Symfony Messenger需要额外配置队列工作进程)
- 是否使用AI相关库?(目前PHP还没有AI自动埋点能力,如有需要请手动记录)
- 是否有配套前端项目?(触发阶段4的关联配置推荐)

---

Phase 2: Recommend

阶段2:方案推荐

Based on what you found, present a concrete proposal. Don't ask open-ended questions — lead with a recommendation:
Always recommended (core coverage):
  • Error Monitoring — captures unhandled exceptions and PHP errors
  • Logging — Monolog integration (Laravel/Symfony auto-configure; plain PHP uses
    MonologHandler
    )
Recommend when detected:
  • Tracing — web framework detected (Laravel/Symfony auto-instrument HTTP, DB, Twig/Blade, cache)
  • Profiling — production apps where performance matters (requires
    excimer
    PHP extension, Linux/macOS only)
  • Crons — scheduler patterns detected (Laravel Scheduler, Symfony Scheduler, custom cron jobs)
  • Metrics — business KPIs or SLO tracking (beta; uses
    TraceMetrics
    API)
Recommendation matrix:
FeatureRecommend when...Reference
Error MonitoringAlways — non-negotiable baseline
${SKILL_ROOT}/references/error-monitoring.md
TracingLaravel/Symfony detected, or manual spans needed
${SKILL_ROOT}/references/tracing.md
ProfilingProduction +
excimer
extension available
${SKILL_ROOT}/references/profiling.md
LoggingAlways; Monolog for Laravel/Symfony
${SKILL_ROOT}/references/logging.md
MetricsBusiness events or SLO tracking needed (beta)
${SKILL_ROOT}/references/metrics.md
CronsScheduler or cron patterns detected
${SKILL_ROOT}/references/crons.md
Propose: "I recommend Error Monitoring + Tracing [+ Logging]. Want Profiling, Crons, or Metrics too?"

根据你检测到的项目信息,给出具体的配置建议。不要提出开放性问题,先直接给出推荐方案:
默认推荐(基础能力覆盖):
  • 错误监控 — 捕获未处理异常和PHP原生错误
  • 日志记录 — 集成Monolog(Laravel/Symfony会自动配置,原生PHP使用
    MonologHandler
按需推荐的能力:
  • 链路追踪 — 检测到使用Web框架时推荐(Laravel/Symfony可自动对HTTP、数据库、Twig/Blade模板、缓存做埋点)
  • 性能剖析 — 对性能要求高的生产环境使用(需要安装
    excimer
    PHP扩展,仅支持Linux/macOS)
  • 定时任务监控 — 检测到调度器模式时推荐(Laravel Scheduler、Symfony Scheduler、自定义cron任务)
  • 指标统计 — 需要统计业务KPI或SLO时使用(beta阶段,使用
    TraceMetrics
    API)
推荐矩阵:
功能推荐使用场景参考文档
错误监控默认必选 — 基础监控能力
${SKILL_ROOT}/references/error-monitoring.md
链路追踪检测到Laravel/Symfony,或需要手动埋点时
${SKILL_ROOT}/references/tracing.md
性能剖析生产环境且可用
excimer
扩展时
${SKILL_ROOT}/references/profiling.md
日志记录默认必选;Laravel/Symfony使用Monolog
${SKILL_ROOT}/references/logging.md
指标统计需要统计业务事件或SLO时(beta)
${SKILL_ROOT}/references/metrics.md
定时任务监控检测到调度器或cron任务时
${SKILL_ROOT}/references/crons.md
可以这样提议:「我推荐配置错误监控+链路追踪[+日志记录]。是否还需要性能剖析、定时任务监控或指标统计能力?」

Phase 3: Guide

阶段3:配置引导

Install

安装依赖

bash
undefined
bash
undefined

Plain PHP

原生PHP

composer require sentry/sentry "^4.0"
composer require sentry/sentry "^4.0"

Laravel

Laravel

composer require sentry/sentry-laravel "^4.0"
composer require sentry/sentry-laravel "^4.0"

Symfony

Symfony

composer require sentry/sentry-symfony "^5.0"

**System requirements:**
- PHP 7.2 or later
- Extensions: `ext-json`, `ext-mbstring`, `ext-curl` (all required)
- `excimer` PECL extension (Linux/macOS only — required for profiling)
composer require sentry/sentry-symfony "^5.0"

**系统要求:**
- PHP 7.2 及以上版本
- 必须安装扩展:`ext-json`、`ext-mbstring`、`ext-curl`
- `excimer` PECL扩展(仅Linux/macOS可用,性能剖析功能必填)

Framework-Specific Initialization

框架专属初始化配置

Plain PHP

原生PHP

Place
\Sentry\init()
at the top of your entry point (
index.php
,
bootstrap.php
, or equivalent), before any application code:
php
<?php

require_once 'vendor/autoload.php';

\Sentry\init([
    'dsn'                  => $_SERVER['SENTRY_DSN'] ?? '',
    'environment'          => $_SERVER['SENTRY_ENVIRONMENT'] ?? 'production',
    'release'              => $_SERVER['SENTRY_RELEASE'] ?? null,
    'send_default_pii'     => true,
    'traces_sample_rate'   => 1.0,
    'profiles_sample_rate' => 1.0,
    'enable_logs'          => true,
]);

// rest of application...
在入口文件(
index.php
bootstrap.php
或其他等价文件)的最顶部,所有业务代码运行前添加
\Sentry\init()
初始化代码:
php
<?php

require_once 'vendor/autoload.php';

\Sentry\init([
    'dsn'                  => $_SERVER['SENTRY_DSN'] ?? '',
    'environment'          => $_SERVER['SENTRY_ENVIRONMENT'] ?? 'production',
    'release'              => $_SERVER['SENTRY_RELEASE'] ?? null,
    'send_default_pii'     => true,
    'traces_sample_rate'   => 1.0,
    'profiles_sample_rate' => 1.0,
    'enable_logs'          => true,
]);

// 后续业务代码...

Laravel

Laravel

Step 1 — Register exception handler in
bootstrap/app.php
:
php
use Sentry\Laravel\Integration;

return Application::configure(basePath: dirname(__DIR__))
    ->withExceptions(function (Exceptions $exceptions) {
        Integration::handles($exceptions);
    })->create();
Step 2 — Publish config and set DSN:
bash
php artisan sentry:publish --dsn=YOUR_DSN
This creates
config/sentry.php
and adds
SENTRY_LARAVEL_DSN
to
.env
.
Step 3 — Configure
.env
:
ini
SENTRY_LARAVEL_DSN=https://examplePublicKey@o0.ingest.sentry.io/0
SENTRY_TRACES_SAMPLE_RATE=1.0
SENTRY_PROFILES_SAMPLE_RATE=1.0
For full Laravel configuration options, read
${SKILL_ROOT}/references/laravel.md
.
步骤1 — 在
bootstrap/app.php
中注册异常处理器:
php
use Sentry\Laravel\Integration;

return Application::configure(basePath: dirname(__DIR__))
    ->withExceptions(function (Exceptions $exceptions) {
        Integration::handles($exceptions);
    })->create();
步骤2 — 发布配置文件并设置DSN:
bash
php artisan sentry:publish --dsn=YOUR_DSN
该命令会创建
config/sentry.php
配置文件,并将
SENTRY_LARAVEL_DSN
添加到
.env
文件中。
步骤3 — 配置
.env
文件:
ini
SENTRY_LARAVEL_DSN=https://examplePublicKey@o0.ingest.sentry.io/0
SENTRY_TRACES_SAMPLE_RATE=1.0
SENTRY_PROFILES_SAMPLE_RATE=1.0
完整的Laravel配置选项请参考
${SKILL_ROOT}/references/laravel.md

Symfony

Symfony

Step 1 — Register the bundle in
config/bundles.php
(auto-done by Symfony Flex):
php
Sentry\SentryBundle\SentryBundle::class => ['all' => true],
Step 2 — Create
config/packages/sentry.yaml
:
yaml
sentry:
    dsn: '%env(SENTRY_DSN)%'
    options:
        environment: '%env(APP_ENV)%'
        release: '%env(SENTRY_RELEASE)%'
        send_default_pii: true
        traces_sample_rate: 1.0
        profiles_sample_rate: 1.0
        enable_logs: true
Step 3 — Set the DSN in
.env
:
ini
SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0
For full Symfony configuration options, read
${SKILL_ROOT}/references/symfony.md
.
步骤1 — 在
config/bundles.php
中注册bundle(Symfony Flex会自动完成该步骤):
php
Sentry\SentryBundle\SentryBundle::class => ['all' => true],
步骤2 — 创建
config/packages/sentry.yaml
配置文件:
yaml
sentry:
    dsn: '%env(SENTRY_DSN)%'
    options:
        environment: '%env(APP_ENV)%'
        release: '%env(SENTRY_RELEASE)%'
        send_default_pii: true
        traces_sample_rate: 1.0
        profiles_sample_rate: 1.0
        enable_logs: true
步骤3 — 在
.env
文件中设置DSN:
ini
SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0
完整的Symfony配置选项请参考
${SKILL_ROOT}/references/symfony.md

Quick Start — Recommended Init (Plain PHP)

快速入门 — 原生PHP推荐初始化配置

Full init enabling the most features with sensible defaults:
php
\Sentry\init([
    'dsn'                     => $_SERVER['SENTRY_DSN'] ?? '',
    'environment'             => $_SERVER['SENTRY_ENVIRONMENT'] ?? 'production',
    'release'                 => $_SERVER['SENTRY_RELEASE'] ?? null,
    'send_default_pii'        => true,

    // Tracing (lower to 0.1–0.2 in high-traffic production)
    'traces_sample_rate'      => 1.0,

    // Profiling — requires excimer extension (Linux/macOS only)
    'profiles_sample_rate'    => 1.0,

    // Structured logs (sentry/sentry >=4.12.0)
    'enable_logs'             => true,
]);
以下是开启大部分常用功能的合理默认配置:
php
\Sentry\init([
    'dsn'                     => $_SERVER['SENTRY_DSN'] ?? '',
    'environment'             => $_SERVER['SENTRY_ENVIRONMENT'] ?? 'production',
    'release'                 => $_SERVER['SENTRY_RELEASE'] ?? null,
    'send_default_pii'        => true,

    // 链路追踪采样率(高流量生产环境建议调低到0.1–0.2)
    'traces_sample_rate'      => 1.0,

    // 性能剖析 — 需要安装excimer扩展(仅支持Linux/macOS)
    'profiles_sample_rate'    => 1.0,

    // 结构化日志(需要sentry/sentry >=4.12.0)
    'enable_logs'             => true,
]);

For Each Agreed Feature

已确认启用的功能配置

Walk through features one at a time. Load the reference, follow its steps, verify before moving on:
FeatureReference fileLoad when...
Error Monitoring
${SKILL_ROOT}/references/error-monitoring.md
Always (baseline)
Tracing
${SKILL_ROOT}/references/tracing.md
HTTP handlers / distributed tracing
Profiling
${SKILL_ROOT}/references/profiling.md
Performance-sensitive production
Logging
${SKILL_ROOT}/references/logging.md
Always; Monolog for Laravel/Symfony
Metrics
${SKILL_ROOT}/references/metrics.md
Business KPIs / SLO tracking (beta)
Crons
${SKILL_ROOT}/references/crons.md
Scheduler / cron patterns detected
For each feature:
Read ${SKILL_ROOT}/references/<feature>.md
, follow steps exactly, verify it works.

逐个配置你需要的功能,加载对应参考文档,按步骤操作,验证通过后再进行下一个功能的配置:
功能参考文档启用场景
错误监控
${SKILL_ROOT}/references/error-monitoring.md
默认必选(基础能力)
链路追踪
${SKILL_ROOT}/references/tracing.md
HTTP服务/分布式链路追踪需求
性能剖析
${SKILL_ROOT}/references/profiling.md
对性能敏感的生产环境
日志记录
${SKILL_ROOT}/references/logging.md
默认必选;Laravel/Symfony使用Monolog
指标统计
${SKILL_ROOT}/references/metrics.md
业务KPI/SLO统计需求(beta)
定时任务监控
${SKILL_ROOT}/references/crons.md
检测到调度器或cron任务时
对每个功能:
读取 ${SKILL_ROOT}/references/<功能名>.md
,严格按步骤操作,验证功能正常后再继续。

Configuration Reference

配置参考

Key
\Sentry\init()
Options (Plain PHP)

\Sentry\init()
核心配置项(原生PHP)

OptionTypeDefaultPurpose
dsn
string|bool|null
$_SERVER['SENTRY_DSN']
SDK disabled if empty or
false
environment
string|null
$_SERVER['SENTRY_ENVIRONMENT']
e.g.,
"staging"
release
string|null
$_SERVER['SENTRY_RELEASE']
e.g.,
"myapp@1.0.0"
send_default_pii
bool
false
Include request headers, cookies, IP
sample_rate
float
1.0
Error event sample rate (0.0–1.0)
traces_sample_rate
float|null
null
Transaction sample rate;
null
disables tracing
traces_sampler
callable|null
null
Custom per-transaction sampling (overrides rate)
profiles_sample_rate
float|null
null
Profiling rate relative to traces; requires
excimer
enable_logs
bool
false
Send structured logs to Sentry (>=4.12.0)
max_breadcrumbs
int
100
Max breadcrumbs per event
attach_stacktrace
bool
false
Stack traces on
captureMessage()
in_app_include
string[]
[]
Path prefixes belonging to your app
in_app_exclude
string[]
[]
Path prefixes for third-party code (hidden in traces)
ignore_exceptions
string[]
[]
Exception FQCNs to never report
ignore_transactions
string[]
[]
Transaction names to never report
error_types
int|null
error_reporting()
PHP error bitmask (e.g.,
E_ALL & ~E_NOTICE
)
capture_silenced_errors
bool
false
Capture errors suppressed by
@
operator
max_request_body_size
string
"medium"
"none"
/
"small"
/
"medium"
/
"always"
before_send
callable
identity
fn(Event $event, ?EventHint $hint): ?Event
— return
null
to drop
before_breadcrumb
callable
identity
fn(Breadcrumb $b): ?Breadcrumb
— return
null
to discard
trace_propagation_targets
string[]|null
null
Downstream hosts to inject
sentry-trace
headers into;
null
= all,
[]
= none
debug
bool
false
Verbose SDK output (use a PSR-3
logger
option instead for structured output)
配置项类型默认值作用
dsn
string|bool|null
$_SERVER['SENTRY_DSN']
为空或
false
时SDK禁用
environment
string|null
$_SERVER['SENTRY_ENVIRONMENT']
环境标识,例如
"staging"
release
string|null
$_SERVER['SENTRY_RELEASE']
版本标识,例如
"myapp@1.0.0"
send_default_pii
bool
false
是否包含请求头、Cookie、IP等用户标识信息
sample_rate
float
1.0
错误事件采样率(范围0.0–1.0)
traces_sample_rate
float|null
null
链路追踪采样率;为
null
时禁用链路追踪
traces_sampler
callable|null
null
自定义链路采样逻辑(覆盖固定采样率)
profiles_sample_rate
float|null
null
性能剖析采样率(基于链路追踪采样结果);需要
excimer
扩展
enable_logs
bool
false
发送结构化日志到Sentry(需要>=4.12.0版本)
max_breadcrumbs
int
100
每个事件最多保留的面包屑数量
attach_stacktrace
bool
false
调用
captureMessage()
时是否附带堆栈信息
in_app_include
string[]
[]
属于业务代码的路径前缀
in_app_exclude
string[]
[]
第三方代码的路径前缀(链路追踪中会隐藏)
ignore_exceptions
string[]
[]
不需要上报的异常类全限定名
ignore_transactions
string[]
[]
不需要上报的事务名称
error_types
int|null
error_reporting()
PHP错误掩码,例如
E_ALL & ~E_NOTICE
capture_silenced_errors
bool
false
是否上报被
@
运算符抑制的错误
max_request_body_size
string
"medium"
请求体采集大小:
"none"
/
"small"
/
"medium"
/
"always"
before_send
callable
identity
fn(Event $event, ?EventHint $hint): ?Event
— 返回
null
则丢弃该事件
before_breadcrumb
callable
identity
fn(Breadcrumb $b): ?Breadcrumb
— 返回
null
则丢弃该面包屑
trace_propagation_targets
string[]|null
null
需要注入
sentry-trace
头的下游服务域名;
null
=全部域名,
[]
=不注入
debug
bool
false
开启SDK详细日志输出(建议使用PSR-3
logger
配置项输出结构化日志)

Environment Variables

环境变量

VariableMaps toNotes
SENTRY_DSN
dsn
Also
$_SERVER['SENTRY_DSN']
SENTRY_ENVIRONMENT
environment
SENTRY_RELEASE
release
Also reads
$_SERVER['AWS_LAMBDA_FUNCTION_VERSION']
SENTRY_SPOTLIGHT
spotlight
Laravel note: Uses
SENTRY_LARAVEL_DSN
(falls back to
SENTRY_DSN
). Other options follow
SENTRY_TRACES_SAMPLE_RATE
,
SENTRY_PROFILES_SAMPLE_RATE
, etc.

环境变量对应配置项说明
SENTRY_DSN
dsn
也会从
$_SERVER['SENTRY_DSN']
读取
SENTRY_ENVIRONMENT
environment
SENTRY_RELEASE
release
也会读取
$_SERVER['AWS_LAMBDA_FUNCTION_VERSION']
SENTRY_SPOTLIGHT
spotlight
Laravel注意事项: 使用
SENTRY_LARAVEL_DSN
(会 fallback 到
SENTRY_DSN
),其他配置项对应
SENTRY_TRACES_SAMPLE_RATE
SENTRY_PROFILES_SAMPLE_RATE
等格式。

Verification

配置验证

Test that Sentry is receiving events:
php
// Trigger a real error event — check the Sentry dashboard within seconds
throw new \Exception('Sentry PHP SDK test');
Or for a non-crashing check:
php
\Sentry\captureMessage('Sentry PHP SDK test');
Laravel:
bash
php artisan sentry:test
If nothing appears:
  1. Enable debug output:
    php
    \Sentry\init([
        'dsn' => '...',
        'logger' => new \Sentry\Logger\DebugStdOutLogger(),
    ]);
  2. Verify the DSN is correct (format:
    https://<key>@o<org>.ingest.sentry.io/<project>
    )
  3. Check
    SENTRY_DSN
    (or
    SENTRY_LARAVEL_DSN
    ) env var is set in the running process
  4. For queue workers: ensure Sentry is initialized inside the worker process, not just the web process

测试Sentry是否能正常接收事件:
php
// 触发一个真实错误事件 — 几秒内即可在Sentry控制台看到上报结果
throw new \Exception('Sentry PHP SDK 测试');
如果不想让程序崩溃,可以使用以下方式测试:
php
\Sentry\captureMessage('Sentry PHP SDK 测试');
Laravel专属测试命令:
bash
php artisan sentry:test
如果控制台没有收到事件:
  1. 开启调试输出:
    php
    \Sentry\init([
        'dsn' => '...',
        'logger' => new \Sentry\Logger\DebugStdOutLogger(),
    ]);
  2. 验证DSN格式正确(格式:
    https://<key>@o<org>.ingest.sentry.io/<project>
  3. 检查运行进程中是否正确设置了
    SENTRY_DSN
    (或
    SENTRY_LARAVEL_DSN
    )环境变量
  4. 队列工作进程场景:确保Sentry在队列工作进程内部初始化,而不是仅在Web进程中初始化

Phase 4: Cross-Link

阶段4:关联配置推荐

After completing PHP setup, check for a companion frontend missing Sentry:
bash
ls frontend/ resources/js/ assets/ public/ 2>/dev/null
cat package.json frontend/package.json 2>/dev/null \
  | grep -E '"react"|"svelte"|"vue"|"next"|"nuxt"'
If a frontend exists without Sentry, suggest the matching skill:
Frontend detectedSuggest skill
React / Next.js
sentry-react-sdk
Svelte / SvelteKit
sentry-svelte-sdk
Vue / NuxtUse
@sentry/vue
— see docs.sentry.io/platforms/javascript/guides/vue/
Other JS/TS
sentry-react-sdk
(covers generic browser JS patterns)

完成PHP侧配置后,检查是否有未配置Sentry的配套前端项目:
bash
ls frontend/ resources/js/ assets/ public/ 2>/dev/null
cat package.json frontend/package.json 2>/dev/null \
  | grep -E '"react"|"svelte"|"vue"|"next"|"nuxt"'
如果存在未配置Sentry的前端项目,推荐使用对应配置技能:
检测到的前端框架推荐技能
React / Next.js
sentry-react-sdk
Svelte / SvelteKit
sentry-svelte-sdk
Vue / Nuxt使用
@sentry/vue
— 参考 docs.sentry.io/platforms/javascript/guides/vue/
其他JS/TS项目
sentry-react-sdk
(覆盖通用浏览器JS配置逻辑)

Troubleshooting

问题排查

IssueSolution
Events not appearingEnable
logger
option (
DebugStdOutLogger
), verify DSN, check env vars in the running process
Malformed DSN errorFormat:
https://<key>@o<org>.ingest.sentry.io/<project>
Laravel exceptions not capturedEnsure
Integration::handles($exceptions)
is in
bootstrap/app.php
Symfony exceptions not capturedVerify
SentryBundle
is registered in
config/bundles.php
No traces appearingSet
traces_sample_rate
(not
null
); confirm auto-instrumentation is enabled
Profiling not working
excimer
extension required (Linux/macOS only; not available on Windows); requires
traces_sample_rate > 0
enable_logs
not working
Requires
sentry/sentry >= 4.12.0
,
sentry/sentry-laravel >= 4.15.0
, or
sentry/sentry-symfony >= 5.4.0
Queue worker errors missingInit Sentry in the worker process itself, not just the web process; for Laravel use
SENTRY_LARAVEL_DSN
in worker
.env
Too many transactionsLower
traces_sample_rate
or use
traces_sampler
to drop health check routes
PII not capturedSet
send_default_pii: true
; for Laravel set
send_default_pii: true
in
config/sentry.php
@
-suppressed errors missing
Set
capture_silenced_errors: true
Cross-service traces brokenCheck
trace_propagation_targets
; ensure downstream services have Sentry installed
问题解决方案
控制台收不到事件开启
logger
配置项(使用
DebugStdOutLogger
)、验证DSN正确性、检查运行进程的环境变量
DSN格式错误正确格式为:
https://<key>@o<org>.ingest.sentry.io/<project>
Laravel异常没有被捕获确认
bootstrap/app.php
中已添加
Integration::handles($exceptions)
配置
Symfony异常没有被捕获确认
config/bundles.php
中已注册
SentryBundle
没有链路追踪数据确保
traces_sample_rate
不为
null
;确认自动埋点已开启
性能剖析不生效需要安装
excimer
扩展(仅支持Linux/macOS,Windows不可用);需要
traces_sample_rate > 0
enable_logs
配置不生效
需要
sentry/sentry >= 4.12.0
sentry/sentry-laravel >= 4.15.0
sentry/sentry-symfony >= 5.4.0
队列工作进程错误没有上报在队列工作进程自身的配置中初始化Sentry,不要仅在Web进程中配置;Laravel场景下确保工作进程的
.env
中配置了
SENTRY_LARAVEL_DSN
事务上报数量过多调低
traces_sample_rate
,或使用
traces_sampler
过滤健康检查等不需要上报的路由
用户标识信息没有被采集配置
send_default_pii: true
;Laravel场景下在
config/sentry.php
中配置
send_default_pii: true
@
抑制的错误没有上报
配置
capture_silenced_errors: true
跨服务链路不通检查
trace_propagation_targets
配置;确认下游服务也已安装Sentry