Skip to content

feat(ray): Support span streaming#6518

Open
alexander-alderman-webb wants to merge 6 commits into
masterfrom
webb/ray/span-first
Open

feat(ray): Support span streaming#6518
alexander-alderman-webb wants to merge 6 commits into
masterfrom
webb/ray/span-first

Conversation

@alexander-alderman-webb
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Jun 8, 2026

Description

No attributes are changed as the integration does not set undocumented or deprecated attributes.

Use RayLoggingTransport transport in tests to capture streamed spans, as spans are not emitted synchronously like transactions.

Adapting Tests

sed commands used for converting transaction context managers:

  • sed -i '' 's/with sentry_sdk.start_transaction(op="task", name="ray test transaction"):/with sentry_sdk.traces.start_span(name="ray test parent", attributes={"sentry.op": "task"}):/g'
  • sed -i '' 's/with sentry_sdk.start_span(op="task", name="example actor execution"):/with sentry_sdk.traces.start_span(name="example actor execution", attributes={"sentry.op": "task"}):/g'

sed commands used for converting event capture:

  • sed -i '' 's/setup_sentry()/setup_sentry_with_span_streaming() if span_streaming else setup_sentry()/g'
  • sed -i '' 's/"worker_process_setup_hook": setup_sentry,/"worker_process_setup_hook": setup_sentry_with_span_streaming if span_streaming else setup_sentry,/g'
  • sed -i '' 's/"worker_process_setup_hook": setup_sentry_with_logging_transport,/"worker_process_setup_hook": setup_sentry_with_logging_transport_and_span_streaming if span_streaming else setup_sentry_with_logging_transport,/g'
  • sed -i '' 's/client_transaction = client_envelope.get_transaction_event()/client_spans = [span for item in client_envelope.items for span in item.payload.json["items"]]/g'
  • sed -i '' 's/client_transaction/client_spans[1]/g'
  • sed -i '' 's/worker_transaction/worker_spans[1]/g'

sed commands used for converting source:

  • sed -i '' 's/["transaction_info"]/["attributes"]["sentry.span.source"]/g'

sed commands used for converting op:

  • sed -i '' 's/["op"]/["attributes"]["sentry.op"]/g'

sed commands used for converting origin:

  • sed -i '' 's/["origin"]/["attributes"]["sentry.origin"]/g'

sed commands used for converting description:

  • sed -i '' 's/description/name/g'

other test changes:

  • sed -i '' 's/example_task.remote()/example_task.remote(span_streaming)/g'
  • sed -i '' 's/["contexts"]["trace"]["trace_id"]/["trace_id"]/g'
  • sed -i '' 's/["contexts"]["trace"]["span_id"]/["span_id"]/g'

Issues

Closes #6051

Reminders

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 8, 2026

Codecov Results 📊

88762 passed | ⏭️ 6025 skipped | Total: 94787 | Pass Rate: 93.64% | Execution Time: 307m 54s

All tests are passing successfully.

❌ Patch coverage is 33.33%. Project has 2490 uncovered lines.

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/ray.py 33.33% ⚠️ 32 Missing

Generated by Codecov Action

Comment thread tests/integrations/ray/test_ray.py Outdated
Comment thread tests/integrations/ray/test_ray.py Outdated
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review June 8, 2026 07:46
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner June 8, 2026 07:46
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a53ce3e. Configure here.

Comment thread sentry_sdk/integrations/ray.py
Copy link
Copy Markdown
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

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

LGTM, see couple comments

):
try:
result = user_f(*f_args, **f_kwargs)
except Exception:
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.

Should we set the span status to error here or is that already happening somewhere in the helper methods?

Copy link
Copy Markdown
Contributor Author

@alexander-alderman-webb alexander-alderman-webb Jun 8, 2026

Choose a reason for hiding this comment

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

The span status is set to error in StreamedSpan.__exit__() since we use the with ...: construct.

The integration has had this manual status management since the start (#2444), so I am assumed this isn't behavior we wish to keep (but please let me know if I'm missing something).

The only functional difference is when the exception is in the list used by should_be_treated_as_error().

result = old_remote_method(
*args, **kwargs, _sentry_tracing=tracing
)
except Exception:
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.

Same q re: setting span status to error


def setup_sentry(span_streaming=False, transport=None):
if span_streaming:
sentry_sdk._span_batcher.SpanBatcher.MAX_BEFORE_FLUSH = 1
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.

Is this needed/can we flush explicitly instead?

Copy link
Copy Markdown
Contributor Author

@alexander-alderman-webb alexander-alderman-webb Jun 8, 2026

Choose a reason for hiding this comment

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

I added this for the Ray worker. I couldn't find a hook to run code on teardown of the Ray task, and we finish the Ray segment span in the worker after the target function has returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate ray to span first

2 participants