- 
        Couldn't load subscription status. 
- Fork 15
[ffe] add pyo3 conversion methods #1289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| /// Convert Python value to Attribute. | ||
| /// | ||
| /// The following types are currently supported: | ||
| /// - `str` | ||
| /// - `int` | ||
| /// - `float` | ||
| /// - `bool` | ||
| /// - `NoneType` | ||
| /// | ||
| /// Note that nesting is not currently supported and will throw an error. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avara1986 note that we don't support nested dicts, dicts, and datetime attributes, so these need to be filtered out before getting passed into Rust.
| /// Accepts either a dict with `"targeting_key"` and `"attributes"` items, or any object with | ||
| /// `targeting_key` and `attributes` attributes. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```python | ||
| /// {"targeting_key": "user1", "attributes": {"attr1": 42}} | ||
| /// ``` | ||
| /// | ||
| /// ```python | ||
| /// @dataclass | ||
| /// class EvaluationContext: | ||
| /// targeting_key: Optional[str] | ||
| /// attributes: dict[str, Any] | ||
| /// | ||
| /// EvaluationContext(targeting_key="user1", attributes={"attr1": 42}) | ||
| /// ``` | ||
| impl<'py> FromPyObject<'py> for EvaluationContext { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avara1986 for evaluation context, either a dict or an object with targeting_key/attributes is accepted. (We can technically pass OF's EvaluationContext if we filter out unsupported attributes.)
|  | ||
| /// Result of assignment evaluation. | ||
| #[derive(Debug, Serialize, Clone)] | ||
| #[cfg_attr(feature = "pyo3", pyo3::pyclass(frozen))] | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avara1986 found a way to expose enums and classes from Rust, so Assignment and AssignmentReason are proper Python classes now.
| /// Convert `VariationType` from Python string. | ||
| /// | ||
| /// The value must be one of: | ||
| /// ```python | ||
| /// # Preferred: | ||
| /// "string" | ||
| /// "integer" | ||
| /// "float" | ||
| /// "boolean" | ||
| /// "object" | ||
| /// | ||
| /// # Legacy (for compatibility): | ||
| /// "STRING" | ||
| /// "INTEGER" | ||
| /// "NUMERIC" | ||
| /// "BOOLEAN" | ||
| /// "JSON" | ||
| /// ``` | ||
| impl<'py> FromPyObject<'py> for VariationType { | ||
| #[inline] | ||
| fn extract_bound(value: &Bound<'py, PyAny>) -> PyResult<Self> { | ||
| let s = value.downcast::<PyString>()?.to_cow()?; | ||
| let ty = match s.as_ref() { | ||
| "string" | "STRING" => VariationType::String, | ||
| "integer" | "INTEGER" => VariationType::Integer, | ||
| "float" | "NUMERIC" => VariationType::Numeric, | ||
| "boolean" | "BOOLEAN" => VariationType::Boolean, | ||
| "object" | "JSON" => VariationType::Json, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@avara1986 TBD: VariationType stays as string for now but we can convert to enum in the future. The reason I didn't do this yet is because our internal names are inconsistent 😢
| BenchmarksComparisonBenchmark execution time: 2025-10-30 02:24:44 Comparing candidate commit 8a462e1 in PR branch  Found 0 performance improvements and 1 performance regressions! Performance is the same for 54 metrics, 2 unstable metrics. scenario:benching deserializing traces from msgpack to their internal representation
 CandidateCandidate benchmark detailsGroup 1
 
 
 Group 2
 
 
 Group 3
 
 
 Group 4
 
 
 Group 5
 
 
 Group 6
 
 
 Group 7
 
 
 Group 8
 
 
 Group 9
 
 
 Group 10
 
 
 Group 11
 
 
 Group 12
 
 
 Group 13
 
 
 Group 14
 
 
 Group 15
 
 
 Group 16
 
 
 Group 17
 
 
 BaselineOmitted due to size. | 
| Codecov Report❌ Patch coverage is  Additional details and impacted files@@            Coverage Diff             @@
##             main    #1289      +/-   ##
==========================================
- Coverage   72.05%   71.91%   -0.15%     
==========================================
  Files         368      369       +1     
  Lines       58076    58198     +122     
==========================================
+ Hits        41847    41852       +5     
- Misses      16229    16346     +117     
 🚀 New features to boost your workflow:
 | 
| Artifact Size Benchmark Reportaarch64-alpine-linux-musl
 aarch64-unknown-linux-gnu
 libdatadog-x64-windows
 libdatadog-x86-windows
 x86_64-alpine-linux-musl
 x86_64-unknown-linux-gnu
 | 
What does this PR do?
Add pyo3 conversion methods for
datadog-ffe.Motivation
This will allow our Python tracer to easily call into
datadog-ffewith Rust automatically doing conversion from Python to Rust types (and vice versa)How to test the change?
Will be tested as part of ddtrace.