Skip to content

Commit

Permalink
feat(forge): Use attribute registry namespace instead of group prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
lquerel committed Apr 30, 2024
1 parent 9483d63 commit e2e2df1
Show file tree
Hide file tree
Showing 13 changed files with 464 additions and 188 deletions.
20 changes: 20 additions & 0 deletions crates/weaver_forge/codegen_examples/expected_codegen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Semantic Conventions for Rust

# Usage

```rust
fn main() {
// Display the KeyValue of the attribute CLIENT_ADDRESS initialized with the value "145.34.23.56"
println!("{:?}", semconv::client::CLIENT_ADDRESS.value("145.34.23.56".into()));
// Display the key of the attribute CLIENT_ADDRESS
println!("{:?}", semconv::client::CLIENT_ADDRESS.key());

// Display the KeyValue of the attribute CLIENT_PORT initialized with the value 8080
println!("{:?}", semconv::client::CLIENT_PORT.value(8080));
// Display the key of the attribute CLIENT_PORT
println!("{:?}", semconv::client::CLIENT_PORT.key());

// Display the string representation of the enum variant HttpRequestMethod::Connect
println!("{}", semconv::http::HttpRequestMethod::Connect);
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
//! These attributes may be used to describe the client in a connection-based network interaction where there is one side that initiates the connection (the client is the side that initiates the connection). This covers all TCP network interactions since TCP is connection-based and one side initiates the connection (an exception is made for peer-to-peer communication over TCP where the "user-facing" surface of the protocol / API doesn't expose a clear notion of client and server). This also covers UDP network interactions where one side initiates the interaction, e.g. QUIC (HTTP/3) and DNS.
//! DO NOT EDIT, this is an Auto-generated file from templates/registry/rust/lib.rs.j2
use opentelemetry::StringValue;
use crate::AttributeKey;


/// Client address - domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name.
///
/// Notes:
/// When observed from the server side, and when communicating through an intermediary, `client.address` SHOULD represent the client address behind any intermediaries, for example proxies, if it's available.
pub const CLIENT_ADDRESS: AttributeKey<StringValue> = AttributeKey::new("client.address");
pub const CLIENT_ADDRESS: crate::AttributeKey<opentelemetry::StringValue> = crate::AttributeKey::new("client.address");




/// Client port number.
///
/// Notes:
/// When observed from the server side, and when communicating through an intermediary, `client.port` SHOULD represent the client port behind any intermediaries, for example proxies, if it's available.
pub const CLIENT_PORT: AttributeKey<i64> = AttributeKey::new("client.port");
pub const CLIENT_PORT: crate::AttributeKey<i64> = crate::AttributeKey::new("client.port");


Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
//! This document defines the shared attributes used to report a single exception associated with a span or log.
//! DO NOT EDIT, this is an Auto-generated file from templates/registry/rust/lib.rs.j2
use opentelemetry::StringValue;
use crate::AttributeKey;


/// The type of the exception (its fully-qualified class name, if applicable). The dynamic type of the exception should be preferred over the static type in languages that support it.
pub const EXCEPTION_TYPE: AttributeKey<StringValue> = AttributeKey::new("exception.type");
pub const EXCEPTION_TYPE: crate::AttributeKey<opentelemetry::StringValue> = crate::AttributeKey::new("exception.type");




/// The exception message.
pub const EXCEPTION_MESSAGE: AttributeKey<StringValue> = AttributeKey::new("exception.message");
pub const EXCEPTION_MESSAGE: crate::AttributeKey<opentelemetry::StringValue> = crate::AttributeKey::new("exception.message");




/// A stacktrace as a string in the natural representation for the language runtime. The representation is to be determined and documented by each language SIG.
pub const EXCEPTION_STACKTRACE: AttributeKey<StringValue> = AttributeKey::new("exception.stacktrace");
pub const EXCEPTION_STACKTRACE: crate::AttributeKey<opentelemetry::StringValue> = crate::AttributeKey::new("exception.stacktrace");




Expand All @@ -44,5 +44,6 @@ pub const EXCEPTION_STACKTRACE: AttributeKey<StringValue> = AttributeKey::new("e
/// even if the `exception.escaped` attribute was not set or set to false,
/// since the event might have been recorded at a time where it was not
/// clear whether the exception will escape.
pub const EXCEPTION_ESCAPED: AttributeKey<bool> = AttributeKey::new("exception.escaped");
pub const EXCEPTION_ESCAPED: crate::AttributeKey<bool> = crate::AttributeKey::new("exception.escaped");


93 changes: 78 additions & 15 deletions crates/weaver_forge/codegen_examples/expected_codegen/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
//! This document defines semantic convention attributes in the HTTP namespace.
//! DO NOT EDIT, this is an Auto-generated file from templates/registry/rust/lib.rs.j2
use opentelemetry::StringValue;
use crate::AttributeKey;


/// The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.
#[cfg(feature = "semconv_experimental")]
pub const HTTP_REQUEST_BODY_SIZE: AttributeKey<i64> = AttributeKey::new("http.request.body.size");
pub const HTTP_REQUEST_BODY_SIZE: crate::AttributeKey<i64> = crate::AttributeKey::new("http.request.body.size");



/// HTTP request headers, `<key>` being the normalized HTTP Header name (lowercase), the value being the header values.
Expand All @@ -21,7 +19,8 @@ pub const HTTP_REQUEST_BODY_SIZE: AttributeKey<i64> = AttributeKey::new("http.re
/// Instrumentations SHOULD require an explicit configuration of which headers are to be captured. Including all request headers can be a security risk - explicit configuration helps avoid leaking sensitive information.
/// The `User-Agent` header is already captured in the `user_agent.original` attribute. Users MAY explicitly configure instrumentations to capture them even though it is not recommended.
/// The attribute value MUST consist of either multiple header values as an array of strings or a single-item array containing a possibly comma-concatenated string, depending on the way the HTTP library provides access to headers.
pub const HTTP_REQUEST_HEADER: AttributeKey<Vec<String>> = AttributeKey::new("http.request.header");
pub const HTTP_REQUEST_HEADER: crate::AttributeKey<Vec<String>> = crate::AttributeKey::new("http.request.header");



/// HTTP request method.
Expand All @@ -41,7 +40,8 @@ pub const HTTP_REQUEST_HEADER: AttributeKey<Vec<String>> = AttributeKey::new("ht
/// HTTP method names are case-sensitive and `http.request.method` attribute value MUST match a known HTTP method name exactly.
/// Instrumentations for specific web frameworks that consider HTTP methods to be case insensitive, SHOULD populate a canonical equivalent.
/// Tracing instrumentations that do so, MUST also set `http.request.method_original` to the original value.
pub const HTTP_REQUEST_METHOD: AttributeKey<HttpRequestMethod> = AttributeKey::new("http.request.method");
pub const HTTP_REQUEST_METHOD: crate::AttributeKey<HttpRequestMethod> = crate::AttributeKey::new("http.request.method");



/// HTTP request method.
Expand Down Expand Up @@ -70,27 +70,61 @@ pub enum HttpRequestMethod {

}

impl HttpRequestMethod {
/// Returns the string representation of the [`HttpRequestMethod`].
pub fn as_str(&self) -> &'static str {
match self {
HttpRequestMethod::Connect => "CONNECT",
HttpRequestMethod::Delete => "DELETE",
HttpRequestMethod::Get => "GET",
HttpRequestMethod::Head => "HEAD",
HttpRequestMethod::Options => "OPTIONS",
HttpRequestMethod::Patch => "PATCH",
HttpRequestMethod::Post => "POST",
HttpRequestMethod::Put => "PUT",
HttpRequestMethod::Trace => "TRACE",
HttpRequestMethod::Other => "_OTHER",
// Without this default case, the match expression would not
// contain any variants if all variants are annotated with the
// 'semconv_experimental' feature and the feature is not enabled.
#[allow(unreachable_patterns)]
_ => unreachable!(),
}
}
}

impl core::fmt::Display for HttpRequestMethod {
/// Formats the value using the given formatter.
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}


/// Original HTTP method sent by the client in the request line.
pub const HTTP_REQUEST_METHOD_ORIGINAL: AttributeKey<StringValue> = AttributeKey::new("http.request.method_original");
pub const HTTP_REQUEST_METHOD_ORIGINAL: crate::AttributeKey<opentelemetry::StringValue> = crate::AttributeKey::new("http.request.method_original");




/// The ordinal number of request resending attempt (for any reason, including redirects).
///
/// Notes:
/// The resend count SHOULD be updated each time an HTTP request gets resent by the client, regardless of what was the cause of the resending (e.g. redirection, authorization failure, 503 Server Unavailable, network issues, or any other).
pub const HTTP_REQUEST_RESEND_COUNT: AttributeKey<i64> = AttributeKey::new("http.request.resend_count");
pub const HTTP_REQUEST_RESEND_COUNT: crate::AttributeKey<i64> = crate::AttributeKey::new("http.request.resend_count");



/// The total size of the request in bytes. This should be the total number of bytes sent over the wire, including the request line (HTTP/1.1), framing (HTTP/2 and HTTP/3), headers, and request body if any.
#[cfg(feature = "semconv_experimental")]
pub const HTTP_REQUEST_SIZE: AttributeKey<i64> = AttributeKey::new("http.request.size");
pub const HTTP_REQUEST_SIZE: crate::AttributeKey<i64> = crate::AttributeKey::new("http.request.size");



/// The size of the response payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.
#[cfg(feature = "semconv_experimental")]
pub const HTTP_RESPONSE_BODY_SIZE: AttributeKey<i64> = AttributeKey::new("http.response.body.size");
pub const HTTP_RESPONSE_BODY_SIZE: crate::AttributeKey<i64> = crate::AttributeKey::new("http.response.body.size");



/// HTTP response headers, `<key>` being the normalized HTTP Header name (lowercase), the value being the header values.
Expand All @@ -99,30 +133,35 @@ pub const HTTP_RESPONSE_BODY_SIZE: AttributeKey<i64> = AttributeKey::new("http.r
/// Instrumentations SHOULD require an explicit configuration of which headers are to be captured. Including all response headers can be a security risk - explicit configuration helps avoid leaking sensitive information.
/// Users MAY explicitly configure instrumentations to capture them even though it is not recommended.
/// The attribute value MUST consist of either multiple header values as an array of strings or a single-item array containing a possibly comma-concatenated string, depending on the way the HTTP library provides access to headers.
pub const HTTP_RESPONSE_HEADER: AttributeKey<Vec<String>> = AttributeKey::new("http.response.header");
pub const HTTP_RESPONSE_HEADER: crate::AttributeKey<Vec<String>> = crate::AttributeKey::new("http.response.header");



/// The total size of the response in bytes. This should be the total number of bytes sent over the wire, including the status line (HTTP/1.1), framing (HTTP/2 and HTTP/3), headers, and response body and trailers if any.
#[cfg(feature = "semconv_experimental")]
pub const HTTP_RESPONSE_SIZE: AttributeKey<i64> = AttributeKey::new("http.response.size");
pub const HTTP_RESPONSE_SIZE: crate::AttributeKey<i64> = crate::AttributeKey::new("http.response.size");



/// [HTTP response status code](https://tools.ietf.org/html/rfc7231#section-6).
pub const HTTP_RESPONSE_STATUS_CODE: AttributeKey<i64> = AttributeKey::new("http.response.status_code");
pub const HTTP_RESPONSE_STATUS_CODE: crate::AttributeKey<i64> = crate::AttributeKey::new("http.response.status_code");



/// The matched route, that is, the path template in the format used by the respective server framework.
///
/// Notes:
/// MUST NOT be populated when this is not supported by the HTTP server framework as the route attribute should have low-cardinality and the URI path can NOT substitute it.
/// SHOULD include the [application root](/docs/http/http-spans.md#http-server-definitions) if there is one.
pub const HTTP_ROUTE: AttributeKey<StringValue> = AttributeKey::new("http.route");
pub const HTTP_ROUTE: crate::AttributeKey<opentelemetry::StringValue> = crate::AttributeKey::new("http.route");




/// State of the HTTP connection in the HTTP connection pool.
#[cfg(feature = "semconv_experimental")]
pub const HTTP_CONNECTION_STATE: AttributeKey<HttpConnectionState> = AttributeKey::new("http.connection.state");
pub const HTTP_CONNECTION_STATE: crate::AttributeKey<HttpConnectionState> = crate::AttributeKey::new("http.connection.state");



/// State of the HTTP connection in the HTTP connection pool.
Expand All @@ -137,3 +176,27 @@ pub enum HttpConnectionState {

}

impl HttpConnectionState {
/// Returns the string representation of the [`HttpConnectionState`].
pub fn as_str(&self) -> &'static str {
match self {
#[cfg(feature = "semconv_experimental")]
HttpConnectionState::Active => "active",
#[cfg(feature = "semconv_experimental")]
HttpConnectionState::Idle => "idle",
// Without this default case, the match expression would not
// contain any variants if all variants are annotated with the
// 'semconv_experimental' feature and the feature is not enabled.
#[allow(unreachable_patterns)]
_ => unreachable!(),
}
}
}

impl core::fmt::Display for HttpConnectionState {
/// Formats the value using the given formatter.
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod exception;
/// This document defines semantic convention attributes in the HTTP namespace.
pub mod http;
/// These attributes may be used for any network related operation.
pub mod net;
pub mod network;

/// A typed attribute key.
pub struct AttributeKey<T> {
Expand Down
134 changes: 0 additions & 134 deletions crates/weaver_forge/codegen_examples/expected_codegen/net.rs

This file was deleted.

Loading

0 comments on commit e2e2df1

Please sign in to comment.