drift-core-python 0.1.5__tar.gz → 0.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/Cargo.lock +5 -3
  2. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/Cargo.toml +4 -1
  3. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/PKG-INFO +1 -1
  4. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/bindings/python/Cargo.toml +1 -0
  5. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/bindings/python/src/api.rs +12 -0
  6. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/Cargo.toml +1 -1
  7. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/src/export_request_proto.rs +14 -0
  8. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/src/hash.rs +31 -0
  9. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/src/normalize.rs +19 -0
  10. drift_core_python-0.1.7/crates/drift-rust-core/src/payload.rs +82 -0
  11. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/src/protobuf_struct.rs +32 -0
  12. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/src/span_proto.rs +48 -6
  13. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/src/types.rs +4 -3
  14. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/pyproject.toml +1 -1
  15. drift_core_python-0.1.5/crates/drift-rust-core/src/payload.rs +0 -35
  16. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/bindings/python/.gitignore +0 -0
  17. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/bindings/python/src/conversion.rs +0 -0
  18. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/bindings/python/src/error.rs +0 -0
  19. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/bindings/python/src/lib.rs +0 -0
  20. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/src/error.rs +0 -0
  21. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/src/lib.rs +0 -0
  22. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/src/schema.rs +0 -0
  23. {drift_core_python-0.1.5 → drift_core_python-0.1.7}/crates/drift-rust-core/tests/fixture_smoke.rs +0 -0
