Skip to content

fix(link): Set span attributes on creation - #4044

Open
awishere wants to merge 3 commits into
getsentry:mainfrom
awishere:awishere/fix/span-start-attributes
Open

awishere wants to merge 3 commits into
getsentry:mainfrom
awishere:awishere/fix/span-start-attributes

Conversation

@awishere

@awishere awishere commented Sep 23, 2026 •

Copy link
Copy Markdown

📜 Description

Provide sentry.op, sentry.origin, and integration data that is already known when streaming instrumentation spans are created. This makes the attributes available to root sampling decisions and span-start lifecycle callbacks, while preserving the existing final attributes and static tracing behavior.

The internal instrumentation span factory now accepts an optional origin, data, and synchronous marker and supplies them to startInactiveSpan. GraphQL root spans do the same directly. HTTP, Dio, gRPC, Drift, Hive, Isar, Sqflite, Supabase, and file instrumentation now pass their known attributes at creation.

💡 Motivation and Context

Streaming spans previously received their operation and origin immediately after creation. As a result, tracesSampler and OnSpanStartV2 callbacks could not inspect values that the integration already knew.

Fixes #3990

💚 How did you test it?

  • Added regressions proving GraphQL root sampling and child span-start callbacks receive sentry.op and sentry.origin, plus factory coverage for arbitrary known data and the synchronous marker.
  • Complete suites passed for all affected packages: Dart 1,713 (4 skipped), Dio 86, gRPC 36, Drift 34, Hive 94, Isar 108, Sqflite 113, Supabase 94, File 29, and Link 9.
  • dart analyze --fatal-warnings passed for all ten affected packages.
  • Repository formatter and git diff --check passed.

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec
  • No breaking changes

🔮 Next steps

None.

Provide known operation and origin attributes when streaming spans are created so sampling and span-start callbacks can inspect them.

Co-Authored-By: OpenAI Codex <noreply@openai.com>

@buenaflor buenaflor 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.

Thanks for the contribution

This fixes the reported call sites, but known attributes are still set after creation in:

  • Core HTTP client: method and sanitized URL.
  • Dio adapter/transformer: origin and method; adapter URL.
  • gRPC: origin, RPC system/service/method, request metadata.
  • Drift, Hive, Isar: origin and database metadata.
  • Sqflite executor/database/batch/open/factory paths: origin and applicable database metadata.
  • Supabase: origin and database/request metadata.
  • File sync/async wrappers: origin, async flag, and file path.

Could we migrate these too - and double check that we didnt miss any other spots?

Pass origin and known integration data through the instrumentation span factory so streaming lifecycle callbacks observe them at creation.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
@awishere

Copy link
Copy Markdown
Author

Addressed in 6e40963c. The instrumentation span factory now accepts known data and a synchronous marker and supplies those attributes when a streaming span is created.

I migrated the core HTTP client, Dio adapter/transformer, gRPC, Drift, Hive, Isar, Sqflite executor/database/batch/open/factory paths, Supabase, and file sync/async wrappers. I also scanned every InstrumentationSpanFactory.createSpan call site; the remaining Link serializer/parser sites have no additional known attributes, while response values and statuses still remain post-creation because they are only known after the operation.

I added a factory regression that verifies operation, origin, arbitrary data, and the sync marker are visible in OnSpanStartV2. All affected package analyzers are clean, and their complete suites pass: Dart 1,713 (4 skipped), Dio 86, gRPC 36, Drift 34, Hive 94, Isar 108, Sqflite 113, Supabase 94, File 29, and Link 9.

@codecov

codecov Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.42424% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.30%. Comparing base (91c111c) to head (6e40963).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...acing/instrumentation/synchronous_span_marker.dart 0.00% 7 Missing ⚠️
.../tracing/instrumentation/span_attribute_utils.dart 95.00% 1 Missing ⚠️
.../lib/src/tracing/instrumentation/span_factory.dart 91.66% 1 Missing ⚠️
packages/link/lib/src/sentry_tracing_link.dart 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4044      +/-   ##
==========================================
+ Coverage   88.17%   88.30%   +0.13%     
==========================================
  Files         347      348       +1     
  Lines       12951    12950       -1     
==========================================
+ Hits        11420    11436      +16     
+ Misses       1531     1514      -17     
Flag Coverage Δ
sentry 88.14% <81.63%> (+0.28%) ⬆️
sentry_dio 97.73% <100.00%> (ø)
sentry_drift 93.69% <100.00%> (+0.11%) ⬆️
sentry_file 65.08% <100.00%> (-0.21%) ⬇️
sentry_firebase_remote_config 100.00% <ø> (ø)
sentry_flutter 92.48% <ø> (+<0.01%) ⬆️
sentry_grpc 99.08% <100.00%> (-0.02%) ⬇️
sentry_hive 77.56% <100.00%> (+0.08%) ⬆️
sentry_isar 74.37% <ø> (ø)
sentry_link 21.80% <80.00%> (+0.30%) ⬆️
sentry_logging 97.01% <ø> (ø)
sentry_sqflite 88.46% <100.00%> (-0.36%) ⬇️
sentry_supabase 97.24% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Exercise the legacy synchronous marker, double attribute conversion, and the static GraphQL root origin. Restore the private synchronous marker constant so existing marker behavior is not counted as newly changed code.\n\nCo-Authored-By: OpenAI Codex <noreply@openai.com>

@buenaflor buenaflor 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.

Looks good to me. Could you rebase onto main to resolve the conflicts please

This branch has not been deployed

No deployments
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.

Set known span attributes at start time for streaming/v2

2 participants