Skip to content
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

Allow adding a description when using opt_in requirement level #392

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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_resolved_schema/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl Catalog {
RequirementLevel::Basic(BasicRequirementLevelSpec::Optional) => "optional",
RequirementLevel::Recommended { .. } => "recommended",
RequirementLevel::ConditionallyRequired { .. } => "conditionally_required",
RequirementLevel::OptIn { .. } => "opt_in",
};
(requirement_level.to_owned(), 1)
})
Expand Down
4 changes: 2 additions & 2 deletions crates/weaver_semconv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ documentation.

For a formal definition of the allowed syntax, see the [build-tools JSON schema](https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/semconv.schema.json).

# Design Principles
## Design Principles

- Collect as many warnings and errors as possible. Do not stop at the first error; this approach helps the user fix
multiple issues at once.
- Rely on the Serde ecosystem for serialization and deserialization. This reliance simplifies support for multiple
formats such as YAML, JSON, etc.
- This crate is foundational for the OpenTelemetry Weaver project. Therefore, it is crucial to keep the API stable and
user-friendly. Maintaining a test coverage greater than 80% is important. Test as many as possible error cases/paths.
user-friendly. Maintaining a test coverage greater than 80% is important. Test as many as possible error cases/paths.
16 changes: 16 additions & 0 deletions crates/weaver_semconv/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,12 @@ pub enum RequirementLevel {
#[serde(rename = "recommended")]
text: String,
},
/// An opt in requirement level.
OptIn {
/// The description of the recommendation.
#[serde(rename = "opt_in")]
text: String,
},
}

/// Implements a human readable display for RequirementLevel.
Expand All @@ -590,6 +596,7 @@ impl Display for RequirementLevel {
write!(f, "conditionally required (condition: {})", text)
}
RequirementLevel::Recommended { text } => write!(f, "recommended ({})", text),
RequirementLevel::OptIn { text } => write!(f, "opt in ({})", text),
}
}
}
Expand Down Expand Up @@ -694,6 +701,15 @@ mod tests {
),
"recommended (recommendation)"
);
assert_eq!(
format!(
"{}",
RequirementLevel::OptIn {
text: "recommendation".to_owned()
}
),
"opt in (recommendation)"
);
}

#[test]
Expand Down
20 changes: 18 additions & 2 deletions schemas/semconv.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,23 @@
]
},
{
"const": "opt_in"
"oneOf": [
{
"const": "opt_in"
},
{
"type": "object",
"additionalProperties": false,
"required": [
"opt_in"
],
"properties": {
"opt_in": {
"type": "string"
}
}
}
]
}
]
},
Expand Down Expand Up @@ -428,7 +444,7 @@
},
"type": {
"$ref": "#/$defs/AttributeType"
}
}
}
},
"AttributeReference": {
Expand Down
Loading