Skip to content

py_function_sync_async should work with sync functions that return a future #59

Description

@erichulburd

Opentelemetry context propagation in the QCS SDK broke when py_function_sync_async migrated from QCS SDK to this repository. The missing bit is the with_current_context and corresponding (use opentelemetry::trace::FutureExt;):

 macro_rules! py_function_sync_async {
     (
         $(#[$meta: meta])+
         async fn $name: ident($($(#[$arg_meta: meta])*$arg: ident : $kind: ty),* $(,)?) $(-> $ret: ty)? $body: block
     ) => {
         async fn $name($($arg: $kind,)*) $(-> $ret)? {
             $body
         }
 
         ::paste::paste! {
         $(#[$meta])+
         #[allow(clippy::too_many_arguments)]
         #[pyo3(name = $name "")]
         pub fn [< py_ $name >](py: ::pyo3::Python<'_> $(, $(#[$arg_meta])*$arg: $kind)*) $(-> $ret)? {
             use opentelemetry::trace::FutureExt;
             $crate::py_sync::py_sync!(py, $name($($arg),*).with_current_context())
         }
 
         $(#[$meta])+
         #[pyo3(name = $name "_async")]
         #[allow(clippy::too_many_arguments)]
         pub fn [< py_ $name _async >](py: ::pyo3::Python<'_> $(, $(#[$arg_meta])*$arg: $kind)*) -> ::pyo3::PyResult<&::pyo3::PyAny> {
             use opentelemetry::trace::FutureExt;
             $crate::py_sync::py_async!(py, $name($($arg),*).with_current_context())
         }
         }
     };
 }

To avoid introducing anything Opentelemetry in this repository, we should support this macro matching on a sync function that returns a future.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions