Skip to content

docs(dart): Add New Spans page and stream mode migration guide#18554

Draft
buenaflor wants to merge 8 commits into
masterfrom
buenaflor/docs/dart-span-streaming-new-spans
Draft

docs(dart): Add New Spans page and stream mode migration guide#18554
buenaflor wants to merge 8 commits into
masterfrom
buenaflor/docs/dart-span-streaming-new-spans

Conversation

@buenaflor

@buenaflor buenaflor commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

DESCRIBE YOUR PR

Introduces the Dart/Flutter stream mode (span streaming) documentation — the base of a 4-PR stack. Mirrors the Python New Spans docs.

  • New New Spans page: enabling stream mode (traceLifecycle: SentryTraceLifecycle.stream), manual instrumentation (startSpan/startSpanSync/startInactiveSpan), typed SentryAttribute attributes (including array factories), span status, beforeSendSpan/ignoreSpans, sampling, and verification
  • New Migrate to Stream Mode guide mapping the transaction API to the new span API
  • Minimum SDK version documented as 9.23.0

This is the bottom of the stack — merge this first. Stacked children: #18609, #18610, #18611.

IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs to go live.

  • Urgent deadline (GA date, etc.):
  • Other deadline:
  • None: Not urgent, can wait up to 1 week+

SLA

  • Teamwork makes the dream work, so please add a reviewer to your PRs.
  • Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it.
    Thanks in advance for your help!

PRE-MERGE CHECKLIST

Make sure you've checked the following before merging your changes:

  • Checked Vercel preview for correctness, including links
  • PR was reviewed and approved by any necessary SMEs (subject matter experts)
  • PR was reviewed and approved by a member of the Sentry docs team

Document stream mode (SentryTraceLifecycle.stream) for the Dart and
Flutter SDKs, where spans are sent as they finish instead of being
batched into a transaction. Mirrors the Python New Spans pages.

- New Spans page: enabling stream mode, manual instrumentation with
  startSpan/startSpanSync/startInactiveSpan, typed attributes, status,
  beforeSendSpan/ignoreSpans, sampling, and verification
- Migration guide: mapping transaction-based APIs to the new span APIs
- Platform-includes split init snippets for Flutter vs plain Dart

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sentry-docs Ready Ready Preview, Comment Jul 8, 2026 1:24pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
develop-docs Ignored Ignored Preview Jul 8, 2026 1:24pm

Request Review

Fix two factual errors in the New Spans pages verified against the SDK
source: a custom tracesSampler receives a different sampling context in
stream mode (read name and attributes from spanContext, not the
transaction context), and beforeSendSpan runs when each span ends and
sees all attributes rather than only creation-time ones. Also add the
service span type to the span taxonomy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
buenaflor and others added 3 commits July 6, 2026 14:10
Add the array SentryAttribute factories (stringArray/intArray/boolArray/
doubleArray) to the attributes table and clarify that startSpanSync is
the synchronous variant of startSpan (T vs Future<T> callback).

Co-Authored-By: Claude <noreply@anthropic.com>
The enum has four values (ok, error, cancelled, deadlineExceeded), not
just ok/error. Fix the New Spans and migration guide wording.

Co-Authored-By: Claude <noreply@anthropic.com>
Per SDK maintainer: only ok and error are valid stream-mode span
statuses.

Co-Authored-By: Claude <noreply@anthropic.com>
@buenaflor buenaflor changed the title docs(dart): Draft New Spans and Migration Guide pages docs(dart): Add New Spans page and stream mode migration guide Jul 6, 2026
Mirror the Python migration guide: scope setTag isn't applied to
streamed spans; use Sentry.setAttributes to set span-applying attributes.

Co-Authored-By: Claude <noreply@anthropic.com>
- In `stream` mode, the transaction APIs (`Sentry.startTransaction`, `ISentrySpan.startChild`) do nothing and log a warning.
- In `static` mode, the new span APIs (`Sentry.startSpan`) do nothing.
- Auto-instrumentations switch to the correct API automatically based on this setting.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd like to add the Expandable "How does span flushing work?" we have in the other guides here too. Or is there a specific reason why it's not included on this page?

