-
Notifications
You must be signed in to change notification settings - Fork 19
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 (#70)
* Initial build generation to weaver. * Use weaver for codegen. * Remove deprecated incubating attributes. * Update generated code. * Add workaround for javadoc issue. * Update codegen. * Regenerate code. * Bump to latest weaver. * Regenerate classes/code. * Allow generated code to have different paragaph styles. * Add dots back into javadoc. * Codegen. * Add back-links from incubating to stable when things go stable. * Update generated incubating files. * Fix formatting. * Fix formatting. * Fix handling of template keys. * codegen * Update build.gradle.kts Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com> * Fix missing deprecated + experimental attributes. * Regenerate semconv. * Fix enum values. * regenerate code. * Fix deprecating stable enum values. * Regenerate code. * Fixes from review. * Fix bug where deprecated attributes were being added in future for-loops. * fix up deprecated attributes. * Add descriptions back to deprecated-for-stable incubating attributes. * Codegen * Add deprecation warnings back into enum value classes. * Fix deprecation on enum value classes. * Fix enum value links. * regenerate * Fix links from deprecated-for-stable enum classes. * regenerate. * Fix deprecated annotation. * regneerate. --------- Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com>
- Loading branch information
Showing
83 changed files
with
1,728 additions
and
1,581 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 was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
buildscripts/templates/registry/incubating_java/IncubatingSemanticAttributes.java.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,76 @@ | ||
{%- macro to_java_key_type(attribute) -%} | ||
{%- if attribute.type is template_type -%} | ||
{{ attribute.type | instantiated_type | map_text("java_template_key_type") }} | ||
{%- else -%} | ||
{{ attribute.type | instantiated_type | map_text("java_key_type") }} | ||
{%- endif %} | ||
{%- endmacro %} | ||
{%- macro to_java_key_factory(attribute) -%} | ||
{%- if attribute.type is template_type -%} | ||
{{ attribute.type | instantiated_type | map_text("java_template_key_factory") }} | ||
{%- else -%} | ||
{{ attribute.type | instantiated_type | map_text("java_key_factory") }} | ||
{%- endif %} | ||
{%- endmacro %} | ||
{%- set my_class_name = ctx.root_namespace | pascal_case ~ "IncubatingAttributes" -%} | ||
{%- set stable_class_name = ctx.root_namespace | pascal_case ~ "Attributes" -%} | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package io.opentelemetry.semconv.incubating; | ||
|
||
import static io.opentelemetry.api.common.AttributeKey.booleanKey; | ||
import static io.opentelemetry.api.common.AttributeKey.doubleKey; | ||
import static io.opentelemetry.api.common.AttributeKey.longKey; | ||
import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
import static io.opentelemetry.api.common.AttributeKey.stringArrayKey; | ||
|
||
import static io.opentelemetry.semconv.AttributeKeyTemplate.stringArrayKeyTemplate; | ||
import static io.opentelemetry.semconv.AttributeKeyTemplate.stringKeyTemplate; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.semconv.AttributeKeyTemplate; | ||
import java.util.List; | ||
|
||
// DO NOT EDIT, this is an Auto-generated file from buildscripts/templates/registry/incubating_java/IncubatingSemanticAttributes.java.j2 | ||
@SuppressWarnings("unused") | ||
public final class {{ my_class_name }} { | ||
{% for attribute in ctx.attributes | rejectattr("name", "in", ctx.excluded_attributes) %}{% if attribute is experimental %} | ||
{%- if attribute is deprecated %}{%- set deprecated_javadoc = "@deprecated " ~ attribute.deprecated -%} | ||
{%- else -%}{%- set deprecated_javadoc = "" -%} | ||
{%- endif -%} | ||
{{ [attribute.brief, concat_if("\n\nNotes:\n\n", attribute.note), deprecated_javadoc] | comment(indent=4) }} | ||
{% if attribute is deprecated %}@Deprecated{% endif %} public static final {{ to_java_key_type(attribute) | trim }} {{ attribute.name | screaming_snake_case }} = {{ to_java_key_factory(attribute) | trim }}("{{ attribute.name }}"); | ||
{% elif attribute is stable %} | ||
{%- set stable_class_link = "io.opentelemetry.semconv." ~ stable_class_name ~ "#" ~ (attribute.name | screaming_snake_case) -%} | ||
{{ [attribute.brief, concat_if("\n\nNotes:\n\n", attribute.note), "@deprecated deprecated in favor of stable {@link " ~ stable_class_link ~ "} attribute."] | comment(indent=4) }} | ||
@Deprecated public static final {{ to_java_key_type(attribute) | trim }} {{ attribute.name | screaming_snake_case }} = {{ to_java_key_factory(attribute) | trim }}("{{ attribute.name }}"); | ||
{% endif %} | ||
{% endfor %} | ||
// Enum definitions | ||
{% for attribute in ctx.attributes | select("enum") | rejectattr("name", "in", ctx.excluded_attributes) %} | ||
{%- if attribute is stable -%} | ||
{%- set stable_class_link = "io.opentelemetry.semconv." ~ stable_class_name ~ "." ~ (attribute.name | pascal_case) ~ "Values" -%} | ||
/** | ||
* Values for {@link #{{ attribute.name | screaming_snake_case }}}. | ||
* | ||
* @deprecated deprecated in favor of stable {@link {{stable_class_link}}}. | ||
*/ | ||
{%- elif attribute is deprecated -%} | ||
{{ ["Values for {@link #" ~ attribute.name | screaming_snake_case ~ "}", "@deprecated " ~ attribute.deprecated ] | comment }} | ||
{%- else -%} | ||
/** Values for {@link #{{ attribute.name | screaming_snake_case }}}. */ | ||
{%- endif -%} | ||
{% if attribute is stable or attribute is deprecated %}@Deprecated{% endif %} | ||
public static final class {{ attribute.name | pascal_case }}Values { | ||
{%- for member in attribute.type.members %} | ||
{{ [member.brief or (member.id ~ '.')] | comment(indent=4) }} | ||
public static final {{ attribute.type | instantiated_type | map_text("java_enum_type") }} {{ member.id | screaming_snake_case }} = {{ member.value | print_member_value }}; | ||
{%- endfor %} | ||
private {{ attribute.name | pascal_case }}Values() {} | ||
} | ||
{% endfor %} | ||
|
||
private {{ my_class_name }}() {} | ||
} |
77 changes: 77 additions & 0 deletions
77
buildscripts/templates/registry/incubating_java/weaver.yaml
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,77 @@ | ||
params: | ||
excluded_namespaces: ["ios", "aspnetcore", "signalr"] | ||
excluded_attributes: ["messaging.client_id"] | ||
comment_formats: | ||
javadoc: | ||
format: html | ||
header: "/**" | ||
prefix: " * " | ||
footer: " */" | ||
old_style_paragraph: true | ||
omit_closing_li: true | ||
inline_code_snippet: "{@code {{code}}}" | ||
block_code_snippet: "<pre>{@code {{code}}}</pre>" | ||
trim: true | ||
remove_trailing_dots: false | ||
default_comment_format: javadoc | ||
templates: | ||
- pattern: IncubatingSemanticAttributes.java.j2 | ||
filter: > | ||
semconv_grouped_attributes({ | ||
"exclude_root_namespace": $excluded_namespaces, | ||
"exclude_stability": [], | ||
"exclude_deprecated": false | ||
}) | map({ | ||
root_namespace: .root_namespace, | ||
attributes: .attributes, | ||
excluded_attributes: $excluded_attributes[] | ||
}) | ||
application_mode: each | ||
file_name: "{{ctx.root_namespace | pascal_case}}IncubatingAttributes.java" | ||
text_maps: | ||
java_enum_type: | ||
int: long | ||
double: double | ||
boolean: boolean | ||
string: String | ||
string[]: String[] | ||
int[]: long[] | ||
double[]: double[] | ||
boolean[]: boolean[] | ||
java_key_type: | ||
int: AttributeKey<Long> | ||
double: AttributeKey<Double> | ||
boolean: AttributeKey<Boolean> | ||
string: AttributeKey<String> | ||
string[]: AttributeKey<List<String>> | ||
int[]: AttributeKey<List<Long>> | ||
double[]: AttributeKey<List<Double>> | ||
boolean[]: AttributeKey<List<Boolean>> | ||
java_template_key_type: | ||
int: AttributeKeyTemplate<Long> | ||
double: AttributeKeyTemplate<Double> | ||
boolean: AttributeKeyTemplate<Boolean> | ||
string: AttributeKeyTemplate<String> | ||
string[]: AttributeKeyTemplate<List<String>> | ||
int[]: AttributeKeyTemplate<List<Long>> | ||
double[]: AttributeKeyTemplate<List<Double>> | ||
boolean[]: AttributeKeyTemplate<List<Boolean>> | ||
java_key_factory: | ||
int: longKey | ||
double: doubleKey | ||
boolean: booleanKey | ||
string: stringKey | ||
string[]: stringArrayKey | ||
int[]: longArrayKey | ||
double[]: doubleArrayKey | ||
boolean[]: booleanArrayKey | ||
java_template_key_factory: | ||
int: longKeyTemplate | ||
double: doubleKeyTemplate | ||
boolean: booleanKeyTemplate | ||
string: stringKeyTemplate | ||
string[]: stringArrayKeyTemplate | ||
int[]: longArrayKeyTemplate | ||
double[]: doubleArrayKeyTemplate | ||
boolean[]: booleanArrayKeyTemplate | ||
|
Oops, something went wrong.