Skip to main content

openlineage_client/
event.rs

1//! OpenLineage run-event envelope.
2//!
3//! See <https://openlineage.io/docs/spec/object-model> and the core
4//! `OpenLineage.json` spec.
5
6use serde::{Deserialize, Serialize};
7use uuid::Uuid;
8
9use crate::facets::{DatasetFacets, InputDatasetFacets, JobFacets, OutputDatasetFacets, RunFacets};
10
11/// URL of the OpenLineage run-event schema this crate emits against.
12pub const RUN_EVENT_SCHEMA_URL: &str =
13    "https://openlineage.io/spec/2-0-2/OpenLineage.json#/$defs/RunEvent";
14
15/// Lifecycle stage of a run, per the OpenLineage spec.
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
17#[serde(rename_all = "UPPERCASE")]
18pub enum RunEventType {
19    /// The run has started.
20    Start,
21    /// The run is in progress.
22    Running,
23    /// The run finished successfully.
24    Complete,
25    /// The run was aborted before completing.
26    Abort,
27    /// The run failed.
28    Fail,
29    /// A lifecycle event that doesn't fit the other variants.
30    Other,
31}
32
33/// A single OpenLineage run event.
34///
35/// All events for one query share a constant [`Run::run_id`]; `eventType`
36/// distinguishes START from COMPLETE/FAIL.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct RunEvent {
40    /// Lifecycle stage this event reports.
41    pub event_type: RunEventType,
42    /// RFC3339 timestamp.
43    pub event_time: String,
44    /// The run this event belongs to.
45    pub run: Run,
46    /// The job the run is an execution of.
47    pub job: Job,
48    /// Datasets consumed by the run.
49    #[serde(default)]
50    pub inputs: Vec<Dataset>,
51    /// Datasets produced by the run.
52    #[serde(default)]
53    pub outputs: Vec<Dataset>,
54    /// URI identifying the software that emitted the event.
55    pub producer: String,
56    /// URL of the OpenLineage schema this event conforms to.
57    #[serde(rename = "schemaURL")]
58    pub schema_url: String,
59}
60
61/// A single execution of a [`Job`], stable across all its events.
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(rename_all = "camelCase")]
64pub struct Run {
65    /// Unique identifier shared by every event of this run.
66    pub run_id: Uuid,
67    /// Run-level facets carrying additional metadata.
68    #[serde(default)]
69    pub facets: RunFacets,
70}
71
72/// A process definition that runs are executions of.
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct Job {
75    /// Namespace the job belongs to.
76    pub namespace: String,
77    /// Job name, unique within its namespace.
78    pub name: String,
79    /// Job-level facets carrying additional metadata.
80    #[serde(default)]
81    pub facets: JobFacets,
82}
83
84/// A dataset consumed or produced by a run.
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct Dataset {
87    /// Namespace the dataset belongs to.
88    pub namespace: String,
89    /// Dataset name, unique within its namespace.
90    pub name: String,
91    /// Dataset-level facets carrying additional metadata.
92    #[serde(default)]
93    pub facets: DatasetFacets,
94    /// Input-only facets (e.g. runtime statistics). Serialized as `inputFacets`
95    /// and only present on input datasets.
96    #[serde(
97        rename = "inputFacets",
98        default,
99        skip_serializing_if = "Option::is_none"
100    )]
101    pub input_facets: Option<InputDatasetFacets>,
102    /// Output-only facets (e.g. runtime statistics). Serialized as
103    /// `outputFacets` and only present on output datasets.
104    #[serde(
105        rename = "outputFacets",
106        default,
107        skip_serializing_if = "Option::is_none"
108    )]
109    pub output_facets: Option<OutputDatasetFacets>,
110}