Skip to content

Conversation

@huangdijia
Copy link
Contributor

@huangdijia huangdijia commented Sep 28, 2025

Summary

This PR adds view rendering tracing support to the Sentry component, allowing developers to monitor and trace Hyperf view rendering operations.

Changes Made

  • Added ViewRenderAspect: New aspect class that intercepts Hyperf\View\Render::render calls to create tracing spans
  • Updated sentry.php config: Added view option to the tracing spans configuration with environment variable SENTRY_TRACING_SPANS_VIEW
  • Added feature() helper function: Convenience function in Function.php to get the Feature instance from the container

Features

  • ✅ Configurable view tracing via environment variable
  • ✅ Automatic span creation with template name and data
  • ✅ Integration with existing Feature-based span enablement system
  • ✅ Proper span context with operation type view.render and origin auto.view

Technical Details

  • The aspect captures the template name and data passed to the view renderer
  • Spans are only created when SENTRY_TRACING_SPANS_VIEW=true (default: true)
  • Uses the existing trace() function for consistent span handling
  • Follows the same pattern as other tracing aspects in the codebase

Configuration

// In .env
SENTRY_TRACING_SPANS_VIEW=true

Test Plan

  • View rendering operations generate appropriate spans
  • Configuration option correctly enables/disables tracing
  • Template names and data are properly captured in span context
  • No performance impact when tracing is disabled

Summary by CodeRabbit

  • 新功能
    • 新增“视图”追踪跨度(tracing.spans.view,默认开启),可通过配置控制。
    • 对视图渲染自动追踪,记录模板名、渲染模式、引擎与渲染数据,便于在 Sentry 中分析性能与错误上下文。
    • 新增全局辅助函数 feature(),用于从容器访问 Feature 服务以便扩展与集成。

- Add ViewRenderAspect to trace Hyperf view rendering operations
- Add 'view' tracing span configuration option to sentry.php config
- Add feature() helper function to Function.php for easier Feature access
- Integrate with existing Feature-based span enablement system
@coderabbitai
Copy link

coderabbitai bot commented Sep 28, 2025

Walkthrough

新增 tracing.spans.view 配置项、全局 feature() 助手,并新增 ViewRenderAspect 切面以在视图渲染时根据配置与特性开关创建 Sentry span 并包裹实际渲染流程;同时在 ConfigProvider 中注册该切面。

Changes

Cohort / File(s) Summary
配置:Tracing spans 扩展
src/sentry/publish/sentry.php
tracing.spans 下新增键 view,默认值为 true
全局助手函数
src/sentry/src/Function.php
新增全局函数 feature(): Feature,通过 ApplicationContext::getContainer()->get(Feature::class) 获取 Feature 实例。
视图渲染切面与追踪
src/sentry/src/Tracing/Aspect/ViewRenderAspect.php, src/sentry/src/ConfigProvider.php
新增类 ViewRenderAspect:拦截 Hyperf\View\Render::render,当 tracing.spans.view 与 feature 开启时,创建 op=view.render、origin=auto.view 的 span(描述为模板名并附带渲染数据),在 trace 闭包内调用原渲染并返回结果;并在 ConfigProvider 中注册该切面。

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Caller as 调用方
    participant Render as Hyperf\View\Render
    participant Aspect as ViewRenderAspect
    participant Feature as Feature(配置/开关)
    participant Sentry as Sentry SDK

    Caller->>Render: render(template, data)
    Render->>Aspect: 进入切面 process()
    Aspect->>Feature: 检查 tracing.spans.view 与特性开关
    alt 开启
        Aspect->>Sentry: startSpan(op="view.render", desc=template, origin="auto.view", data)
        Aspect->>Render: proceed() 执行原渲染
        Render-->>Aspect: 返回渲染结果
        Aspect->>Sentry: finishSpan()
        Aspect-->>Caller: 返回渲染结果
    else 关闭
        Aspect->>Render: proceed() 直接执行并返回
        Render-->>Caller: 返回渲染结果
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • xuanyanwow

Poem

