-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use weaver for semantic convention codegen (#2098)
Co-authored-by: Zhongyang Wu <[email protected]> Co-authored-by: Lalit Kumar Bhasin <[email protected]>
- Loading branch information
1 parent
0f15d21
commit 161929d
Showing
18 changed files
with
4,139 additions
and
1,508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
opentelemetry-semantic-conventions/scripts/templates/header_attribute.rs
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
opentelemetry-semantic-conventions/scripts/templates/header_metric.rs
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
opentelemetry-semantic-conventions/scripts/templates/registry/rust/attribute.rs.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{%- import 'macros.j2' as attr_macros -%} | ||
// DO NOT EDIT, this is an auto-generated file | ||
// | ||
// If you want to update the file: | ||
// - Edit the template at scripts/templates/registry/rust/attributes.rs.j2 | ||
// - Run the script at scripts/generate-consts-from-spec.sh | ||
|
||
//! # Semantic Attributes | ||
//! | ||
//! The entire set of semantic attributes (or [conventions](https://opentelemetry.io/docs/concepts/semantic-conventions/)) defined by the project. The resource, metric, and trace modules reference these attributes. | ||
|
||
{% for root_ns in ctx %} | ||
{% for attr in root_ns.attributes | rejectattr("name", "in", params.excluded_attributes) %} | ||
{{ [attr.brief, concat_if("\n\n## Notes\n\n", attr.note), attr_macros.examples(attr)] | comment }} | ||
{% if attr is experimental %} | ||
#[cfg(feature = "semconv_experimental")] | ||
{% endif %} | ||
{% if attr is deprecated %} | ||
#[deprecated(note="{{ attr.deprecated.strip(" \n\"") }}")] | ||
{% endif %} | ||
pub const {{ attr.name | screaming_snake_case }}: &str = "{{ attr.name }}"; | ||
|
||
{% endfor %} | ||
{% endfor %} |
25 changes: 25 additions & 0 deletions
25
opentelemetry-semantic-conventions/scripts/templates/registry/rust/lib.rs.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! OpenTelemetry semantic conventions are agreed standardized naming patterns | ||
//! for OpenTelemetry things. This crate aims to be the centralized place to | ||
//! interact with these conventions. | ||
#![warn( | ||
future_incompatible, | ||
missing_debug_implementations, | ||
missing_docs, | ||
nonstandard_style, | ||
rust_2018_idioms, | ||
unreachable_pub, | ||
unused | ||
)] | ||
#![cfg_attr(test, deny(warnings))] | ||
#![doc( | ||
html_logo_url = "https://raw.githubusercontent.com/open-telemetry/opentelemetry-rust/main/assets/logo.svg" | ||
)] | ||
|
||
pub mod attribute; | ||
pub mod metric; | ||
pub mod resource; | ||
pub mod trace; | ||
|
||
/// The schema URL that matches the version of the semantic conventions that | ||
/// this crate defines. | ||
pub const SCHEMA_URL: &str = "{{ params.schema_url }}"; |
13 changes: 13 additions & 0 deletions
13
opentelemetry-semantic-conventions/scripts/templates/registry/rust/macros.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{%- macro examples(entity) -%} | ||
{% if entity.examples %} | ||
# Examples | ||
|
||
{% if entity.examples is sequence %} | ||
{% for example in entity.examples %} | ||
- `{{ example | pprint }}` | ||
{% endfor %} | ||
{% else %} | ||
- `{{ entity.examples | pprint }}` | ||
{% endif %} | ||
{% endif %} | ||
{% endmacro %} |
79 changes: 79 additions & 0 deletions
79
opentelemetry-semantic-conventions/scripts/templates/registry/rust/metric.rs.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{%- import 'macros.j2' as metric_macros -%} | ||
// DO NOT EDIT, this is an auto-generated file | ||
// | ||
// If you want to update the file: | ||
// - Edit the template at scripts/templates/registry/rust/metric.rs.j2 | ||
// - Run the script at scripts/generate-consts-from-spec.sh | ||
|
||
//! # Metric Semantic Conventions | ||
//! | ||
//! The [metric semantic conventions] define a set of standardized attributes to | ||
//! be used in `Meter`s. | ||
//! | ||
//! [metric semantic conventions]: https://github.com/open-telemetry/semantic-conventions/tree/main/model/metric | ||
//! | ||
//! ## Usage | ||
//! | ||
//! ```rust | ||
//! use opentelemetry::{global, KeyValue}; | ||
//! use opentelemetry_semantic_conventions as semconv; | ||
//! | ||
//! // Assumes we already have an initialized `MeterProvider` | ||
//! // See: https://github.com/open-telemetry/opentelemetry-rust/blob/main/examples/metrics-basic/src/main.rs | ||
//! // for an example | ||
//! let meter = global::meter("mylibraryname"); | ||
//! let histogram = meter | ||
//! .u64_histogram(semconv::metric::HTTP_SERVER_REQUEST_DURATION) | ||
//! .with_unit("By") | ||
//! .with_description("Duration of HTTP server requests.") | ||
//! .init(); | ||
//! ``` | ||
|
||
{% for root_ns in ctx %} | ||
{% for metric in root_ns.metrics %} | ||
{{ ["## Description\n\n", metric.brief, concat_if("\n\n## Notes\n\n", metric.note), metric_macros.examples(metric)] | comment }} | ||
/// ## Metadata | ||
/// | | | | ||
/// |:-|:- | ||
/// | Instrument: | `{{ metric.instrument }}` | | ||
/// | Unit: | `{{ metric.unit }}` | | ||
/// | Status: | `{{ metric.stability | capitalize }}` | | ||
{% if metric.attributes %} | ||
/// | ||
/// ## Attributes | ||
/// | Name | Requirement | | ||
/// |:-|:- | | ||
{% endif %} | ||
{% for attribute in metric.attributes | rejectattr("name", "in", params.excluded_attributes) | sort(attribute="name") %} | ||
{% if attribute.requirement_level %} | ||
{% if attribute.requirement_level.conditionally_required %} | ||
{% set req_level = "Conditionally_required" %} | ||
{% set req_message = attribute.requirement_level.conditionally_required %} | ||
{% else %} | ||
{% set req_level = (attribute.requirement_level | capitalize) %} | ||
{% set req_message = attribute.requirement_level_msg %} | ||
{% endif %} | ||
{% else %} | ||
{% set req_level = "Unspecified" %} | ||
{% set req_message = '' %} | ||
{% endif %} | ||
/// | [`crate::attribute::{{ attribute.name | screaming_snake_case }}`] | `{{ req_level }}`{{ (': ' + req_message if req_message else '') }} | ||
{% endfor %} | ||
{% if metric.examples %} | ||
/// | ||
/// ## Examples | ||
/// | ||
{% for example in metric.examples %} | ||
/// - `{{ example }}` | ||
{% endfor %} | ||
{% endif %} | ||
{% if metric is experimental %} | ||
#[cfg(feature = "semconv_experimental")] | ||
{% endif %} | ||
{% if metric is deprecated %} | ||
#[deprecated(note="{{ metric.deprecated.strip(" \n\"") }}")] | ||
{% endif %} | ||
pub const {{ metric.metric_name | screaming_snake_case }}: &str = "{{ metric.metric_name }}"; | ||
|
||
{% endfor %} | ||
{% endfor %} |
60 changes: 39 additions & 21 deletions
60
...ions/scripts/templates/header_resource.rs → ...ts/templates/registry/rust/resource.rs.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
//! # Resource Semantic Conventions | ||
//! | ||
//! The [resource semantic conventions] define a set of standardized attributes | ||
//! to be used in `Resource`s. | ||
//! | ||
//! [resource semantic conventions]: https://github.com/open-telemetry/semantic-conventions/tree/main/model/resource | ||
//! | ||
//! ## Usage | ||
//! | ||
//! ```rust | ||
//! use opentelemetry::KeyValue; | ||
//! use opentelemetry_sdk::{trace::{config, TracerProvider}, Resource}; | ||
//! use opentelemetry_semantic_conventions as semconv; | ||
//! | ||
//! let _tracer = TracerProvider::builder() | ||
//! .with_config(config().with_resource(Resource::new(vec![ | ||
//! KeyValue::new(semconv::resource::SERVICE_NAME, "my-service"), | ||
//! KeyValue::new(semconv::resource::SERVICE_NAMESPACE, "my-namespace"), | ||
//! ]))) | ||
//! .build(); | ||
//! ``` | ||
{%- import 'macros.j2' as attr_macros -%} | ||
// DO NOT EDIT, this is an auto-generated file | ||
// | ||
// If you want to update the file: | ||
// - Edit the template at scripts/templates/registry/rust/resource.rs.j2 | ||
// - Run the script at scripts/generate-consts-from-spec.sh | ||
|
||
//! # Resource Semantic Conventions | ||
//! | ||
//! The [resource semantic conventions] define a set of standardized attributes | ||
//! to be used in `Resource`s. | ||
//! | ||
//! [resource semantic conventions]: https://github.com/open-telemetry/semantic-conventions/tree/main/model/resource | ||
//! | ||
//! ## Usage | ||
//! | ||
//! ```rust | ||
//! use opentelemetry::KeyValue; | ||
//! use opentelemetry_sdk::{trace::{config, TracerProvider}, Resource}; | ||
//! use opentelemetry_semantic_conventions as semconv; | ||
//! | ||
//! let _tracer = TracerProvider::builder() | ||
//! .with_config(config().with_resource(Resource::new(vec![ | ||
//! KeyValue::new(semconv::resource::SERVICE_NAME, "my-service"), | ||
//! KeyValue::new(semconv::resource::SERVICE_NAMESPACE, "my-namespace"), | ||
//! ]))) | ||
//! .build(); | ||
//! ``` | ||
|
||
{% for attr in ctx | rejectattr("name", "in", params.excluded_attributes) %} | ||
{% if attr is experimental %} | ||
#[cfg(feature = "semconv_experimental")] | ||
{% endif %} | ||
{% if attr is deprecated %} | ||
#[allow(deprecated)] | ||
{% endif %} | ||
pub use crate::attribute::{{ attr.name | screaming_snake_case }}; | ||
|
||
{% endfor %} |
Oops, something went wrong.