config: generate model code from json schema#4879
config: generate model code from json schema#4879codeboten wants to merge 20 commits intoopen-telemetry:mainfrom
Conversation
Proposing that the first step towards implementing OpenTelemetry Configuration is to produce the model code from the json schema. I did a quick search for tools available to do this and came across datamodel-codegen which seems to do what i expected. Will open following pull requests (in draft) to use this model code, i just want to keep these as clearly separated as possible to make reviewing them easier. Signed-off-by: alex boten <223565+codeboten@users.noreply.github.com>
pyproject.toml
Outdated
| formatters = ["ruff-format", "ruff-check"] | ||
| use-standard-collections = true | ||
| use-schema-description = true | ||
| use-title-as-name = true |
There was a problem hiding this comment.
| use-title-as-name = true | |
| use-title-as-name = true | |
| use-union-operator = true |
Does this make a difference? It should be the default but the pipe is not used for optionals
There was a problem hiding this comment.
I tried this but Python 3.9 doesn't support | and with use-union-operator set we'd generate something like
AlwaysOffSampler: TypeAlias = dict[str, Any] | Nonewith it disabled, we generate which works in 3.9
AlwaysOffSampler: TypeAlias = Optional[dict[str, Any]]I also updated the target-python-version to 3.10 as datamodel-codegen's validation wants 3.10+.
There was a problem hiding this comment.
We have from __future__ import annotations for being able to use the | on older pythons.
… into codeboten/generate-config-model-from-schema
|
I'm helping pick this up from @codeboten - I've opened the following PR to their branch that fixes the codegeneration tooling and also sets the use-union-operator option @xrmx suggested: |
…el-from-schema fix code-generation command and regenerate models
…el-from-schema.2 Fix lint errors and update uv.lock file
Signed-off-by: alex boten <223565+codeboten@users.noreply.github.com>
|
I've been reviewing the CI failures and I don't think they are related to the changes in this PR.
If you think any of the changes are related, let me know. Thanks. cc @open-telemetry/python-approvers @open-telemetry/python-maintainers |
… into codeboten/generate-config-model-from-schema
datamodel-codegen section was inserted between [tool.pyright] and its include/exclude config, causing pyright to check entire repo (599 files) instead of just included paths. Moved datamodel-codegen section after pyright config.
|
I found the problem with the CI type checks, I had the new tool definition under the wrong section. It's fixed now. cc @open-telemetry/python-approvers |
|
PS the check-links error seems to be transient. The most recent failure is referencing (#3038) which is a valid link. I don't have the ability to re-run, could someone do that for me? |
… into codeboten/generate-config-model-from-schema
Pyright doesn't recognize that pipe operators are valid with from __future__ import annotations on Python 3.9.
Testing if dev dependency updates in uv.lock are causing contrib test failures. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Hmm, the contrib CI failures are related to the uv.lock updates. Looking into this now. |
|
Okay, fixed - I think maybe something for weird after merging main into this branch. Reverting and regenerating the uv.lock seems to have fixed it 🎉 |
Description
Proposing that the first step towards implementing OpenTelemetry Configuration is to produce the model code from the json schema. I did a quick search for tools available to do this and came across datamodel-codegen which seems to do what i expected.
Will open following pull requests (in draft) to use this model code, i just want to keep these as clearly separated as possible to make reviewing them easier.
Related to #3631
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
This PR is just code generation, no tests have been added just yet
Checklist: