Gate server SDK overhead in CI and reduce per-request cost under span streaming

Đang mở
#25,678 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
backend, performance, testing

Hướng nghiên cứu

Start with server-utils/server-subscription.ts, core/src/tracing/trace.ts, core/src/tracing/spans/captureSpan.ts, and core/src/tracing/spans/spanBuffer.ts; the proposal identifies these paths and the relevant sampling and buffering behavior. First inspect the existing dev-packages CI suites and the tests around these tracing paths. Done means stable counter based regression coverage and measured changes to sampling, span capture, and buffering that preserve propagation and sent data; this spans several subsystems and needs project familiarity.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Node.js Task

Server SDK overhead has no regression gate. The timing-based node-overhead-gh-action was removed as too flaky (#20246). Kiln (#23302) compares versions on demand, but nothing runs on PRs. Regressions such as #24820 (CPU up from 10.56 to 10.74+) are found by users and are hard to bisect afterwards.

Now that span streaming is the default, a few per-request and per-span paths cost noticeably more than they need to. Local measurements on Node 24.21, using an in-process fetch against an http server so client and server instrumentation both run:

Setup Time per request Scope clones per request spanStart per request
No SDK 0.056 ms 0 0
init() without tracesSampleRate 0.088 ms 4 0
tracesSampleRate: 0 0.130 ms 6 2
tracesSampleRate: 1 0.183 ms 6 2
Proposal
  1. A CI gate based on counts, not wall-clock time. Add a dev-packages suite that records stable counters for a few scenarios (raw http, express, a span-heavy loop):

    • scope clones per request
    • spanStart per request
    • bytes retained per buffered trace after gc()
    • modules loaded by require('@sentry/node')
    • heap after N requests, to catch leaks

    It should fail when a counter grows past a small threshold. Timings stay informational only. The point is to avoid the flakiness that got the old action removed.

  2. A cheaper sampled-out path. A request that is sampled out still costs about 70% as much as a sampled one.

    • The http server subscription builds the full attribute set (headers, URL parsing, filtering) before any sampling decision (server-utils server-subscription.ts).
    • An unsampled root still becomes a full SentrySpan (core/src/tracing/trace.ts, sampleSpan → new SentrySpan) and emits spanStart.

    When no tracesSampler or beforeSampling hook is registered, the decision depends only on tracesSampleRate, the parent decision and sampleRand, so it can be made first. On "drop", skip building attributes and return a non-recording span. That span must still record the dropped-span outcome and keep propagation working. With a sampler registered, behavior stays as it is.

  3. Less work per span in captureSpan. Under streaming this runs on every span end. It calls getCombinedScopeData (copying the breadcrumb and event-processor arrays and deep-merging request data) and spanToJSON(segmentSpan) for every child (core/src/tracing/spans/captureSpan.ts). However, applyCommonSpanAttributes only reads user, attributes, contexts and the segment's name and id. A narrow merge plus direct reads would give the same output.

  4. A bounded span buffer. SpanBuffer.add (core/src/tracing/spans/spanBuffer.ts) creates one bucket and one setTimeout per trace. It caps size per trace but has no global cap. Each buffered span keeps its segment span alive, along with that span's scopes and request data. Locally, about 7 KB was retained per trace, and 20k buffered traces held about 141 MB until they were flushed. Proposed: global limits on buffered traces and bytes (flush the oldest bucket when reached), one shared unref'd interval instead of per-trace timers, and optionally dropping scopes and request data from the segment span once it ends.

None of these change public API or the data that is sent. Related: #15861.

Ngôn ngữ chính
TypeScript
Star
8.8k
Fork
1.9k
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
744

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của getsentry/sentry-javascript

Tất cả issue của getsentry/sentry-javascript

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.