Skip to content

fix(perps): cp-7.57.0 missing trace attachment in sentry measurements#20817

Merged
abretonc7s merged 26 commits into
mainfrom
perps/sentry-dashboard
Oct 9, 2025
Merged

fix(perps): cp-7.57.0 missing trace attachment in sentry measurements#20817
abretonc7s merged 26 commits into
mainfrom
perps/sentry-dashboard

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

Description

What is the reason for the change?

Previous implementation sent Sentry measurements using setMeasurement() without attaching them to parent spans, causing Sentry to drop measurements or attach them to incorrect spans.

What is the improvement/solution?

Fixes measurement attachment by passing the parent traceSpan parameter to all setMeasurement() calls.

Changelog

CHANGELOG entry: fix missing span attachment to sentry measurements for perps

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TAT-1824

Manual testing steps

Feature: Sentry Measurement Attachment

  Scenario: Verify measurements attach to correct spans
    Given user places an order
    When Sentry trace is created
    Then measurements should attach to correct parent span

Screenshots/Recordings

Before

  • setMeasurement() called without span parameter
  • Measurements dropped or attached to wrong spans

After

  • setMeasurement(name, duration, 'millisecond', traceSpan) - span attached
  • Measurements reliably appear under correct traces
image

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Replaces ad-hoc measurements with span-based tracing across Perps UI and backend, attaching all Sentry measurements to proper parent spans and adding granular traces/metrics, analytics, tests, and docs.

  • Telemetry/Tracing:
    • Replace measurementName usage with span-based API (traceName, TraceName, TraceOperation) in UI hooks/views (Markets, Asset Details, Order, Close, Tab, Withdraw, Transactions).
    • Overhaul usePerpsMeasurement to start/end Sentry spans and mark completion via endTrace, supporting conditions/reset; deprecates direct setMeasurement timing there.
    • Add detailed Perps trace names/ops (place/edit/cancel/close/update TPSL/withdraw, fetches, WS first data, connection/reconnection, data lake report) and attach setMeasurement(..., span) where applicable.
  • Controller/Services:
    • PerpsController: wrap operations with unique trace IDs; attach measurements (rewards, data lake, get/open orders, positions, account state, markets, funding) to parent spans; improve error logging and fire-and-forget data lake tracing with retries.
    • PerpsConnectionManager: trace connection establishment and reconnection sub-stages; measure and log preload timings; add health-check sources and retry.
    • PerpsStreamManager/HyperLiquidSubscriptionService: trace WS connects and first-data latencies for positions/orders/account; remove stray console errors, unify logging.
  • Analytics:
    • Add/extend event properties and screen events (e.g., connection error and retry) and reuse consolidated events in error view.
  • Tests/Docs:
    • Update tests to new trace ops and expectations; add concise Sentry/MetaMetrics reference docs.

Written by Cursor Bugbot for commit e7e41c0. This will update automatically on new commits. Configure here.

@github-actions

github-actions Bot commented Oct 6, 2025

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-perps Perps team label Oct 6, 2025
@abretonc7s abretonc7s changed the title Perps/sentry dashboard fix(perps): cp-7.57.0 missing trace attachment in sentry measurements Oct 6, 2025
@abretonc7s abretonc7s marked this pull request as ready for review October 7, 2025 02:47
@abretonc7s abretonc7s requested a review from a team as a code owner October 7, 2025 02:47
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

abretonc7s and others added 2 commits October 7, 2025 18:50
- Remove unnecessary startTime/timestamp parameters from trace/endTrace calls
  (Let trace system auto-calculate using getPerformanceTimestamp)
- Add missing traceSpan parameters to setMeasurement calls
- Add complete trace context to getOpenOrders method

Fixes in PerpsController.ts:
- closePosition: Remove startTime from trace(), add traceSpan to setMeasurement, remove timestamp from endTrace
- reportOrderToDataLake: Remove startTime and timestamp parameters
- getOpenOrders: Add full trace context matching other data-fetch methods

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
cursor[bot]

This comment was marked as outdated.

@abretonc7s abretonc7s added the skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. label Oct 7, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

nickewansmith
nickewansmith previously approved these changes Oct 9, 2025
@nickewansmith

Copy link
Copy Markdown
Contributor

Approving to unblock, code looks generally good here

@abretonc7s abretonc7s enabled auto-merge October 9, 2025 01:47
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

gambinish
gambinish previously approved these changes Oct 9, 2025

@gambinish gambinish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Stamping to unblock the cp. Lmk if you need another approval after CI is green

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Order Execution Tracking Fails Without `lastResult`

Removing the lastResult state variable broke the usePerpsMeasurement hook in usePerpsOrderExecution.ts. Its endConditions still depend on !!lastResult, causing performance tracking for order execution to never complete.

app/components/UI/Perps/hooks/usePerpsClosePosition.ts#L18-L19

const [isClosing, setIsClosing] = useState(false);
const [error, setError] = useState<Error | null>(null);

Fix in Cursor Fix in Web


@abretonc7s abretonc7s disabled auto-merge October 9, 2025 02:49
@abretonc7s abretonc7s enabled auto-merge October 9, 2025 02:49
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2025

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
56.7% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@abretonc7s abretonc7s added this pull request to the merge queue Oct 9, 2025
Merged via the queue into main with commit 20ecfb5 Oct 9, 2025
182 of 189 checks passed
@abretonc7s abretonc7s deleted the perps/sentry-dashboard branch October 9, 2025 04:01
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 9, 2025
@metamaskbot metamaskbot added the release-7.58.0 Issue or pull request that will be included in release 7.58.0 label Oct 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.58.0 Issue or pull request that will be included in release 7.58.0 Sev1-high An issue that may have caused fund loss or access to wallet in the past & may still be ongoing size-XL skip-sonar-cloud Only used for bypassing sonar cloud when failures are not relevant to the changes. team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants