Skip to content

Commit e0f8fdc

Browse files
authored
refactor: update span proto types (#74)
1 parent 2c23291 commit e0f8fdc

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

drift/core/rust_core_binding.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
import json
1010
import logging
1111
import os
12-
from typing import Any
12+
from typing import TYPE_CHECKING, Any
13+
14+
if TYPE_CHECKING:
15+
from .types import PackageType, SpanKind, StatusCode
1316

1417
logger = logging.getLogger(__name__)
1518

@@ -161,16 +164,16 @@ def build_span_proto_bytes(
161164
package_name: str,
162165
instrumentation_name: str,
163166
submodule_name: str,
164-
package_type: int,
167+
package_type: PackageType,
165168
environment: str | None,
166-
kind: int,
169+
kind: SpanKind,
167170
input_schema: dict[str, Any],
168171
output_schema: dict[str, Any],
169172
input_schema_hash: str,
170173
output_schema_hash: str,
171174
input_value_hash: str,
172175
output_value_hash: str,
173-
status_code: int,
176+
status_code: StatusCode,
174177
status_message: str,
175178
is_pre_app_start: bool,
176179
is_root_span: bool,
@@ -190,6 +193,14 @@ def build_span_proto_bytes(
190193
if binding is None:
191194
return None
192195
try:
196+
from .types import PackageType, SpanKind, StatusCode
197+
198+
if not isinstance(package_type, PackageType):
199+
raise TypeError(f"package_type must be PackageType, got {type(package_type).__name__}")
200+
if not isinstance(kind, SpanKind):
201+
raise TypeError(f"kind must be SpanKind, got {type(kind).__name__}")
202+
if not isinstance(status_code, StatusCode):
203+
raise TypeError(f"status_code must be StatusCode, got {type(status_code).__name__}")
193204
return binding.build_span_proto_bytes_pyobject(
194205
trace_id,
195206
span_id,
@@ -198,16 +209,16 @@ def build_span_proto_bytes(
198209
package_name,
199210
instrumentation_name,
200211
submodule_name,
201-
package_type,
212+
package_type.value,
202213
environment,
203-
kind,
214+
kind.value,
204215
input_schema,
205216
output_schema,
206217
input_schema_hash,
207218
output_schema_hash,
208219
input_value_hash,
209220
output_value_hash,
210-
status_code,
221+
status_code.value,
211222
status_message,
212223
is_pre_app_start,
213224
is_root_span,

drift/core/tracing/otel_converter.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,6 @@ def otel_span_to_clean_span_data(
420420
# Convert kind
421421
kind = otel_span_kind_to_drift(otel_span.kind)
422422

423-
kind_value = kind.value if hasattr(kind, "value") else kind
424-
status_code_value = status.code.value if hasattr(status.code, "value") else status.code
425-
package_type_value = package_type.value if hasattr(package_type, "value") else package_type
426423
span_proto_bytes = build_span_proto_bytes(
427424
trace_id=trace_id,
428425
span_id=span_id,
@@ -431,16 +428,16 @@ def otel_span_to_clean_span_data(
431428
package_name=package_name,
432429
instrumentation_name=instrumentation_name,
433430
submodule_name=submodule_name,
434-
package_type=package_type_value,
431+
package_type=package_type,
435432
environment=environment,
436-
kind=kind_value,
433+
kind=kind,
437434
input_schema=input_schema,
438435
output_schema=output_schema,
439436
input_schema_hash=input_schema_hash,
440437
output_schema_hash=output_schema_hash,
441438
input_value_hash=input_value_hash,
442439
output_value_hash=output_value_hash,
443-
status_code=status_code_value,
440+
status_code=status.code,
444441
status_message=status.message,
445442
is_pre_app_start=is_pre_app_start,
446443
is_root_span=is_root_span,

0 commit comments

Comments
 (0)