Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@
"note",
"stability"
],
"locally_overridden_fields": [
"requirement_level"
],
"source_group": "registry.data.registry.registry-http"
},
"http.response.status_code": {
Expand All @@ -151,8 +148,7 @@
],
"locally_overridden_fields": [
"brief",
"examples",
"requirement_level"
"examples"
],
"source_group": "registry.data.registry.registry-http"
},
Expand All @@ -163,8 +159,7 @@
"stability"
],
"locally_overridden_fields": [
"brief",
"requirement_level"
"brief"
],
"source_group": "server"
},
Expand All @@ -175,8 +170,7 @@
"stability"
],
"locally_overridden_fields": [
"brief",
"requirement_level"
"brief"
],
"source_group": "server"
},
Expand All @@ -187,8 +181,7 @@
"stability"
],
"locally_overridden_fields": [
"examples",
"requirement_level"
"examples"
],
"source_group": "registry.url"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@
"note",
"stability"
],
"locally_overridden_fields": [
"requirement_level"
],
"source_group": "registry.data.registry.registry-http"
},
"http.response.status_code": {
Expand All @@ -151,8 +148,7 @@
],
"locally_overridden_fields": [
"brief",
"examples",
"requirement_level"
"examples"
],
"source_group": "registry.data.registry.registry-http"
},
Expand All @@ -163,8 +159,7 @@
"stability"
],
"locally_overridden_fields": [
"brief",
"requirement_level"
"brief"
],
"source_group": "server"
},
Expand All @@ -175,8 +170,7 @@
"stability"
],
"locally_overridden_fields": [
"brief",
"requirement_level"
"brief"
],
"source_group": "server"
},
Expand All @@ -187,8 +181,7 @@
"stability"
],
"locally_overridden_fields": [
"examples",
"requirement_level"
"examples"
],
"source_group": "registry.url"
}
Expand Down
10 changes: 10 additions & 0 deletions crates/weaver_forge/src/v2/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ mod tests {
}],
entity_associations: vec![],
common: CommonFields::default(),
lineage: None,
}],
metrics: vec![metric::Metric {
name: SignalId::from("my-metric".to_owned()),
Expand All @@ -485,6 +486,7 @@ mod tests {
}],
entity_associations: vec![],
common: CommonFields::default(),
lineage: None,
}],
events: vec![event::Event {
name: SignalId::from("my-event".to_owned()),
Expand All @@ -496,6 +498,7 @@ mod tests {
}],
entity_associations: vec![],
common: CommonFields::default(),
lineage: None,
}],
entities: vec![v2::entity::Entity {
r#type: SignalId::from("my-entity".to_owned()),
Expand Down Expand Up @@ -528,7 +531,9 @@ mod tests {
}],
entity_associations: vec![],
common: CommonFields::default(),
lineage: None,
},
lineage: None,
}],
metrics: vec![metric::MetricRefinement {
id: SignalId::from("my-refined-metric".to_owned()),
Expand All @@ -544,7 +549,9 @@ mod tests {
}],
entity_associations: vec![],
common: CommonFields::default(),
lineage: None,
},
lineage: None,
}],
events: vec![event::EventRefinement {
id: SignalId::from("my-refined-event".to_owned()),
Expand All @@ -558,7 +565,9 @@ mod tests {
}],
entity_associations: vec![],
common: CommonFields::default(),
lineage: None,
},
lineage: None,
}],
},
};
Expand Down Expand Up @@ -629,6 +638,7 @@ mod tests {
}],
entity_associations: vec![],
common: CommonFields::default(),
lineage: None,
}],
metrics: vec![],
events: vec![],
Expand Down
12 changes: 11 additions & 1 deletion crates/weaver_resolved_schema/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use serde::{Deserialize, Serialize};

use crate::attribute::AttributeRef;
use crate::error::Error::{AttributeNotFound, CompoundError, EventNameNotFound, InvalidSchemaUrl};
use crate::error::Error::{
AttributeNotFound, CompoundError, EventNameNotFound, InvalidSchemaUrl, RefinementLineageBroken,
};

/// Errors emitted by this crate.
#[derive(thiserror::Error, Debug, Clone, Deserialize, Serialize)]
Expand Down Expand Up @@ -36,6 +38,13 @@ pub enum Error {
error: String,
},

/// A refinement signal could not be found.
#[error("Unable to determine refinement lineage for v1 group: {group_id}")]
RefinementLineageBroken {
/// Group id.
group_id: String,
},

/// A generic container for multiple errors.
#[error("Errors:\n{0:#?}")]
CompoundError(Vec<Error>),
Expand Down Expand Up @@ -63,6 +72,7 @@ impl Error {
CompoundError(errors) => errors,
e @ AttributeNotFound { .. } => vec![e],
e @ EventNameNotFound { .. } => vec![e],
e @ RefinementLineageBroken { .. } => vec![e],
e @ InvalidSchemaUrl { .. } => vec![e],
})
.collect(),
Expand Down
35 changes: 35 additions & 0 deletions crates/weaver_resolved_schema/src/lineage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ pub struct GroupLineage {
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub includes_group: Vec<String>,

/// (V2 Only) Track inherited fields for accurate V2 schema lineage reconstruction.
#[serde(skip)]
pub v2_inherited_fields: BTreeSet<String>,

/// (V2 Only) Track locally overridden fields for accurate V2 schema lineage reconstruction.
#[serde(skip)]
pub v2_locally_overridden_fields: BTreeSet<String>,

/// (V2 Only) The ID of the signal being refined.
#[serde(skip)]
pub v2_refines: Option<String>,
}

impl AttributeLineage {
Expand Down Expand Up @@ -483,9 +495,17 @@ impl GroupLineage {
extends_group: None,
attributes: Default::default(),
includes_group: Default::default(),
v2_inherited_fields: Default::default(),
v2_locally_overridden_fields: Default::default(),
v2_refines: None,
}
}

/// Declares this group refined another signal (v2 only).
pub fn refines(&mut self, refines: &str) {
self.v2_refines = Some(refines.to_owned());
}

/// Declares this group extended another group.
pub fn extends(&mut self, extends_group: &str) {
self.extends_group = Some(extends_group.to_owned());
Expand All @@ -507,6 +527,11 @@ impl GroupLineage {
self.attributes.contains_key(attr_id)
}

/// Returns an iterator over all attribute lineages.
pub fn attributes(&self) -> impl Iterator<Item = (&String, &AttributeLineage)> {
self.attributes.iter()
}

/// Returns the attribute lineage.
#[must_use]
pub fn attribute(&self, attr_id: &str) -> Option<&AttributeLineage> {
Expand All @@ -518,4 +543,14 @@ impl GroupLineage {
pub fn provenance(&self) -> &Provenance {
&self.provenance
}

/// Adds a field as inherited (V2 tracking).
pub fn add_v2_inherited_field(&mut self, field: &str) {
_ = self.v2_inherited_fields.insert(field.to_owned());
}

/// Adds a field as locally overridden (V2 tracking).
pub fn add_v2_locally_overridden_field(&mut self, field: &str) {
_ = self.v2_locally_overridden_fields.insert(field.to_owned());
}
}
4 changes: 3 additions & 1 deletion crates/weaver_resolved_schema/src/v2/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use weaver_semconv::{
use crate::v2::Signal;

/// The definition of an Attribute.
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema, PartialEq, Hash, Eq)]
#[derive(
Serialize, Deserialize, Debug, Clone, JsonSchema, PartialEq, Hash, Eq, PartialOrd, Ord,
)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "snake_case")]
pub struct Attribute {
Expand Down
7 changes: 6 additions & 1 deletion crates/weaver_resolved_schema/src/v2/attribute_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use weaver_semconv::v2::{signal_id::SignalId, CommonFields};

use crate::v2::{attribute::AttributeRef, Signal};
use crate::v2::{attribute::AttributeRef, lineage::SignalLineage, Signal};

/// Public attribute group.
///
Expand All @@ -27,6 +27,11 @@ pub struct AttributeGroup {
/// Common fields (like brief, note, annotations).
#[serde(flatten)]
pub common: CommonFields,

/// Lineage for this attribute group.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub lineage: Option<SignalLineage>,
}

impl Signal for AttributeGroup {
Expand Down
16 changes: 15 additions & 1 deletion crates/weaver_resolved_schema/src/v2/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use weaver_semconv::{
v2::{signal_id::SignalId, CommonFields},
};

use crate::v2::{attribute::AttributeRef, Signal};
use crate::v2::{
attribute::AttributeRef,
lineage::{RefinementLineage, SignalLineage},
Signal,
};

/// The definition of an Event signal.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
Expand All @@ -33,6 +37,11 @@ pub struct Event {
/// Common fields (like brief, note, annotations).
#[serde(flatten)]
pub common: CommonFields,

/// Lineage for this event.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub lineage: Option<SignalLineage>,
}

/// A special type of reference to attributes that remembers event-specicific information.
Expand Down Expand Up @@ -66,6 +75,11 @@ pub struct EventRefinement {
/// The definition of the event refinement.
#[serde(flatten)]
pub event: Event,

/// Lineage for this event refinement.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub lineage: Option<RefinementLineage>,
}

impl Signal for Event {
Expand Down
Loading
Loading