Skip to content

Conversation

@lquerel
Copy link
Contributor

@lquerel lquerel commented May 28, 2025

The deserialization of YAML semconv files using serde often results in low-quality error messages.

This PR:

  • Continues to use serde for deserialization.
  • Implements a fallback mechanism when serde detects errors:
    • Generates the JSON schema associated with the Rust SemConvSpec structure.
    • Converts the YAML file into an equivalent JSON representation.
    • Validates the JSON content obtained from the previous step using the generated JSON schema.
    • Exploits error messages returned by the validator (if any).
    • For each error, identifies its original location in the YAML file, extracts the description field from the JSON schema, and generates detailed error messages using the miette framework.

This PR also adds a new parameter to the command weaver registry json-schema to generate the JSON Schema for the semconv-group instead of the resolved registry.

weaver registry json-schema -j semconv-group

Example of error messages:

Screenshot 2025-05-28 at 4 21 02 PM

Closes: #746

@lquerel lquerel requested a review from a team as a code owner May 28, 2025 22:22
@lquerel lquerel self-assigned this May 28, 2025
@lquerel lquerel added enhancement New feature or request ux User experience enhancement labels May 28, 2025
@lquerel lquerel moved this to Next Release in OTel Weaver Project May 28, 2025
/// Supported group types are: `attribute_group`, `span`, `event`, `metric`, `entity`, `scope`.
/// Mandatory fields are: `id` and `brief`.
///
/// Note: The `resource` type is no longer used and is an alias for `entity`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I like how this forces better rust documentation too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I’ve improved a few comments, but we’ll certainly need to continue this effort throughout the objects representing all the semantic conventions.

// Force the `miette` context to 5 lines.
miette::set_hook(Box::new(|_| {
Box::new(
miette::MietteHandlerOpts::new()
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like just generally more investment in Miette would be valuable from what I see.

E.g. we should see if we can preserve spans further into resolution for error messages over time.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to say something similar I think - these errors are now better than the ones produced here: https://github.com/open-telemetry/weaver/blob/main/crates/weaver_semconv/src/group.rs#L107.

On the topic of using this machine generated json schema. The hand-crafted json schema: https://github.com/open-telemetry/weaver/blob/main/schemas/semconv.schema.json encodes more rules than can be expressed in the Rust structs/enum, I think. And it is aligned with --future as @lmolkova pointed out. So it would be a shame to lose this. An author with a modern text editor with the schema plugged in will be warned there and then that prefix is not part of the schema. With the machine generated version there won't be this warning until they pass it through weaver. This IMO creates a disconnected experience for the author where they'll have to go back and forth between command line and text to make their yaml compliant.

@lquerel lquerel merged commit 9810b28 into open-telemetry:main May 29, 2025
23 of 24 checks passed
@github-project-automation github-project-automation bot moved this from Next Release to Done in OTel Weaver Project May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ux User experience enhancement

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Provide actionable error messages for malformed semconv YAML files

3 participants