Skip to content

Allow attributes to be identifying or descriptive. #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions crates/weaver_emit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ mod tests {
tags: None,
value: None,
annotations: None,
role: Default::default(),
}],
span_kind: Some(SpanKindSpec::Internal),
events: vec![],
Expand Down
1 change: 1 addition & 0 deletions crates/weaver_emit/src/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ mod tests {
tags: None,
value: None,
annotations: None,
role: Default::default(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"brief",
"note",
"requirement_level",
"role",
"stability"
],
"source_group": "registry.exception"
Expand All @@ -185,6 +186,7 @@
"brief",
"examples",
"note",
"role",
"stability"
],
"locally_overridden_fields": [
Expand All @@ -198,6 +200,7 @@
"examples",
"note",
"requirement_level",
"role",
"stability"
],
"source_group": "registry.exception"
Expand All @@ -207,6 +210,7 @@
"brief",
"examples",
"note",
"role",
"stability"
],
"locally_overridden_fields": [
Expand Down
17 changes: 17 additions & 0 deletions crates/weaver_forge/src/extensions/otel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
};

otel::add_filters(&mut env);
Expand Down Expand Up @@ -810,6 +811,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
};

assert_eq!(
Expand Down Expand Up @@ -997,6 +999,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "rec.b".into(),
Expand All @@ -1013,6 +1016,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "crec.a".into(),
Expand All @@ -1029,6 +1033,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "crec.b".into(),
Expand All @@ -1045,6 +1050,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "rec.c".into(),
Expand All @@ -1061,6 +1067,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "rec.d".into(),
Expand All @@ -1077,6 +1084,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "opt.a".into(),
Expand All @@ -1093,6 +1101,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "opt.b".into(),
Expand All @@ -1109,6 +1118,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "req.a".into(),
Expand All @@ -1125,6 +1135,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "req.b".into(),
Expand All @@ -1141,6 +1152,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
];
let json =
Expand Down Expand Up @@ -1200,6 +1212,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "attr2".to_owned(),
Expand All @@ -1216,6 +1229,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
Attribute {
name: "attr3".to_owned(),
Expand All @@ -1232,6 +1246,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
},
];

Expand Down Expand Up @@ -1523,6 +1538,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
};

otel::add_filters(&mut env);
Expand Down Expand Up @@ -1552,6 +1568,7 @@ mod tests {
value: None,
prefix: false,
annotations: None,
role: Default::default(),
};

otel::add_filters(&mut env);
Expand Down
10 changes: 8 additions & 2 deletions crates/weaver_live_check/src/live_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ mod tests {
use weaver_resolved_schema::attribute::Attribute;
use weaver_semconv::{
attribute::{
AttributeType, EnumEntriesSpec, Examples, PrimitiveOrArrayTypeSpec, RequirementLevel,
TemplateTypeSpec, ValueSpec,
AttributeRole, AttributeType, EnumEntriesSpec, Examples, PrimitiveOrArrayTypeSpec,
RequirementLevel, TemplateTypeSpec, ValueSpec,
},
group::{GroupType, SpanKindSpec},
stability::Stability,
Expand Down Expand Up @@ -320,6 +320,7 @@ mod tests {
tags: None,
value: None,
annotations: None,
role: AttributeRole::Identifying,
},
Attribute {
name: "test.enum".to_owned(),
Expand Down Expand Up @@ -358,6 +359,7 @@ mod tests {
tags: None,
value: None,
annotations: None,
role: AttributeRole::Identifying,
},
Attribute {
name: "test.deprecated".to_owned(),
Expand All @@ -381,6 +383,7 @@ mod tests {
tags: None,
value: None,
annotations: None,
role: AttributeRole::Identifying,
},
Attribute {
name: "test.template".to_owned(),
Expand All @@ -402,6 +405,7 @@ mod tests {
tags: None,
value: None,
annotations: None,
role: AttributeRole::Identifying,
},
],
span_kind: Some(SpanKindSpec::Internal),
Expand Down Expand Up @@ -451,6 +455,7 @@ mod tests {
tags: None,
value: None,
annotations: None,
role: AttributeRole::Identifying,
}],
span_kind: Some(SpanKindSpec::Internal),
events: vec![],
Expand Down Expand Up @@ -619,6 +624,7 @@ mod tests {
tags: None,
value: None,
annotations: None,
role: AttributeRole::Identifying,
}],
span_kind: Some(SpanKindSpec::Internal),
events: vec![],
Expand Down
12 changes: 11 additions & 1 deletion crates/weaver_resolved_schema/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use std::fmt::Display;
use std::ops::Not;
#[cfg(test)]
use weaver_semconv::attribute::PrimitiveOrArrayTypeSpec;
use weaver_semconv::attribute::{AttributeSpec, AttributeType, Examples, RequirementLevel};
use weaver_semconv::attribute::{
AttributeRole, AttributeSpec, AttributeType, Examples, RequirementLevel,
};
use weaver_semconv::deprecated::Deprecated;
use weaver_semconv::stability::Stability;
use weaver_semconv::YamlValue;
Expand Down Expand Up @@ -87,6 +89,10 @@ pub struct Attribute {
/// Note: This is only used in a telemetry schema specification.
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<Value>,
/// Whether the attribute is identifying or descriptive.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a document describing the difference between these two roles that we could reference here?

#[serde(default)]
#[serde(skip_serializing_if = "AttributeRole::is_identifying")]
pub role: AttributeRole,
}

/// An unresolved attribute definition.
Expand Down Expand Up @@ -128,6 +134,7 @@ impl Attribute {
tags: None,
value: None,
annotations: None,
role: Default::default(),
}
}

Expand All @@ -150,6 +157,7 @@ impl Attribute {
tags: None,
value: None,
annotations: None,
role: Default::default(),
}
}

Expand All @@ -172,6 +180,7 @@ impl Attribute {
tags: None,
value: None,
annotations: None,
role: Default::default(),
}
}

Expand All @@ -198,6 +207,7 @@ impl Attribute {
tags: None,
value: None,
annotations: None,
role: Default::default(),
}
}

Expand Down
43 changes: 42 additions & 1 deletion crates/weaver_resolved_schema/src/lineage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::collections::{BTreeMap, BTreeSet};

use serde::{Deserialize, Serialize};

use weaver_semconv::attribute::{AttributeSpec, Examples, RequirementLevel};
use weaver_semconv::attribute::{AttributeRole, AttributeSpec, Examples, RequirementLevel};
use weaver_semconv::deprecated::Deprecated;
use weaver_semconv::provenance::Provenance;
use weaver_semconv::stability::Stability;
Expand Down Expand Up @@ -327,6 +327,47 @@ impl AttributeLineage {
parent_value.clone()
}
}
/// Determines the value of the role field by evaluating the presence of
/// a local value. If a local value is provided, it is used, and the role
/// field's lineage is marked as local. Otherwise, the specified parent
/// value is used, and the role field's lineage is marked as inherited
/// from the parent.
pub fn optional_role(
&mut self,
local_value: &Option<AttributeRole>,
parent_value: &Option<AttributeRole>,
) -> Option<AttributeRole> {
if local_value.is_some() {
_ = self.locally_overridden_fields.insert("role".to_owned());
_ = self.inherited_fields.remove("role");
local_value.clone()
} else {
if parent_value.is_some() {
_ = self.inherited_fields.insert("role".to_owned());
}
parent_value.clone()
}
}

/// Determines the value of the role field by evaluating the presence of
/// a local value. If a local value is provided, it is used, and the role
/// field's lineage is marked as local. Otherwise, the specified parent
/// value is used, and the role field's lineage is marked as inherited
/// from the parent.
pub fn role(
&mut self,
local_value: &Option<AttributeRole>,
parent_value: &AttributeRole,
) -> AttributeRole {
if let Some(v) = local_value {
_ = self.locally_overridden_fields.insert("role".to_owned());
_ = self.inherited_fields.remove("role");
v.clone()
} else {
_ = self.inherited_fields.insert("role".to_owned());
parent_value.clone()
}
}

/// Determines the value of the deprecated field by evaluating the presence of
/// a local value. If a local value is provided, it is used, and the deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"brief",
"examples",
"note",
"role",
"stability"
],
"locally_overridden_fields": [
Expand Down
Loading
Loading