def _actor_hydrate_span_args(class_: _nameable, method: _nameable): """Get the Attributes of the actor that will be reported as attributes in the trace.""" if callable(class_): class_ = class_.__name__ if callable(method): method = method.__name__ runtime_context = get_runtime_context().get() span_args = { "ray.remote": "actor", "ray.actor_class": class_, "ray.actor_method": method, "ray.function": f"{class_}.{method}", "ray.pid": str(os.getpid()), "ray.job_id": runtime_context["job_id"].hex(), "ray.node_id": runtime_context["node_id"].hex(), } # We only get actor ID for workers if ray.worker.global_worker.mode == ray.worker.WORKER_MODE: actor_id = (runtime_context["actor_id"].hex() if runtime_context["actor_id"] else None) if actor_id: span_args["ray.actor_id"] = actor_id worker_id = getattr(ray.worker.global_worker, "worker_id", None) if worker_id: span_args["ray.worker_id"] = worker_id.hex() return span_args
def _function_hydrate_span_args(func: Callable[..., Any]): """Get the Attributes of the function that will be reported as attributes in the trace.""" runtime_context = get_runtime_context().get() span_args = { "ray.remote": "function", "ray.function": func, "ray.pid": str(os.getpid()), "ray.job_id": runtime_context["job_id"].hex(), "ray.node_id": runtime_context["node_id"].hex(), } # We only get task ID for workers if ray.worker.global_worker.mode == ray.worker.WORKER_MODE: task_id = (runtime_context["task_id"].hex() if runtime_context["task_id"] else None) if task_id: span_args["ray.task_id"] = task_id worker_id = getattr(ray.worker.global_worker, "worker_id", None) if worker_id: span_args["ray.worker_id"] = worker_id.hex() return span_args