Skip to content
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

Define SemConv predefined JQ functions #246

Merged
merged 41 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
cb9cd58
feat(forge): Support hierarchical weaver config
lquerel Jul 6, 2024
b8faa77
feat(forge): Test override_with
lquerel Jul 8, 2024
da7b6c7
feat(forge): Implement better UX for templates and config.
lquerel Jul 10, 2024
b6bb5ef
chore(forge): Fix a unit test.
lquerel Jul 10, 2024
e818435
feat(forge): Support multiple paths to init a WeaverConfig with overr…
lquerel Jul 11, 2024
fdd51cc
feat(cli): Reintroduce target concept
lquerel Jul 11, 2024
ef59887
feat(cli): Introduce --config parameter in weaver registry generate
lquerel Jul 11, 2024
c55f85b
Merge branch 'main' into hierarchical-config
lquerel Jul 11, 2024
f9bf773
doc(forge): Document the organization and resolution of config files
lquerel Jul 11, 2024
d42a61a
doc(forge): Document the organization and resolution of config files
lquerel Jul 11, 2024
ec39d09
Merge branch 'main' into hierarchical-config
lquerel Jul 11, 2024
add9388
feat(forge): Improve WeaverConfig and TemplateEngine public APIs
lquerel Jul 15, 2024
0f44a4c
Merge remote-tracking branch 'origin/hierarchical-config' into hierar…
lquerel Jul 15, 2024
582516b
feat(forge): Remove FileContent from the public API
lquerel Jul 15, 2024
78d4f40
feat(forge): Create constants for Jinja syntax delimiters
lquerel Jul 15, 2024
399030b
Merge branch 'lquerel-hierarchical-config'
lquerel Jul 15, 2024
0f2d7c7
chore(forge): Remove unused filters function_name, struct_name, ...
lquerel Jul 16, 2024
d93a9c8
chore(build): Merge with main and bump weaver version
lquerel Jul 16, 2024
1e54041
chore(build): Merge with main and bump weaver version
lquerel Jul 16, 2024
35a405b
Merge branch 'main' of https://github.com/lquerel/otel-weaver
lquerel Jul 16, 2024
e5504cf
Merge remote-tracking branch 'upstream/main'
lquerel Jul 16, 2024
0749edd
Merge branch 'open-telemetry:main' into main
lquerel Jul 16, 2024
49197f6
Merge branch 'open-telemetry:main' into main
lquerel Jul 17, 2024
088cf19
feat(forge): Add predefined semconv JQ functions
lquerel Jul 17, 2024
cd08316
feat(forge): Add more predefined semconv JQ functions
lquerel Jul 17, 2024
73d464b
feat(forge): Use new JQ function in rust codegen example
lquerel Jul 17, 2024
4001a24
feat(forge): Define semconv functions
lquerel Jul 18, 2024
7aff7c0
feat(forge): Update documentation
lquerel Jul 18, 2024
321762e
feat(forge): Update documentation
lquerel Jul 18, 2024
4d3b747
Merge branch 'main' into semconv-jq-function
lquerel Jul 18, 2024
c344aa8
feat(forge): Introduce concept of JQ package to import JQ functions
lquerel Jul 18, 2024
ebae346
feat(forge): Simplify the Rust example with the new filters.
lquerel Jul 19, 2024
e8d4389
feat(forge): Update unit tests
lquerel Jul 19, 2024
97747f8
feat(forge): Enable whitespace control on the Rust example
lquerel Jul 20, 2024
726ecb7
feat(forge): Improve documentation intro
lquerel Jul 22, 2024
d3594a7
feat(forge): Improve documentation section Template Directory Structure
lquerel Jul 22, 2024
7d516c3
feat(forge): Improve documentation section Configuration file
lquerel Jul 22, 2024
58e0b7c
Merge branch 'main' into semconv-jq-function
lquerel Jul 22, 2024
f2dfaa4
Merge branch 'main' into semconv-jq-function
lquerel Jul 22, 2024
5dbcc11
feat(forge): Change namespace to root_namespace and improve docs
lquerel Jul 22, 2024
b8172b1
feat(forge): Fix renaming issue
lquerel Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 19 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions crates/weaver_codegen_test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use weaver_common::{in_memory, Logger};
use weaver_forge::config::{Params, WeaverConfig};
use weaver_forge::file_loader::FileSystemFileLoader;
use weaver_forge::registry::ResolvedRegistry;
use weaver_forge::{OutputDirective, TemplateEngine};
use weaver_forge::{OutputDirective, TemplateEngine, SEMCONV_JQ};
use weaver_resolver::SchemaResolver;
use weaver_semconv::path::RegistryPath;
use weaver_semconv::registry::SemConvRegistry;
Expand Down Expand Up @@ -53,7 +53,10 @@ fn main() {
.unwrap_or_else(|e| process_error(&logger, e));
let config = WeaverConfig::try_from_path("./templates/registry/rust")
.unwrap_or_else(|e| process_error(&logger, e));
let engine = TemplateEngine::new(config, loader, Params::default());
let mut engine = TemplateEngine::new(config, loader, Params::default());
engine
.import_jq_package(SEMCONV_JQ)
.unwrap_or_else(|e| process_error(&logger, e));
let template_registry = ResolvedRegistry::try_from_resolved_registry(
schema
.registry(REGISTRY_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
params:
attributes: true
metrics: false # With this alternate configuration, the metrics are disabled
registry_prefix: "registry."
exclude_deprecated: true
lmolkova marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
{%- macro comments(attribute, prefix) -%}
{%- if attribute.brief %}
{% if attribute.brief %}
{{ attribute.brief | comment_with_prefix(prefix ~ " ") }}
{%- endif %}
{%- if attribute.note %}
{% endif %}
{% if attribute.note %}
{{ prefix }}
{{ prefix }} Notes:
{{ attribute.note | comment_with_prefix(prefix ~ " ") }}
{%- endif %}
{%- if attribute.examples %}
{%- if attribute.examples is sequence %}
{% endif %}
{% if attribute.examples %}
{% if attribute.examples is sequence %}
{{ prefix }}
{{ prefix }} Examples:
{%- for example in attribute.examples %}
{% for example in attribute.examples %}
{{ example | comment_with_prefix(prefix ~ " - ") }}
{%- endfor %}
{%- else %}
{% endfor %}
{% else %}
{{ prefix }}
{{ prefix }} Example: {{ attribute.examples | trim }}
{%- endif %}
{%- endif %}
{%- endmacro %}
{% endif %}
{% endif %}
{% endmacro %}

{%- macro attributes_to_key_values(required_attributes, not_required_attributes) -%}
let mut attributes = vec![
{%- for attribute in required_attributes | attribute_sort %}
{%- if attribute is experimental %}
{% for attribute in required_attributes | attribute_sort %}
{% if attribute is experimental %}
#[cfg(feature = "semconv_experimental")]
{%- endif %}
{%- if attribute.type.members is defined %}
{% endif %}
{% if attribute.type.members is defined %}
crate::attributes::{{ attribute.name | attribute_namespace }}::{{ attribute.name | screaming_snake_case }}.value(&required_attributes.{{ attribute.name | snake_case }}),
{%- elif attribute.type == "string" %}
{% elif attribute.type == "string" %}
crate::attributes::{{ attribute.name | attribute_namespace }}::{{ attribute.name | screaming_snake_case }}.value(required_attributes.{{ attribute.name | snake_case }}.to_owned().into()),
{%- else %}
{% else %}
crate::attributes::{{ attribute.name | attribute_namespace }}::{{ attribute.name | screaming_snake_case }}.value(required_attributes.{{ attribute.name | snake_case }}),
{%- endif %}
{%- endfor %}
{% endif %}
{% endfor %}
];

if let Some(value) = &not_required_attributes {
{%- for attribute in not_required_attributes | attribute_sort %}
{%- if attribute is experimental %}
{% for attribute in not_required_attributes | attribute_sort %}
{% if attribute is experimental %}
#[cfg(feature = "semconv_experimental")]
{%- endif %}
{%- if attribute.type.members is defined %}
{% endif %}
{% if attribute.type.members is defined %}
if let Some({{ attribute.name | snake_case }}) = &value.{{ attribute.name | snake_case }} {
attributes.push(crate::attributes::{{ attribute.name | attribute_namespace }}::{{ attribute.name | screaming_snake_case }}.value({{ attribute.name | snake_case }}));
}
{%- elif attribute.type == "string" %}
{% elif attribute.type == "string" %}
if let Some({{ attribute.name | snake_case }}) = &value.{{ attribute.name | snake_case }} {
attributes.push(crate::attributes::{{ attribute.name | attribute_namespace }}::{{ attribute.name | screaming_snake_case }}.value({{ attribute.name | snake_case }}.to_owned().into()));
}
{%- else %}
{% else %}
if let Some({{ attribute.name | snake_case }}) = value.{{ attribute.name | snake_case }} {
attributes.push(crate::attributes::{{ attribute.name | attribute_namespace }}::{{ attribute.name | screaming_snake_case }}.value({{ attribute.name | snake_case }}));
}
{%- endif %}
{%- endfor %}
{% endif %}
{% endfor %}
}
{%- endmacro %}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{%- set file_name = ctx.id | attribute_registry_namespace | snake_case -%}
{%- set file_name = ctx.namespace | snake_case -%}
{{- template.set_file_name("attributes/" ~ file_name ~ ".rs") -}}
{%- import 'attribute_macros.j2' as attribute_macros -%}

Expand All @@ -7,42 +7,41 @@
* SPDX-License-Identifier: Apache-2.0
*/

{{ ctx.brief | comment_with_prefix("//! ") }}
{%- if ctx.note %}
//!
//! Notes:
{{ ctx.note | comment_with_prefix("//! ") }}
{%- endif %}
//! DO NOT EDIT, THIS FILE HAS BEEN GENERATED BY WEAVER

{%- for attribute in ctx.attributes | attribute_sort %}
{{ attribute_macros.comments(attribute, "///") }}
{%- if attribute is experimental %}
{% for attribute in ctx.attributes | attribute_sort %}
{{ attribute_macros.comments(attribute, "///") -}}
{% if attribute is experimental %}
#[cfg(feature = "semconv_experimental")]
{%- endif %}
{%- if attribute is deprecated %}
{% endif %}
{% if attribute is deprecated %}
#[deprecated(note="{{ attribute.deprecated }}")]
{%- endif %}
{%- if attribute.type.allow_custom_values is defined %}
{% endif %}
{% if attribute.type.allow_custom_values is defined %}
pub const {{ attribute.name | screaming_snake_case }}: crate::attributes::AttributeKey<{{ attribute.name | pascal_case }}> = crate::attributes::AttributeKey::new("{{ attribute.name }}");
{%- elif attribute.type == "string" %}
{% elif attribute.type == "string" %}
pub const {{ attribute.name | screaming_snake_case }}: crate::attributes::AttributeKey<opentelemetry::{{ attribute.type | map_text("rust_types") }}Value> = crate::attributes::AttributeKey::new("{{ attribute.name }}");
{%- else %}
{% else %}
pub const {{ attribute.name | screaming_snake_case }}: crate::attributes::AttributeKey<{{ attribute.type | map_text("rust_types") }}> = crate::attributes::AttributeKey::new("{{ attribute.name }}");
{%- endif %}
{%- if attribute.type.members is defined %}
{% endif %}

{% if attribute.brief %}{{ attribute.brief | comment_with_prefix("/// ") }}{%- endif %}
{% if attribute.type.members is defined %}
{% if attribute.brief %}
{{ attribute.brief | comment_with_prefix("/// ") }}
{% endif %}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum {{ attribute.name | pascal_case }} {
{%- for variant in attribute.type.members %}
{{ variant.brief | default("No brief") | comment_with_prefix(" /// ") }}
{%- if variant.note %}{{ variant.note | comment_with_prefix(" /// ") }}{% endif %}
{%- if variant is experimental %}
#[cfg(feature = "semconv_experimental")] {% endif %}
{% for variant in attribute.type.members %}
{{ variant.brief | default("No brief") | comment_with_prefix("/// ") }}
{% if variant.note %}
{{ variant.note | comment_with_prefix("/// ") }}
{% endif %}
{% if variant is experimental %}
#[cfg(feature = "semconv_experimental")]
{% endif %}
{{ variant.id | pascal_case }},
{%- endfor %}
{% endfor %}
/// This variant allows defining a custom entry in the enum.
_Custom(String),
}
Expand All @@ -52,11 +51,12 @@ impl {{ attribute.name | pascal_case }} {
#[must_use]
pub fn as_str(&self) -> &str {
match self {
{%- for variant in attribute.type.members %}
{%- if variant is experimental %}
#[cfg(feature = "semconv_experimental")] {% endif %}
{% for variant in attribute.type.members %}
{% if variant is experimental %}
#[cfg(feature = "semconv_experimental")]
{% endif %}
{{ attribute.name | pascal_case }}::{{ variant.id | pascal_case }} => "{{ variant.value }}",
{%- endfor %}
{% endfor %}
{{ attribute.name | pascal_case }}::_Custom(v) => v.as_str(),
// Without this default case, the match expression would not
// contain any variants if all variants are annotated with the
Expand All @@ -81,5 +81,6 @@ impl crate::attributes::AttributeKey<{{ attribute.name | pascal_case }}> {
opentelemetry::KeyValue::new(self.key.clone(), v.to_string())
}
}
{%- endif %}
{%- endfor %}

{% endif %}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use opentelemetry::{Key, KeyValue, StringValue};

pub const ATTRIBUTES_PARAM: bool = {{ params.attributes }};

{% for group in ctx %}
/// Attributes for the `{{ group.id | attribute_registry_namespace }}` namespace.
pub mod {{ group.id | attribute_registry_namespace | snake_case }};
{%- endfor %}
{% for attributes_namespace in ctx %}
/// Attributes for the `{{ attributes_namespace.namespace }}` namespace.
pub mod {{ attributes_namespace.namespace | snake_case }};
{% endfor %}

/// A typed attribute key.
pub struct AttributeKey<T> {
Expand Down
Loading
Loading