@@ -106,7 +106,7 @@ dependencies = [
106
106
 
107
107
  [[package]]
108
108
  name = "drift-rust-core"
109
- version = "0.1.5"
109
+ version = "0.1.7"
110
110
  dependencies = [
111
111
  "base64",
112
112
  "prost",
@@ -119,22 +119,24 @@ dependencies = [
119
119
 
120
120
  [[package]]
121
121
  name = "drift-rust-core-node"
122
- version = "0.1.5"
122
+ version = "0.1.7"
123
123
  dependencies = [
124
124
  "drift-rust-core",
125
125
  "napi",
126
126
  "napi-build",
127
127
  "napi-derive",
128
128
  "serde_json",
129
+ "tusk-drift-schemas",
129
130
  ]
130
131
 
131
132
  [[package]]
132
133
  name = "drift-rust-core-python"
133
- version = "0.1.5"
134
+ version = "0.1.7"
134
135
  dependencies = [
135
136
  "drift-rust-core",
136
137
  "pyo3",
137
138
  "serde_json",
139
+ "tusk-drift-schemas",
138
140
  ]
139
141
 
140
142
  [[package]]
@@ -3,4 +3,7 @@ members = ["crates/drift-rust-core", "bindings/python"]
3
3
  resolver = "2"
4
4
 
5
5
  [workspace.package]
6
- version = "0.1.5"
6
+ version = "0.1.7"
7
+
8
+ [workspace.dependencies]
9
+ tusk-drift-schemas = "0.1.30"
@@ -1,5 +1,5 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: drift-core-python
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: Python bindings for drift-rust-core
5
5
  Requires-Python: >=3.9
@@ -14,3 +14,4 @@ crate-type = ["cdylib"]
14
14
  drift-rust-core = { path = "../../crates/drift-rust-core" }
15
15
  pyo3 = { version = "0.27", features = ["extension-module", "abi3", "abi3-py39"] }
16
16
  serde_json = "1"
17
+ tusk-drift-schemas.workspace = true
@@ -1,5 +1,6 @@
1
1
  use pyo3::prelude::*;
2
2
  use pyo3::types::{PyBytes, PyList};
3
+ use tusk_drift_schemas::tusk::drift::core::v1::{PackageType, SpanKind, StatusCode};
3
4
 
4
5
  use crate::conversion::{
5
6
  json_value_to_py, py_any_to_optional_bytes, py_any_to_optional_json, py_to_json_value,
@@ -126,6 +127,17 @@ pub fn build_span_proto_bytes_pyobject(
126
127
  let output_value_json = py_any_to_optional_json(output_value)?;
127
128
  let input_struct_bytes = py_any_to_optional_bytes(input_value_proto_struct_bytes)?;
128
129
  let output_struct_bytes = py_any_to_optional_bytes(output_value_proto_struct_bytes)?;
130
+ let package_type = PackageType::try_from(package_type).map_err(|_| {
131
+ pyo3::exceptions::PyValueError::new_err(format!(
132
+ "invalid package_type enum: {package_type}"
133
+ ))
134
+ })?;
135
+ let kind = SpanKind::try_from(kind).map_err(|_| {
136
+ pyo3::exceptions::PyValueError::new_err(format!("invalid kind enum: {kind}"))
137
+ })?;
138
+ let status_code = StatusCode::try_from(status_code).map_err(|_| {
139
+ pyo3::exceptions::PyValueError::new_err(format!("invalid status_code enum: {status_code}"))
140
+ })?;
129
141
 
130
142
  drift_rust_core::build_span_proto_bytes(drift_rust_core::BuildSpanProtoInput {
131
143
  trace_id,
@@ -12,4 +12,4 @@ serde = { version = "1", features = ["derive"] }
12
12
  serde_json = "1"
13
13
  sha2 = "0.10"
14
14
  base64 = "0.22"
15
- tusk-drift-schemas = "0.1.30"
15
+ tusk-drift-schemas.workspace = true
@@ -60,4 +60,18 @@ mod tests {
60
60
  assert_eq!(decoded.spans.len(), 1);
61
61
  assert_eq!(decoded.spans[0].trace_id, "trace-1");
62
62
  }
63
+
64
+ #[test]
65
+ fn returns_error_when_span_bytes_are_invalid() {
66
+ let err = build_export_spans_request_bytes(
67
+ "svc-1",
68
+ "test",
69
+ "0.1.0",
70
+ "sdk-instance-1",
71
+ &[vec![0xff, 0x00, 0xab]],
72
+ )
73
+ .expect_err("invalid span bytes should fail");
74
+
75
+ assert!(matches!(err, CoreError::SerializationError(_)));
76
+ }
63
77
  }
@@ -45,3 +45,34 @@ fn sort_keys_recursively(v: &JsonValue) -> JsonValue {
45
45
  _ => v.clone(),
46
46
  }
47
47
  }
48
+
49
+ #[cfg(test)]
50
+ mod tests {
51
+ use super::*;
52
+
53
+ #[test]
54
+ fn deterministic_hash_is_stable_across_object_key_order() {
55
+ let a = r#"{"z":1,"a":{"m":2,"b":[3,4]}}"#;
56
+ let b = r#"{"a":{"b":[3,4],"m":2},"z":1}"#;
57
+
58
+ let hash_a = deterministic_hash(a).expect("hash should succeed");
59
+ let hash_b = deterministic_hash(b).expect("hash should succeed");
60
+
61
+ assert_eq!(hash_a, hash_b);
62
+ }
63
+
64
+ #[test]
65
+ fn normalize_and_hash_returns_compact_json_and_sha256_hex() {
66
+ let input = "{ \"k\": \"v\", \"n\": 3 }";
67
+ let (normalized, hash) = normalize_and_hash(input).expect("operation should succeed");
68
+
69
+ assert_eq!(normalized, r#"{"k":"v","n":3}"#);
70
+ assert_eq!(hash.len(), 64);
71
+ }
72
+
73
+ #[test]
74
+ fn deterministic_hash_returns_invalid_json_error() {
75
+ let err = deterministic_hash("nope").expect_err("invalid json should fail");
76
+ assert!(matches!(err, CoreError::InvalidJson(_)));
77
+ }
78
+ }
@@ -16,3 +16,22 @@ pub(crate) fn json_roundtrip_normalize(v: &JsonValue) -> CoreResult<JsonValue> {
16
16
  let s = serde_json::to_string(v).map_err(|e| CoreError::SerializationError(e.to_string()))?;
17
17
  serde_json::from_str(&s).map_err(|e| CoreError::SerializationError(e.to_string()))
18
18
  }
19
+
20
+ #[cfg(test)]
21
+ mod tests {
22
+ use super::*;
23
+
24
+ #[test]
25
+ fn normalize_json_compacts_valid_json() {
26
+ let input = "{\n \"b\": 2,\n \"a\": { \"x\": true }\n}";
27
+ let normalized = normalize_json(input).expect("normalization should succeed");
28
+
29
+ assert_eq!(normalized, r#"{"a":{"x":true},"b":2}"#);
30
+ }
31
+
32
+ #[test]
33
+ fn normalize_json_returns_invalid_json_error() {
34
+ let err = normalize_json("{not-valid-json").expect_err("invalid json should fail");
35
+ assert!(matches!(err, CoreError::InvalidJson(_)));
36
+ }
37
+ }
@@ -0,0 +1,82 @@
1
+ use serde_json::Value as JsonValue;
2
+
3
+ use crate::error::{CoreError, CoreResult};
4
+ use crate::normalize::parse_json;
5
+ use crate::schema;
6
+ use crate::types::{ExportPayloadResult, ExportPayloadValueResult};
7
+
8
+ pub fn process_export_payload(
9
+ payload_json: &str,
10
+ schema_merges_json: Option<&str>,
11
+ ) -> CoreResult<ExportPayloadResult> {
12
+ let input = parse_json(payload_json)?;
13
+ let value_result = process_export_payload_value(&input, schema_merges_json)?;
14
+ let normalized_json = serde_json::to_string(&value_result.normalized_value)
15
+ .map_err(|e| CoreError::SerializationError(e.to_string()))?;
16
+ let decoded_json = serde_json::to_string(&value_result.decoded_value)
17
+ .map_err(|e| CoreError::SerializationError(e.to_string()))?;
18
+
19
+ Ok(ExportPayloadResult {
20
+ normalized_json,
21
+ decoded_json,
22
+ decoded_value_hash: value_result.decoded_value_hash,
23
+ decoded_schema_json: serde_json::to_string(&value_result.decoded_schema_value)
24
+ .map_err(|e| CoreError::SerializationError(e.to_string()))?,
25
+ decoded_schema_hash: value_result.decoded_schema_hash,
26
+ protobuf_struct_bytes: value_result.protobuf_struct_bytes,
27
+ })
28
+ }
29
+
30
+ pub fn process_export_payload_value(
31
+ payload_value: &JsonValue,
32
+ schema_merges_json: Option<&str>,
33
+ ) -> CoreResult<ExportPayloadValueResult> {
34
+ schema::process_export_payload_value(payload_value, schema_merges_json)
35
+ }
36
+
37
+ #[cfg(test)]
38
+ mod tests {
39
+ use super::*;
40
+
41
+ #[test]
42
+ fn process_export_payload_value_without_merges_keeps_decoded_equal_normalized() {
43
+ let payload = serde_json::json!({"k":"v","n":1});
44
+ let result = process_export_payload_value(&payload, None).expect("processing should work");
45
+
46
+ assert_eq!(result.decoded_value, result.normalized_value);
47
+ assert_eq!(result.decoded_schema_value["type"], serde_json::json!(6));
48
+ assert!(!result.protobuf_struct_bytes.is_empty());
49
+ }
50
+
51
+ #[test]
52
+ fn process_export_payload_value_applies_base64_and_json_decoding_merges() {
53
+ let payload = serde_json::json!({
54
+ "decoded_blob": "eyJrIjoidiJ9"
55
+ });
56
+ let merges = r#"{"decoded_blob":{"encoding":1,"decoded_type":1,"match_importance":0.75}}"#;
57
+
58
+ let result = process_export_payload_value(&payload, Some(merges))
59
+ .expect("processing with merges should work");
60
+
61
+ assert_eq!(
62
+ result.decoded_value["decoded_blob"]["k"],
63
+ serde_json::json!("v")
64
+ );
65
+ assert_eq!(
66
+ result.decoded_schema_value["properties"]["decoded_blob"]["encoding"],
67
+ serde_json::json!(1)
68
+ );
69
+ assert_eq!(
70
+ result.decoded_schema_value["properties"]["decoded_blob"]["decoded_type"],
71
+ serde_json::json!(1)
72
+ );
73
+ }
74
+
75
+ #[test]
76
+ fn process_export_payload_returns_error_for_invalid_merges_json() {
77
+ let payload = r#"{"k":"v"}"#;
78
+ let err = process_export_payload(payload, Some("{not-json"))
79
+ .expect_err("invalid merges json should fail");
80
+ assert!(matches!(err, CoreError::InvalidJson(_)));
81
+ }
82
+ }
@@ -67,3 +67,35 @@ fn json_to_protobuf_value(v: &JsonValue) -> Value {
67
67
  }
68
68
  }
69
69
  }
70
+
71
+ #[cfg(test)]
72
+ mod tests {
73
+ use super::*;
74
+ use prost_types::value::Kind;
75
+
76
+ #[test]
77
+ fn object_to_protobuf_struct_preserves_top_level_fields() {
78
+ let payload = r#"{"n":1,"s":"x","b":true,"arr":[1,2],"obj":{"k":"v"},"nullv":null}"#;
79
+ let s = object_to_protobuf_struct(payload).expect("conversion should succeed");
80
+
81
+ assert_eq!(s.fields.len(), 6);
82
+ assert!(matches!(
83
+ s.fields.get("nullv").and_then(|v| v.kind.as_ref()),
84
+ Some(Kind::NullValue(_))
85
+ ));
86
+ }
87
+
88
+ #[test]
89
+ fn non_object_json_yields_empty_struct() {
90
+ let s = object_to_protobuf_struct("[1,2,3]").expect("conversion should succeed");
91
+ assert!(s.fields.is_empty());
92
+ }
93
+
94
+ #[test]
95
+ fn object_to_protobuf_struct_field_count_matches_field_total() {
96
+ let payload = r#"{"a":1,"b":2,"c":{"nested":3}}"#;
97
+ let count =
98
+ object_to_protobuf_struct_field_count(payload).expect("field count should succeed");
99
+ assert_eq!(count, 3);
100
+ }
101
+ }
@@ -43,7 +43,7 @@ pub fn build_span_proto_bytes(input: BuildSpanProtoInput<'_>) -> CoreResult<Vec<
43
43
  package_name: input.package_name.to_string(),
44
44
  instrumentation_name: input.instrumentation_name.to_string(),
45
45
  submodule_name: input.submodule_name.to_string(),
46
- package_type: input.package_type,
46
+ package_type: input.package_type as i32,
47
47
  input_value: Some(input_struct),
48
48
  output_value: Some(output_struct),
49
49
  input_schema: Some(json_schema_from_value(input.input_schema)),
@@ -52,9 +52,9 @@ pub fn build_span_proto_bytes(input: BuildSpanProtoInput<'_>) -> CoreResult<Vec<
52
52
  output_schema_hash: input.output_schema_hash.to_string(),
53
53
  input_value_hash: input.input_value_hash.to_string(),
54
54
  output_value_hash: input.output_value_hash.to_string(),
55
- kind: input.kind,
55
+ kind: input.kind as i32,
56
56
  status: Some(SpanStatus {
57
- code: input.status_code,
57
+ code: input.status_code as i32,
58
58
  message: input.status_message.to_string(),
59
59
  }),
60
60
  is_pre_app_start: input.is_pre_app_start,
@@ -123,6 +123,7 @@ fn json_schema_from_value(value: &JsonValue) -> JsonSchema {
123
123
  mod tests {
124
124
  use super::*;
125
125
  use crate::types::BuildSpanProtoInput;
126
+ use tusk_drift_schemas::tusk::drift::core::v1::{PackageType, SpanKind, StatusCode};
126
127
 
127
128
  #[test]
128
129
  fn build_span_proto_bytes_decodes_as_generated_span() {
@@ -140,16 +141,16 @@ mod tests {
140
141
  package_name: "http",
141
142
  instrumentation_name: "instr",
142
143
  submodule_name: "GET",
143
- package_type: 1,
144
+ package_type: PackageType::Http,
144
145
  environment: Some("test"),
145
- kind: 2,
146
+ kind: SpanKind::Server,
146
147
  input_schema: &input_schema,
147
148
  output_schema: &output_schema,
148
149
  input_schema_hash: "ih",
149
150
  output_schema_hash: "oh",
150
151
  input_value_hash: "ivh",
151
152
  output_value_hash: "ovh",
152
- status_code: 1,
153
+ status_code: StatusCode::Ok,
153
154
  status_message: "ok",
154
155
  is_pre_app_start: false,
155
156
  is_root_span: true,
@@ -171,4 +172,45 @@ mod tests {
171
172
  assert_eq!(decoded.kind, 2);
172
173
  assert_eq!(decoded.environment.as_deref(), Some("test"));
173
174
  }
175
+
176
+ #[test]
177
+ fn returns_error_when_prebuilt_proto_struct_bytes_are_invalid() {
178
+ let input_schema = serde_json::json!({"type": 6, "properties": {}});
179
+ let output_schema = serde_json::json!({"type": 6, "properties": {}});
180
+
181
+ let err = build_span_proto_bytes(BuildSpanProtoInput {
182
+ trace_id: "trace-1",
183
+ span_id: "span-1",
184
+ parent_span_id: "",
185
+ name: "test-span",
186
+ package_name: "http",
187
+ instrumentation_name: "instr",
188
+ submodule_name: "GET",
189
+ package_type: PackageType::Http,
190
+ environment: Some("test"),
191
+ kind: SpanKind::Server,
192
+ input_schema: &input_schema,
193
+ output_schema: &output_schema,
194
+ input_schema_hash: "ih",
195
+ output_schema_hash: "oh",
196
+ input_value_hash: "ivh",
197
+ output_value_hash: "ovh",
198
+ status_code: StatusCode::Ok,
199
+ status_message: "ok",
200
+ is_pre_app_start: false,
201
+ is_root_span: true,
202
+ timestamp_seconds: 1,
203
+ timestamp_nanos: 2,
204
+ duration_seconds: 3,
205
+ duration_nanos: 4,
206
+ metadata: None,
207
+ input_value: None,
208
+ output_value: None,
209
+ input_value_proto_struct_bytes: Some(&[0xff, 0x00]),
210
+ output_value_proto_struct_bytes: None,
211
+ })
212
+ .expect_err("invalid struct bytes should fail");
213
+
214
+ assert!(matches!(err, CoreError::SerializationError(_)));
215
+ }
174
216
  }
@@ -1,4 +1,5 @@
1
1
  use serde_json::Value as JsonValue;
2
+ use tusk_drift_schemas::tusk::drift::core::v1::{PackageType, SpanKind, StatusCode};
2
3
 
3
4
  #[derive(Debug, Clone)]
4
5
  pub struct ExportPayloadResult {
@@ -28,16 +29,16 @@ pub struct BuildSpanProtoInput<'a> {
28
29
  pub package_name: &'a str,
29
30
  pub instrumentation_name: &'a str,
30
31
  pub submodule_name: &'a str,
31
- pub package_type: i32,
32
+ pub package_type: PackageType,
32
33
  pub environment: Option<&'a str>,
33
- pub kind: i32,
34
+ pub kind: SpanKind,
34
35
  pub input_schema: &'a JsonValue,
35
36
  pub output_schema: &'a JsonValue,
36
37
  pub input_schema_hash: &'a str,
37
38
  pub output_schema_hash: &'a str,
38
39
  pub input_value_hash: &'a str,
39
40
  pub output_value_hash: &'a str,
40
- pub status_code: i32,
41
+ pub status_code: StatusCode,
41
42
  pub status_message: &'a str,
42
43
  pub is_pre_app_start: bool,
43
44
  pub is_root_span: bool,
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "drift-core-python"
7
- version = "0.1.5"
7
+ version = "0.1.7"
8
8
  description = "Python bindings for drift-rust-core"
9
9
  requires-python = ">=3.9"
10
10
 
@@ -1,35 +0,0 @@
1
- use serde_json::Value as JsonValue;
2
-
3
- use crate::error::{CoreError, CoreResult};
4
- use crate::normalize::parse_json;
5
- use crate::schema;
6
- use crate::types::{ExportPayloadResult, ExportPayloadValueResult};
7
-
8
- pub fn process_export_payload(
9
- payload_json: &str,
10
- schema_merges_json: Option<&str>,
11
- ) -> CoreResult<ExportPayloadResult> {
12
- let input = parse_json(payload_json)?;
13
- let value_result = process_export_payload_value(&input, schema_merges_json)?;
14
- let normalized_json = serde_json::to_string(&value_result.normalized_value)
15
- .map_err(|e| CoreError::SerializationError(e.to_string()))?;
16
- let decoded_json = serde_json::to_string(&value_result.decoded_value)
17
- .map_err(|e| CoreError::SerializationError(e.to_string()))?;
18
-
19
- Ok(ExportPayloadResult {
20
- normalized_json,
21
- decoded_json,
22
- decoded_value_hash: value_result.decoded_value_hash,
23
- decoded_schema_json: serde_json::to_string(&value_result.decoded_schema_value)
24
- .map_err(|e| CoreError::SerializationError(e.to_string()))?,
25
- decoded_schema_hash: value_result.decoded_schema_hash,
26
- protobuf_struct_bytes: value_result.protobuf_struct_bytes,
27
- })
28
- }
29
-
30
- pub fn process_export_payload_value(
31
- payload_value: &JsonValue,
32
- schema_merges_json: Option<&str>,
33
- ) -> CoreResult<ExportPayloadValueResult> {
34
- schema::process_export_payload_value(payload_value, schema_merges_json)
35
- }