This is the content I'd add (copied from Python):

<Expandable title="How does span flushing work?">

When stream mode is enabled, the SDK maintains an internal buffer that groups spans by trace ID.

Spans are flushed:

- On a regular interval (every 5 seconds by default).
- When a trace's buffer reaches 1,000 spans.
- When the SDK shuts down.

Each flush sends only the spans accumulated since the last flush, grouped into envelopes by trace ID.

</Expandable>

@buenaflor buenaflor Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I'd also add:

When the internal buffer size exceeds 1 MiB or something like that. This is specific to mobile because we have tighter memory constraints


By default, a span inherits the currently active span as its parent. To change this, pass `parentSpan`:

- `parentSpan: null` forces a root span with no parent.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

does this force a root span or a service span?
iirc, in python, it's a service span

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Service span should be more accurate here 👍

By default, a span inherits the currently active span as its parent. To change this, pass `parentSpan`:

- `parentSpan: null` forces a root span with no parent.
- `parentSpan: someSpan` parents the new span under a specific `SentrySpanV2`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we mention SentrySpanV2 twice in this document -> will this be documented somewhere we can link to (I haven't looked at the other prs yet)? If not, I propose to just write "span"

@buenaflor buenaflor Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not explictly no, it's the class name for the Span you use in Dart code. I'm also fine with just calling it span


Only **root spans** are sampled; child spans inherit the root span's decision. When a root span isn't sampled, its callback still executes with a no-op span, so all span operations remain safe to call.

## Flutter Auto-Instrumentation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to only show this on the Flutter page and not the Dart page?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah that's my bad. yes definitely

- } finally {
- await transaction.finish();
- }
+ await Sentry.startSpan('checkout', (span) async {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should add more examples here like we did for Python:

  • start a span
  • Start what used to be a transaction (parent none)
  • Start a child span while a parent is active
  • Start a child span with a parent that's currently not active

let me know if you have any thoughts on this

@buenaflor buenaflor Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, here are some examples - feel free to adapt these as you see fit

1. Start a span

If there is no active parent, this becomes a service span. If there is an active span, it becomes a child automatically.

await Sentry.startSpan('load-user', (span) async {
  span.setAttribute('user.id', SentryAttribute.string(userId));

  await loadUser(userId);
});

2. Start what used to be a transaction

Explicitly pass parentSpan: null to force a service span.

await Sentry.startSpan(
  'checkout-flow',
  (span) async {
    await runCheckout();
  },
  parentSpan: null,
);

3. Start a child span while a parent is active

Nested startSpan calls parent automatically through zones.

await Sentry.startSpan('checkout-flow', (checkoutSpan) async {
  await Sentry.startSpan('charge-card', (chargeSpan) async {
    await paymentService.charge();
  });

  await Sentry.startSpan('create-order', (orderSpan) async {
    await orderService.create();
  });
});

4. Start a child span with a parent that is not active

Keep the parent span reference and pass it explicitly.

final parent = Sentry.startInactiveSpan(
  'background-sync',
  parentSpan: null,
);

try {
  await someOtherAsyncBoundary();

  await Sentry.startSpan(
    'fetch-page',
    (child) async {
      await api.fetchPage();
    },
    parentSpan: parent,
  );
} finally {
  parent.end();
}


#### Spans That Outlive a Callback

Use `Sentry.startInactiveSpan` when the work can't be wrapped in a single callback — widget lifecycles, stream subscriptions, or platform channel round-trips. You must call `end()` manually, and other spans do **not** automatically become its children:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

.... and other spans do **not** automatically become its children:

How do you create child spans in that case?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you have to set the parent explicitly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, then the 'inactive span' needs to be set as parent specifically

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