Skip to content

Commit 26fee09

Browse files
committed
Add generated modules that output const &str for tracing compatibility
1 parent ed97a1b commit 26fee09

File tree

7 files changed

+2576
-0
lines changed

7 files changed

+2576
-0
lines changed

opentelemetry-semantic-conventions/scripts/generate-consts-from-spec.sh

+23
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ docker run --rm \
3131
--output /output/trace.rs \
3232
--parameters conventions=trace
3333

34+
docker run --rm \
35+
-v "${CRATE_DIR}/semantic-conventions/model:/source" \
36+
-v "${CRATE_DIR}/scripts/templates:/templates" \
37+
-v "${CRATE_DIR}/src/semconv:/output" \
38+
otel/semconvgen:$SEMCOVGEN_VERSION \
39+
--only span,event,attribute_group,scope \
40+
-f /source code \
41+
--template /templates/semconv_semantic_attributes.rs.j2 \
42+
--output /output/trace.rs \
43+
--parameters conventions=trace
44+
3445
docker run --rm \
3546
-v "${CRATE_DIR}/semantic-conventions/model:/source" \
3647
-v "${CRATE_DIR}/scripts/templates:/templates" \
@@ -42,6 +53,18 @@ docker run --rm \
4253
--output /output/resource.rs \
4354
--parameters conventions=resource
4455

56+
docker run --rm \
57+
-v "${CRATE_DIR}/semantic-conventions/model:/source" \
58+
-v "${CRATE_DIR}/scripts/templates:/templates" \
59+
-v "${CRATE_DIR}/src/semconv:/output" \
60+
otel/semconvgen:$SEMCOVGEN_VERSION \
61+
--only resource \
62+
-f /source code \
63+
--template /templates/semconv_semantic_attributes.rs.j2 \
64+
--output /output/resource.rs \
65+
--parameters conventions=resource
66+
67+
4568
# Keep `SCHEMA_URL` key in sync with spec version
4669
sed -i "s/\(opentelemetry.io\/schemas\/\)[^\"]*\"/\1$SPEC_VERSION\"/" src/lib.rs
4770

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! # Resource Semantic Conventions
2+
//!
3+
//! The [resource semantic conventions] define a set of standardized attributes
4+
//! to be used in `Resource`s.
5+
//!
6+
//! [resource semantic conventions]: https://github.com/open-telemetry/semantic-conventions/tree/main/model/resource
7+
//!
8+
//! ## Usage
9+
//!
10+
//! ```
11+
//! use opentelemetry_semantic_conventions::semconv;
12+
//! use tracing::span;
13+
//!
14+
//! let span = span!(
15+
//! LEVEL::INFO,
16+
//! "handle_request",
17+
//! { semconv::resource::SERVICE_NAME = "my-service" },
18+
//! { semconv::resource::SERVICE_NAMESPACE = "my-namespace" }
19+
//! );
20+
//! ```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! # Trace Semantic Conventions
2+
//!
3+
//! The [trace semantic conventions] define a set of standardized attributes to
4+
//! be used in `Span`s.
5+
//!
6+
//! [trace semantic conventions]: https://github.com/open-telemetry/semantic-conventions/tree/main/model/trace
7+
//!
8+
//! ## Usage
9+
//!
10+
//! ```
11+
//! use opentelemetry_semantic_conventions::semconv;
12+
//! use tracing::span;
13+
//!
14+
//! let span = span!(
15+
//! LEVEL::INFO,
16+
//! "handle_request",
17+
//! { semconv::trace::NET_PEER_NAME = "example.org" },
18+
//! { semconv::trace::NET_PEER_PORT = 80 }
19+
//! );
20+
//! ```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// DO NOT EDIT, this is an auto-generated file
2+
//
3+
// If you want to update the file:
4+
// - Edit the template at scripts{{template}}
5+
// - Run the script at scripts/generate-consts-from-spec.sh
6+
7+
{% include 'semconv_header_' + conventions + '.rs' %}
8+
9+
{%- for attribute in attributes if attribute.is_local and not attribute.ref %}
10+
11+
/// {% filter escape %}{{attribute.brief | to_doc_brief}}.{% endfilter %}
12+
{%- if attribute.note %}
13+
///
14+
{%- for line in attribute.note.split('\n') %}
15+
/// {% filter escape %}{{line}}{% endfilter %}
16+
{%- endfor %}
17+
{%- endif %}
18+
{%- if attribute.examples %}
19+
///
20+
/// # Examples
21+
///
22+
{%- for example in attribute.examples %}
23+
/// - `{{example}}`
24+
{%- endfor %}
25+
{%- endif %}
26+
{%- if (attribute.stability | string()) == "StabilityLevel.DEPRECATED" %}
27+
#[deprecated]
28+
{%- endif %}
29+
pub const {{attribute.fqn | to_const_name}}: &str = "{{attribute.fqn}}";
30+
{%- endfor %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod resource;
2+
pub mod trace;

0 commit comments

Comments
 (0)