-
Notifications
You must be signed in to change notification settings - Fork 526
Use weaver for semantic convention codegen #2098
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
Changes from all commits
5583e3e
5413e78
2661464
63eb57a
03178a1
8211cb8
ce8dcaa
fdbb100
209c775
2b300bb
19aa24f
a2a55c0
731ec69
c6af804
62c12ce
672b66a
6beacd0
441df1f
7b3c044
4970ee9
13f1dbd
d3a3ba6
6f9a59c
23c47f6
664678d
e31d4eb
ff9b3e9
a032fbc
9cb825b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ CRATE_DIR="${SCRIPT_DIR}/../" | |
|
||
# freeze the spec version and generator version to make generation reproducible | ||
SPEC_VERSION=1.27.0 | ||
SEMCOVGEN_VERSION=0.25.0 | ||
WEAVER_VERSION=v0.10.0 | ||
|
||
cd "$CRATE_DIR" | ||
|
||
|
@@ -20,54 +20,24 @@ git fetch origin "v$SPEC_VERSION" | |
git reset --hard FETCH_HEAD | ||
cd "$CRATE_DIR" | ||
|
||
docker run --rm \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only need to call Weaver once, as the |
||
-v "${CRATE_DIR}/semantic-conventions/model:/source" \ | ||
-v "${CRATE_DIR}/scripts/templates:/templates" \ | ||
-v "${CRATE_DIR}/src:/output" \ | ||
otel/semconvgen:$SEMCOVGEN_VERSION \ | ||
-f /source code \ | ||
--template /templates/semantic_attributes.rs.j2 \ | ||
--output /output/attribute.rs \ | ||
--parameters conventions=attribute | ||
|
||
docker run --rm \ | ||
-v "${CRATE_DIR}/semantic-conventions/model:/source" \ | ||
-v "${CRATE_DIR}/scripts/templates:/templates" \ | ||
-v "${CRATE_DIR}/src:/output" \ | ||
otel/semconvgen:$SEMCOVGEN_VERSION \ | ||
--only span,event \ | ||
-f /source code \ | ||
--template /templates/semantic_attributes.rs.j2 \ | ||
--output /output/trace.rs \ | ||
--parameters conventions=trace | ||
|
||
docker run --rm \ | ||
-v "${CRATE_DIR}/semantic-conventions/model:/source" \ | ||
-v "${CRATE_DIR}/scripts/templates:/templates" \ | ||
-v "${CRATE_DIR}/src:/output" \ | ||
otel/semconvgen:$SEMCOVGEN_VERSION \ | ||
--only resource \ | ||
-f /source code \ | ||
--template /templates/semantic_attributes.rs.j2 \ | ||
--output /output/resource.rs \ | ||
--parameters conventions=resource | ||
|
||
docker run --rm \ | ||
-v "${CRATE_DIR}/semantic-conventions/model:/source" \ | ||
-v "${CRATE_DIR}/scripts/templates:/templates" \ | ||
-v "${CRATE_DIR}/src:/output" \ | ||
otel/semconvgen:$SEMCOVGEN_VERSION \ | ||
-f /source code \ | ||
--template /templates/semantic_metrics.rs.j2 \ | ||
--output /output/metric.rs | ||
|
||
SED=(sed -i) | ||
if [[ "$(uname)" = "Darwin" ]]; then | ||
SED=(sed -i "") | ||
fi | ||
|
||
# Keep `SCHEMA_URL` key in sync with spec version | ||
"${SED[@]}" "s/\(opentelemetry.io\/schemas\/\)[^\"]*\"/\1$SPEC_VERSION\"/" src/lib.rs | ||
"${SED[@]}" "s/\(opentelemetry.io\/schemas\/\)[^\"]*\"/\1$SPEC_VERSION\"/" scripts/templates/registry/rust/weaver.yaml | ||
|
||
docker run --rm \ | ||
--mount type=bind,source=$CRATE_DIR/semantic-conventions/model,target=/home/weaver/source,readonly \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For another review: This binding method seems to be incompatible with SELinux systems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there are advantages. For context, I’ve copied the relevant change log entry below. (#322, #312,
|
||
--mount type=bind,source=$CRATE_DIR/scripts/templates,target=/home/weaver/templates,readonly \ | ||
--mount type=bind,source=$CRATE_DIR/src,target=/home/weaver/target \ | ||
otel/weaver:$WEAVER_VERSION \ | ||
registry generate \ | ||
--registry=/home/weaver/source \ | ||
--templates=/home/weaver/templates \ | ||
rust \ | ||
/home/weaver/target/ | ||
|
||
# handle doc generation failures | ||
"${SED[@]}" 's/\[2\]\.$//' src/attribute.rs # remove trailing [2] from few of the doc comments | ||
|
This file was deleted.
This file was deleted.
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 | ||
TommyCpp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
//! # 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 %} |
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 }}"; |
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 %} |
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 %} |
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 %} |
Uh oh!
There was an error while loading. Please reload this page.