Allow `ignoreSpans` to match scope attributes (e.g. `Sentry.getGlobalScope().setAttribute()`) in span streaming mode

Đang mở
#25,745 1 bình luận 1 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Start with _shouldIgnoreStreamedSpan in packages/core/src/tracing/trace.ts and how commonSpanAttributes merges scope data in packages/core/src/tracing/spans/captureSpan.ts. Check the existing ignoreSpans tests and documentation for stream mode and scope attributes. Done means the intended matching behavior and its timing are documented and covered by tests.

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

Mô tả

Spans
Problem

In v11 span streaming mode (traceLifecycle: 'stream'), there's no supported way to drop spans based on an attribute set on the scope:

  • ignoreSpans is evaluated once at span start (_shouldIgnoreStreamedSpan in packages/core/src/tracing/trace.ts) and only sees spanArguments.attributes, i.e. the attributes passed directly to startSpan.
  • Scope attributes (scope.setAttribute() / setAttributes()) are merged into the span later, at capture time (commonSpanAttributes → scopeData.attributes in packages/core/src/tracing/spans/captureSpan.ts), so ignoreSpans never sees them.
  • beforeSendSpan can't drop spans in v11 (documented in MIGRATION.md).

So an ignoreSpans rule with an attributes filter looks like it should work for scope attributes, since those attributes do end up on every sent span, but it silently never matches. For SDK-generated spans (pageload, navigation, http, etc.) users can't add the attribute at start themselves, so there's no workaround short of wrapping the transport.

Use case (from a customer)

A browser app wants to drop spans recorded after the page has been hidden at least once, since timings from backgrounded tabs are noisy:

Sentry.init({
  ignoreSpans: [{ attributes: { document_hid_once: true } }],
});

const globalScope = Sentry.getGlobalScope();
globalScope.setAttribute('document_hid_once', false);

document.addEventListener(
  'visibilitychange',
  () => {
    if (document.visibilityState === 'hidden') {
      globalScope.setAttribute('document_hid_once', true);
    }
  },
  { once: true },
);

Expected: spans started after the flag flips to true are ignored. Actual: nothing is ignored, because ignoreSpans doesn't consider scope attributes.

Proposal

When evaluating ignoreSpans at span start in stream mode, merge the current scope attributes (global → isolation → current, same precedence used at capture) under the span's own start attributes, and match against the result. Span start attributes should take precedence over scope attributes, as they do at capture.

Open questions:

  • Timing: start-time evaluation means a scope attribute changed after a span started won't affect that span. That seems fine and consistent with the documented "ignoreSpans takes effect when a span starts" behavior, but it should be called out in the docs.
  • Docs: whatever the outcome, the ignoreSpans docs should say explicitly whether scope attributes are considered. Right now it's easy to assume they are.
  • Alternative: if matching scope attributes in ignoreSpans isn't wanted, a supported way to drop a streamed span based on its final attributes would also cover this use case. Today the only option is filtering the span envelope item in a custom transport.
Environment
  • @sentry/* v11 (verified against develop at 11.9.0)
  • Span streaming mode (the v11 default)

via ADV.

--

View Junior Session [Sentry]

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.