小兔窜入代码园,
模板一渲入眼前。
span 轻点名与源,
feature 揉抱开关眠。
追踪悄然归日志间。 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 标题直接聚焦于主要功能:为 Sentry 组件添加视图渲染跟踪支持,简洁清晰地传达了此 PR 的核心意图。
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/sentry-view-tracing

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 088e6b2 and 161d6ed.

📒 Files selected for processing (1)
  • src/sentry/src/ConfigProvider.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/*/src/**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use the namespace pattern FriendsOfHyperf{ComponentName} in all component PHP source files

Files:

  • src/sentry/src/ConfigProvider.php
src/*/src/ConfigProvider.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Each component must include a ConfigProvider class (FriendsOfHyperf{ComponentName}\ConfigProvider) with __invoke() returning dependencies, commands, listeners, and annotations scan paths

Files:

  • src/sentry/src/ConfigProvider.php
{src,tests}/**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Adhere to PSR-12 coding standards across PHP code

Files:

  • src/sentry/src/ConfigProvider.php
src/*/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

New components must follow the standard component structure under src/{component-name}/ including .gitattributes, .github, LICENSE, README.md, composer.json, and a src/ subdirectory

Files:

  • src/sentry/src/ConfigProvider.php
🧬 Code graph analysis (1)
src/sentry/src/ConfigProvider.php (1)
src/sentry/src/Tracing/Aspect/ViewRenderAspect.php (1)
  • ViewRenderAspect (26-64)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
🔇 Additional comments (1)
src/sentry/src/ConfigProvider.php (1)

44-44: 新增视图 Tracing 切面配置合理

Tracing\Aspect\ViewRenderAspect 注入 aspects 配置与新增切面实现保持一致,确保视图渲染可以按需创建 Sentry span,整体改动无误。

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.28)

At least one path must be specified to analyse.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cbca72 and 1e62fe8.

📒 Files selected for processing (3)
  • src/sentry/publish/sentry.php (1 hunks)
  • src/sentry/src/Function.php (1 hunks)
  • src/sentry/src/Tracing/Aspect/ViewRenderAspect.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
{src,tests}/**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Adhere to PSR-12 coding standards across PHP code

Files:

  • src/sentry/publish/sentry.php
  • src/sentry/src/Function.php
  • src/sentry/src/Tracing/Aspect/ViewRenderAspect.php
src/*/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

New components must follow the standard component structure under src/{component-name}/ including .gitattributes, .github, LICENSE, README.md, composer.json, and a src/ subdirectory

Files:

  • src/sentry/publish/sentry.php
  • src/sentry/src/Function.php
  • src/sentry/src/Tracing/Aspect/ViewRenderAspect.php
src/*/src/**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use the namespace pattern FriendsOfHyperf{ComponentName} in all component PHP source files

Files:

  • src/sentry/src/Function.php
  • src/sentry/src/Tracing/Aspect/ViewRenderAspect.php
🧬 Code graph analysis (2)
src/sentry/src/Function.php (1)
src/sentry/src/Feature.php (1)
  • Feature (18-71)
src/sentry/src/Tracing/Aspect/ViewRenderAspect.php (2)
src/sentry/src/Feature.php (2)
  • Feature (18-71)
  • isTracingSpanEnabled (43-50)
src/sentry/src/Function.php (1)
  • trace (48-53)
🪛 PHPMD (2.15.0)
src/sentry/src/Tracing/Aspect/ViewRenderAspect.php

43-43: Avoid unused parameters such as '$scope'. (undefined)

(UnusedFormalParameter)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.7
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.7

@huangdijia huangdijia merged commit a615adb into main Sep 28, 2025
15 of 16 checks passed
@huangdijia huangdijia deleted the feat/sentry-view-tracing branch September 28, 2025 05:10
huangdijia added a commit that referenced this pull request Sep 28, 2025
* feat(sentry): add view rendering tracing support

- Add ViewRenderAspect to trace Hyperf view rendering operations
- Add 'view' tracing span configuration option to sentry.php config
- Add feature() helper function to Function.php for easier Feature access
- Integrate with existing Feature-based span enablement system

* 修复 ViewRenderAspect 类,增加对视图模式和引擎的追踪数据收集

* feat(sentry): add ViewRenderAspect to tracing aspects

---------

Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants