scouter_tracing/
error.rs

1use pyo3::exceptions::PyRuntimeError;
2use pyo3::PyErr;
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum TraceError {
7    #[error("{0}")]
8    PyError(String),
9
10    #[error("Failed to initialize tracer: {0}")]
11    InitializationError(String),
12
13    #[error("Span operation failed: {0}")]
14    SpanError(String),
15
16    #[error("OpenTelemetry error: {0}")]
17    OTelBuilderError(#[from] opentelemetry_otlp::ExporterBuildError),
18
19    #[error("No active span found")]
20    NoActiveSpan,
21
22    #[error("Poison error occurred")]
23    PoisonError(String),
24
25    #[error(transparent)]
26    OTelSdkError(#[from] opentelemetry_sdk::error::OTelSdkError),
27
28    #[error(transparent)]
29    TypeError(#[from] scouter_types::error::TypeError),
30
31    #[error("Event must be a dictionary or a Pydantic BaseModel")]
32    EventMustBeDict,
33
34    #[error("Failed to downcast Python object: {0}")]
35    DowncastError(String),
36
37    #[error(transparent)]
38    SerdeError(#[from] serde_json::Error),
39
40    #[error("Invalid function type: {0}")]
41    InvalidFunctionType(String),
42
43    #[error("Unsupported SpanExporter type")]
44    UnsupportedSpanExporterType,
45
46    #[error(transparent)]
47    EventError(#[from] scouter_events::error::EventError),
48}
49
50impl<'a> From<pyo3::DowncastError<'a, 'a>> for TraceError {
51    fn from(err: pyo3::DowncastError) -> Self {
52        TraceError::DowncastError(err.to_string())
53    }
54}
55
56impl From<TraceError> for PyErr {
57    fn from(err: TraceError) -> PyErr {
58        let msg = err.to_string();
59        PyRuntimeError::new_err(msg)
60    }
61}
62
63impl From<PyErr> for TraceError {
64    fn from(err: PyErr) -> TraceError {
65        TraceError::PyError(err.to_string())
66    }
67}