-
Notifications
You must be signed in to change notification settings - Fork 27
Use weaver for semantic convention codegen #70
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
e3c0c9d
d5b2f7e
24c17e2
71d4714
e58b57b
0f7cf02
580363b
4bbb3bc
24ff612
5f2c973
b46f248
783a02b
316bbe7
d091b00
bce1947
5ed3405
17f7d37
28ee6e9
2f66d64
9a4b07b
e2f0c11
afa8d8c
9ed27c4
9695ec9
8756a13
5153d55
bd6d24f
09e7ddf
75c8c58
c15f9ec
e3ba4b8
4c03a4e
e3d06f0
f661cc4
4b66903
5cfefa3
d06cb00
475a041
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 |
---|---|---|
|
@@ -54,7 +54,7 @@ nexusPublishing { | |
} | ||
|
||
// start - define tasks to download, unzip, and generate from opentelemetry/semantic-conventions | ||
var generatorVersion = "0.24.0" | ||
var generatorVersion = "v0.9.1" | ||
val semanticConventionsRepoZip = "https://github.com/open-telemetry/semantic-conventions/archive/v${semanticConventionsVersion}.zip" | ||
val schemaUrl = "https://opentelemetry.io/schemas/$semanticConventionsVersion" | ||
|
||
|
@@ -83,35 +83,37 @@ fun generateTask(taskName: String, incubating: Boolean) { | |
standardOutput = System.out | ||
executable = "docker" | ||
|
||
var filter = if (incubating) "any" else "is_stable" | ||
var classPrefix = if (incubating) "Incubating" else "" | ||
var target = if (incubating) "incubating_java" else "java" | ||
val outputDir = if (incubating) "semconv-incubating/src/main/java/io/opentelemetry/semconv/incubating/" else "semconv/src/main/java/io/opentelemetry/semconv/" | ||
val packageNameArg = if (incubating) "io.opentelemetry.semconv.incubating" else "io.opentelemetry.semconv" | ||
val stablePackageNameArg = if (incubating) "io.opentelemetry.semconv" else "" | ||
|
||
setArgs(listOf( | ||
"run", | ||
val file_args = if (org.gradle.internal.os.OperatingSystem.current().isWindows()) | ||
// Don't need to worry about file system permissions in docker. | ||
listOf() | ||
else { | ||
// Make sure we run as local file user | ||
val unix = com.sun.security.auth.module.UnixSystem() | ||
val uid = unix.getUid() // $(id -u $USERNAME) | ||
val gid = unix.getGid() // $(id -g $USERNAME) | ||
listOf("-u", "$uid:$gid") | ||
} | ||
val weaver_args = listOf( | ||
"--rm", | ||
"-v", "$buildDir/semantic-conventions-${semanticConventionsVersion}/model:/source", | ||
"-v", "$projectDir/buildscripts/templates:/templates", | ||
"-v", "$projectDir/$outputDir:/output", | ||
"otel/semconvgen:$generatorVersion", | ||
"--yaml-root", "/source", | ||
"--continue-on-validation-errors", | ||
"code", | ||
"--template", "/templates/SemanticAttributes.java.j2", | ||
"--output", "/output/{{pascal_prefix}}${classPrefix}Attributes.java", | ||
"--file-per-group", "root_namespace", | ||
// Space delimited list of root namespaces to excluded (i.e. "foo bar") | ||
"-Dexcluded_namespaces=ios aspnetcore signalr", | ||
"-Dexcluded_attributes=messaging.client_id", | ||
"-Dfilter=${filter}", | ||
"-DclassPrefix=${classPrefix}", | ||
"-Dpkg=$packageNameArg", | ||
"-DstablePkg=$stablePackageNameArg")) | ||
"--platform=linux/x86_64", | ||
"--mount", "type=bind,source=$buildDir/semantic-conventions-${semanticConventionsVersion}/model,target=/home/weaver/source,readonly", | ||
"--mount", "type=bind,source=$projectDir/buildscripts/templates,target=/home/weaver/templates,readonly", | ||
"--mount", "type=bind,source=$projectDir/$outputDir,target=/home/weaver/target", | ||
"otel/weaver:$generatorVersion", | ||
"registry", "generate", | ||
"--registry=/home/weaver/source", | ||
"--templates=/home/weaver/templates", | ||
"$target", | ||
"/home/weaver/target/") | ||
|
||
setArgs(listOf("run") + file_args + weaver_args) | ||
} | ||
} | ||
|
||
// TODO - With weaver we can generate both of this in one go, but let's refactor smaller pieces at a time. | ||
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. Meh.. we already have a 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. It just means you have to duplicate the weaver config yaml in both places for now 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. Ah yeah would be good to DRY that up (in a followup) |
||
generateTask("generateStableSemanticAttributes", false) | ||
generateTask("generateIncubatingSemanticAttributes", true) | ||
|
||
|
This file was deleted.
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 }}() {} | ||
} |
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 | ||
|
Uh oh!
There was an error while loading. Please reload this page.