phattarachai/watchtower-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phattarachai/watchtower-laravel

Composer 安装命令:

composer require phattarachai/watchtower-laravel

包简介

Laravel client for the Watchtower self-hosted Sentry-compatible exception tracker. Wires up sentry/sentry-laravel and a same-origin browser tunnel that dodges ad blockers.

README 文档

README

Laravel client for Watchtower, a self-hosted Sentry-compatible exception tracker. Installs and configures sentry/sentry-laravel, wires Integration::handles($exceptions) into bootstrap/app.php, and exposes a same-origin browser tunnel (/api/watchtower-relay) that proxies envelopes to your Watchtower instance — dodging ad-blockers that strip ?sentry_key= query strings.

Install

composer require phattarachai/watchtower-laravel
php artisan watchtower:install --dsn=http://your-public-key@your-watchtower-host/42

The install command:

  1. Validates and writes WATCHTOWER_DSN and SENTRY_LARAVEL_DSN to .env.
  2. Patches bootstrap/app.php to call Sentry\Laravel\Integration::handles($exceptions) inside withExceptions(...).
  3. Publishes config/watchtower.php.
  4. If vite.config.{js,ts} is present, writes VITE_SENTRY_DSN, VITE_SENTRY_TUNNEL, and VITE_SENTRY_ENVIRONMENT and prints a Vite entry snippet.
  5. If the claude (Claude Code) CLI is on PATH, registers the Watchtower MCP server so Claude can query and triage issues directly. Pass --no-mcp to skip.

Re-running is idempotent. Pass --dry-run to preview changes.

Configuration

Env key Default Purpose
WATCHTOWER_DSN falls back to SENTRY_LARAVEL_DSN Watchtower DSN: http://{key}@{host}/{numeric-project-id}.
WATCHTOWER_RELAY_ENABLED true Register the relay route on boot.
WATCHTOWER_RELAY_PATH /api/watchtower-relay Relay endpoint path (must live under /api/).
WATCHTOWER_RELAY_TIMEOUT 5 Upstream request timeout (seconds).
WATCHTOWER_RELAY_ASYNC false Forward envelopes through a queued job instead of sync.
WATCHTOWER_RELAY_QUEUE (default queue) Queue name when async is enabled.
WATCHTOWER_VERIFY_SSL true Verify upstream TLS certificate.
WATCHTOWER_CONNECT_TIMEOUT 3 Guzzle connect timeout (seconds).

Browser side

The browser SDK posts envelopes to your own app at /api/watchtower-relay. The relay parses your configured DSN, forwards the request body verbatim to {scheme}://{host_with_port}/api/watchtower-relay on the Watchtower instance, and passes back the upstream status and rate-limit headers.

watchtower:install publishes a small helper to resources/js/vendor/watchtower.js that wraps Sentry.init(...) with the Watchtower-tuned defaults (same-origin tunnel, no PII, browser-extension denyUrls) and applies <meta name="watchtower-user-*"> to Sentry.setUser(...). Per Vite entry:

import { initWatchtower } from './vendor/watchtower.js';

initWatchtower();

The Sentry config lives inside the published helper, so multiple entries don't duplicate it. Customize options (e.g. ignoreErrors) there once.

In your root Blade layout's <head> add the package directive that emits the user-context meta tags:

@watchtowerUser

@watchtowerUser is registered automatically by the service provider and compiles to three <meta name="watchtower-user-{id,email,name}"> tags. Customize by publishing the view: php artisan vendor:publish --tag=watchtower-views.

For Filament admin panels (which bypass the root Blade layout), register a render hook:

$panel->renderHook(
    PanelsRenderHook::HEAD_END,
    fn (): string => Blade::render('@watchtowerUser'),
);

Because the request hits your own origin under /api/, ad-blockers don't recognize it as Sentry traffic.

Async forwarding

Set WATCHTOWER_RELAY_ASYNC=true to dispatch each forward through a ForwardEnvelope job. The relay returns 202 {"queued": true} immediately and the worker performs the upstream POST. Failures are logged but not retried beyond Guzzle's default behavior — the Sentry SDK retransmits anyway.

Verify

php artisan watchtower:test

Prints the resolved config, runs sentry:test, and POSTs a synthetic envelope through the relay path.

Troubleshooting

The bundled skill at vendor/phattarachai/watchtower-laravel/resources/boost/skills/watchtower-error-tracking/reference.md covers every install + verify + triage path, including the MCP server. To install it into Claude's skill set: php artisan boost:install --skills.

License

MIT.

phattarachai/watchtower-laravel 适用场景与选型建议

phattarachai/watchtower-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 325 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「sentry」 「watchtower」 「error-tracking」 「observability」 「exception-tracking」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 phattarachai/watchtower-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 phattarachai/watchtower-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 phattarachai/watchtower-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 325
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 32
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-17