Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 {
prefix: false,
tags: None,
value: None,
annotations: None,
}],
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 @@ -183,6 +183,7 @@ mod tests {
prefix: false,
tags: None,
value: None,
annotations: None,
}
}

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 @@ -789,6 +789,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
};

otel::add_filters(&mut env);
Expand Down Expand Up @@ -817,6 +818,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
};

assert_eq!(
Expand Down Expand Up @@ -1003,6 +1005,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "rec.b".into(),
Expand All @@ -1018,6 +1021,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "crec.a".into(),
Expand All @@ -1033,6 +1037,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "crec.b".into(),
Expand All @@ -1048,6 +1053,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "rec.c".into(),
Expand All @@ -1063,6 +1069,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "rec.d".into(),
Expand All @@ -1078,6 +1085,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "opt.a".into(),
Expand All @@ -1093,6 +1101,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "opt.b".into(),
Expand All @@ -1108,6 +1117,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "req.a".into(),
Expand All @@ -1123,6 +1133,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "req.b".into(),
Expand All @@ -1138,6 +1149,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
];
let json =
Expand Down Expand Up @@ -1196,6 +1208,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "attr2".to_owned(),
Expand All @@ -1211,6 +1224,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
Attribute {
name: "attr3".to_owned(),
Expand All @@ -1226,6 +1240,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
},
];

Expand Down Expand Up @@ -1516,6 +1531,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
};

otel::add_filters(&mut env);
Expand Down Expand Up @@ -1544,6 +1560,7 @@ mod tests {
tags: None,
value: None,
prefix: false,
annotations: None,
};

otel::add_filters(&mut env);
Expand Down
1 change: 1 addition & 0 deletions crates/weaver_resolved_schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ thiserror.workspace = true
serde.workspace = true
ordered-float.workspace = true
schemars.workspace = true
serde_yaml.workspace = true

[dev-dependencies]
serde_json.workspace = true
10 changes: 10 additions & 0 deletions crates/weaver_resolved_schema/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use crate::tags::Tags;
use crate::value::Value;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
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::deprecated::Deprecated;
use weaver_semconv::stability::Stability;
use weaver_semconv::YamlValue;

/// An attribute definition.
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash, JsonSchema)]
Expand Down Expand Up @@ -76,6 +78,10 @@ pub struct Attribute {
/// A set of tags for the attribute.
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<Tags>,
/// Annotations for the group.
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub annotations: Option<BTreeMap<String, YamlValue>>,

/// The value of the attribute.
/// Note: This is only used in a telemetry schema specification.
Expand Down Expand Up @@ -121,6 +127,7 @@ impl Attribute {
prefix: false,
tags: None,
value: None,
annotations: None,
}
}

Expand All @@ -142,6 +149,7 @@ impl Attribute {
prefix: false,
tags: None,
value: None,
annotations: None,
}
}

Expand All @@ -163,6 +171,7 @@ impl Attribute {
prefix: false,
tags: None,
value: None,
annotations: None,
}
}

Expand All @@ -188,6 +197,7 @@ impl Attribute {
prefix: false,
tags: None,
value: None,
annotations: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/weaver_resolved_schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl ResolvedTelemetrySchema {
constraints: vec![],
unit: None,
body: None,
annotations: None,
});
}

Expand Down
27 changes: 27 additions & 0 deletions crates/weaver_resolved_schema/src/lineage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
use weaver_semconv::attribute::{AttributeSpec, Examples, RequirementLevel};
use weaver_semconv::deprecated::Deprecated;
use weaver_semconv::stability::Stability;
use weaver_semconv::YamlValue;

/// Attribute lineage (at the field level).
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
Expand Down Expand Up @@ -374,6 +375,32 @@ impl AttributeLineage {
}
}

/// Determines the value of the annotations field by evaluating the presence of
/// a local value. If a local value is provided, it is used, and the annotations
/// field's lineage is marked as local. Otherwise, the specified parent
/// value is used, and the tag field's lineage is marked as inherited
/// from the parent.
/// This method updates the lineage information for the annotations field to
/// reflect the source of its value.
pub fn annotations(
&mut self,
local_value: &Option<BTreeMap<String, YamlValue>>,
parent_value: &Option<BTreeMap<String, YamlValue>>,
) -> Option<BTreeMap<String, YamlValue>> {
if local_value.is_some() {
_ = self
.locally_overridden_fields
.insert("annotations".to_owned());
_ = self.inherited_fields.remove("annotations");
local_value.clone()
} else {
if parent_value.is_some() {
_ = self.inherited_fields.insert("annotations".to_owned());
}
parent_value.clone()
}
}

/// Determines the value of the tags field by evaluating the presence of
/// a local value. If a local value is provided, it is used, and the tags
/// field's lineage is marked as local. Otherwise, the specified parent
Expand Down
14 changes: 9 additions & 5 deletions crates/weaver_resolved_schema/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ use schemars::JsonSchema;
use std::collections::{BTreeMap, HashMap, HashSet};
use weaver_semconv::any_value::AnyValueSpec;

use serde::{Deserialize, Serialize};
use weaver_semconv::deprecated::Deprecated;
use weaver_semconv::group::{GroupType, InstrumentSpec, SpanKindSpec};
use weaver_semconv::stability::Stability;

use crate::attribute::{Attribute, AttributeRef};
use crate::catalog::Catalog;
use crate::error::{handle_errors, Error};
use crate::lineage::GroupLineage;
use crate::registry::GroupStats::{
AttributeGroup, Event, Metric, MetricGroup, Resource, Scope, Span,
};
use serde::{Deserialize, Serialize};
use weaver_semconv::deprecated::Deprecated;
use weaver_semconv::group::{GroupType, InstrumentSpec, SpanKindSpec};
use weaver_semconv::stability::Stability;
use weaver_semconv::YamlValue;

/// A semantic convention registry.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema)]
Expand Down Expand Up @@ -131,6 +131,10 @@ pub struct Group {
/// This fields is only used for event groups.
#[serde(skip_serializing_if = "Option::is_none")]
pub body: Option<AnyValueSpec>,
/// Annotations for the group.
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub annotations: Option<HashMap<String, YamlValue>>,
Comment thread
lquerel marked this conversation as resolved.
}

/// Common statistics for a group.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Test that annotations end up in the resolved registry.
This test must success.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"name": "attr1",
"type": "string",
"brief": "Brief",
"examples": "eu-central-1",
"requirement_level": "required",
"note": "Note",
"stability": "stable",
"annotations": {
"code_generation": {
"exclude": true
},
"privacy_sensitivity": "PII"
}
},
{
"name": "attr1",
"type": "string",
"brief": "Brief",
"examples": "eu-central-1",
"requirement_level": "required",
"note": "Note",
"stability": "stable",
"annotations": {
"code_generation": {
"exclude": true
},
"privacy_sensitivity": "PII + PHI"
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"registry_url": "https://127.0.0.1",
"groups": [
{
"id": "attrs",
"type": "attribute_group",
"brief": "Attributes",
"attributes": [
0
],
"lineage": {
"source_file": "data/registry-test-14-annotations/registry/group-with-annotations.yaml"
},
"annotations": {
"privacy_sensitivity": "PII",
"code_generation": {
"exclude": true
}
}
},
{
"id": "attrs_ext",
"type": "attribute_group",
"brief": "Attributes",
"attributes": [
1
],
"lineage": {
"source_file": "data/registry-test-14-annotations/registry/group-with-annotations.yaml",
"attributes": {
"attr1": {
"source_group": "attrs",
"inherited_fields": [
"brief",
"examples",
"note",
"requirement_level",
"stability"
],
"locally_overridden_fields": [
"annotations"
]
}
}
}
}
]
}
Loading