diff --git a/crates/weaver_resolver/data/registry-test-12-rename/expected-attribute-catalog.json b/crates/weaver_resolver/data/registry-test-12-rename/expected-attribute-catalog.json new file mode 100644 index 00000000..fb8832b0 --- /dev/null +++ b/crates/weaver_resolver/data/registry-test-12-rename/expected-attribute-catalog.json @@ -0,0 +1,35 @@ +[ + { + "name": "file.name", + "type": "string", + "brief": "The name of the file.", + "examples": [ + "log.txt", + "/var/log/messages" + ], + "requirement_level": "recommended", + "note": "The name of the file" + }, + { + "name": "log.file.name", + "type": "string", + "brief": "The name of the file.", + "examples": [ + "log.txt", + "/var/log/messages" + ], + "requirement_level": "recommended", + "note": "The name of the file" + }, + { + "name": "log.error.file.name", + "type": "string", + "brief": "The name of the file.", + "examples": [ + "log.txt", + "/var/log/messages" + ], + "requirement_level": "recommended", + "note": "The name of the file" + } +] \ No newline at end of file diff --git a/crates/weaver_resolver/data/registry-test-12-rename/expected-registry.json b/crates/weaver_resolver/data/registry-test-12-rename/expected-registry.json new file mode 100644 index 00000000..3852c1fd --- /dev/null +++ b/crates/weaver_resolver/data/registry-test-12-rename/expected-registry.json @@ -0,0 +1,48 @@ +{ + "registry_url": "https://127.0.0.1", + "groups": [ + { + "id": "logs.file", + "type": "attribute_group", + "brief": "Common log file attributes.", + "attributes": [ + 1, + 2 + ], + "lineage": { + "source_file": "data/registry-test-12-rename/registry/logs-file.yaml", + "attributes": { + "log.error.file.name": { + "source_group": "registry.file", + "inherited_fields": [ + "brief", + "examples", + "note", + "requirement_level" + ] + }, + "log.file.name": { + "source_group": "registry.file", + "inherited_fields": [ + "brief", + "examples", + "note", + "requirement_level" + ] + } + } + } + }, + { + "id": "registry.file", + "type": "attribute_group", + "brief": "Attributes describing telemetry around files.", + "attributes": [ + 0 + ], + "lineage": { + "source_file": "data/registry-test-12-rename/registry/registry-file.yaml" + } + } + ] +} \ No newline at end of file diff --git a/crates/weaver_resolver/data/registry-test-12-rename/registry/logs-file.yaml b/crates/weaver_resolver/data/registry-test-12-rename/registry/logs-file.yaml new file mode 100644 index 00000000..d8e57170 --- /dev/null +++ b/crates/weaver_resolver/data/registry-test-12-rename/registry/logs-file.yaml @@ -0,0 +1,10 @@ +groups: + - id: logs.file + type: attribute_group + brief: "Common log file attributes." + attributes: + - ref: file.name + rename: log.file.name + - ref: file.name + rename: log.error.file.name + \ No newline at end of file diff --git a/crates/weaver_resolver/data/registry-test-12-rename/registry/registry-file.yaml b/crates/weaver_resolver/data/registry-test-12-rename/registry/registry-file.yaml new file mode 100644 index 00000000..eb9364dc --- /dev/null +++ b/crates/weaver_resolver/data/registry-test-12-rename/registry/registry-file.yaml @@ -0,0 +1,10 @@ +groups: + - id: registry.file + type: attribute_group + brief: 'Attributes describing telemetry around files.' + attributes: + - id: file.name + type: string + brief: 'The name of the file.' + note: 'The name of the file' + examples: ['log.txt', '/var/log/messages'] \ No newline at end of file diff --git a/crates/weaver_resolver/src/attribute.rs b/crates/weaver_resolver/src/attribute.rs index bd617df5..71a6c0a1 100644 --- a/crates/weaver_resolver/src/attribute.rs +++ b/crates/weaver_resolver/src/attribute.rs @@ -82,18 +82,22 @@ impl AttributeCatalog { stability, deprecated, prefix, + rename, } => { let name; let root_attr = self.root_attributes.get(r#ref); if let Some(root_attr) = root_attr { let mut attr_lineage = AttributeLineage::new(&root_attr.group_id); - if *prefix { + if let Some(rename) = rename { + // if there is a rename we need to update the name + name = rename.clone(); + } else if *prefix { // depending on the prefix we either create embedded attribute or normal reference name = format!("{}.{}", group_prefix, r#ref); } else { name = r#ref.clone(); - } + } // Create a fully resolved attribute from an attribute spec // (ref) and override the root attribute with the new diff --git a/crates/weaver_resolver/src/registry.rs b/crates/weaver_resolver/src/registry.rs index fa7c6241..0591c816 100644 --- a/crates/weaver_resolver/src/registry.rs +++ b/crates/weaver_resolver/src/registry.rs @@ -618,6 +618,7 @@ fn resolve_inheritance_attr( stability, deprecated, prefix, + .. } => { match parent_attr { AttributeSpec::Ref { @@ -648,6 +649,7 @@ fn resolve_inheritance_attr( stability: lineage.stability(stability, parent_stability), deprecated: lineage.deprecated(deprecated, parent_deprecated), prefix: lineage.prefix(prefix, parent_prefix), + rename: None, } } AttributeSpec::Id { diff --git a/crates/weaver_semconv/src/attribute.rs b/crates/weaver_semconv/src/attribute.rs index 83dfe7c3..6bebb0eb 100644 --- a/crates/weaver_semconv/src/attribute.rs +++ b/crates/weaver_semconv/src/attribute.rs @@ -75,6 +75,10 @@ pub enum AttributeSpec { #[serde(default)] #[serde(skip_serializing_if = "<&bool>::not")] prefix: bool, + /// Specifies the rename of the attribute. + #[serde(skip_serializing_if = "Option::is_none")] + rename: Option, + }, /// Attribute definition. Id { @@ -786,6 +790,7 @@ mod tests { stability: Some(Stability::Stable), deprecated: Some("deprecated".to_owned()), prefix: false, + rename: None, }; assert_eq!(attr.id(), "ref"); assert_eq!(attr.brief(), "brief");