Skip to content

[Core] Add get_session_name() to RuntimeContext#59469

Merged
edoakes merged 5 commits intomasterfrom
add-session-name
Dec 20, 2025
Merged

[Core] Add get_session_name() to RuntimeContext#59469
edoakes merged 5 commits intomasterfrom
add-session-name

Conversation

@marwan116
Copy link
Contributor

Description

Currently, there's no public API to retrieve the Ray session name. Users need to use private APIs like ray._private.worker.global_worker.node.session_name or query the dashboard REST API. This makes it difficult to filter Prometheus metrics by cluster when multiple clusters run the same application name, since Ray metrics use the SessionName label (which contains the session_name value).

Checks

  • I've run scripts/format.sh to lint the code
  • I've included any doc changes needed
  • I've added tests for my changes
  • I've updated the changelog (if needed)

@marwan116 marwan116 requested a review from a team as a code owner December 16, 2025 08:27
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new public API, get_session_name(), to the RuntimeContext. This is a valuable addition, as it provides a standardized way to access the Ray session name, which is particularly useful for monitoring and filtering Prometheus metrics across different clusters. The implementation is clean, and the accompanying tests are well-written, covering both driver and remote task contexts. My only suggestion is a minor documentation improvement to enhance clarity.

@ray-gardener ray-gardener bot added docs An issue or change related to documentation core Issues that should be addressed in Ray Core observability Issues related to the Ray Dashboard, Logging, Metrics, Tracing, and/or Profiling labels Dec 16, 2025
Signed-off-by: Marwan Sarieddine <sarieddine.marwan@gmail.com>
Signed-off-by: Marwan Sarieddine <sarieddine.marwan@gmail.com>
Signed-off-by: Marwan Sarieddine <sarieddine.marwan@gmail.com>
@marwan116 marwan116 requested a review from ZacAttack December 18, 2025 06:36
Comment on lines +156 to +158
assert (
ray.is_initialized()
), "Session name is not available because Ray has not been initialized."
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should raise an exception type rather than be an assertion

assertions are typically used for invariant checking (they should only fail if an unexpected internal system state occurred)

Suggested change
assert (
ray.is_initialized()
), "Session name is not available because Ray has not been initialized."
if not ray.is_initialized():
raise RuntimeError("Session name is not available because Ray has not been initialized.")

Copy link
Contributor Author

@marwan116 marwan116 Dec 19, 2025

Choose a reason for hiding this comment

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

Makes sense - FWIW I copied this assertion from the already implemented get_worker_id and get_node_id

Copy link
Contributor Author

@marwan116 marwan116 Dec 19, 2025

Choose a reason for hiding this comment

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

I know it is technically out of scope for this PR but I will add a commit fixing the get_worker_id, get_node_id and get_job_id methods to raise exceptions instead of relying on asserts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please review the last two commits to resolve 🙏

Signed-off-by: Marwan Sarieddine <sarieddine.marwan@gmail.com>
Signed-off-by: Marwan Sarieddine <sarieddine.marwan@gmail.com>
@edoakes edoakes added the go add ONLY when ready to merge, run all tests label Dec 19, 2025
@edoakes edoakes enabled auto-merge (squash) December 19, 2025 22:36
@edoakes
Copy link
Collaborator

edoakes commented Dec 19, 2025

Thanks @marwan116

@edoakes edoakes merged commit 0dfe3ce into master Dec 20, 2025
8 checks passed
@edoakes edoakes deleted the add-session-name branch December 20, 2025 01:29
Yicheng-Lu-llll pushed a commit to Yicheng-Lu-llll/ray that referenced this pull request Dec 22, 2025
Currently, there's no public API to retrieve the Ray session name. Users
need to use private APIs like
`ray._private.worker.global_worker.node.session_name` or query the
dashboard REST API. This makes it difficult to filter Prometheus metrics
by cluster when multiple clusters run the same application name, since
Ray metrics use the `SessionName` label (which contains the session_name
value).

---------

Signed-off-by: Marwan Sarieddine <sarieddine.marwan@gmail.com>
AYou0207 pushed a commit to AYou0207/ray that referenced this pull request Jan 13, 2026
Currently, there's no public API to retrieve the Ray session name. Users
need to use private APIs like
`ray._private.worker.global_worker.node.session_name` or query the
dashboard REST API. This makes it difficult to filter Prometheus metrics
by cluster when multiple clusters run the same application name, since
Ray metrics use the `SessionName` label (which contains the session_name
value).

---------

Signed-off-by: Marwan Sarieddine <sarieddine.marwan@gmail.com>
Signed-off-by: jasonwrwang <jasonwrwang@tencent.com>
lee1258561 pushed a commit to pinterest/ray that referenced this pull request Feb 3, 2026
Currently, there's no public API to retrieve the Ray session name. Users
need to use private APIs like
`ray._private.worker.global_worker.node.session_name` or query the
dashboard REST API. This makes it difficult to filter Prometheus metrics
by cluster when multiple clusters run the same application name, since
Ray metrics use the `SessionName` label (which contains the session_name
value).

---------

Signed-off-by: Marwan Sarieddine <sarieddine.marwan@gmail.com>
peterxcli pushed a commit to peterxcli/ray that referenced this pull request Feb 25, 2026
Currently, there's no public API to retrieve the Ray session name. Users
need to use private APIs like
`ray._private.worker.global_worker.node.session_name` or query the
dashboard REST API. This makes it difficult to filter Prometheus metrics
by cluster when multiple clusters run the same application name, since
Ray metrics use the `SessionName` label (which contains the session_name
value).

---------

Signed-off-by: Marwan Sarieddine <sarieddine.marwan@gmail.com>
Signed-off-by: peterxcli <peterxcli@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core docs An issue or change related to documentation go add ONLY when ready to merge, run all tests observability Issues related to the Ray Dashboard, Logging, Metrics, Tracing, and/or Profiling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants