-
Notifications
You must be signed in to change notification settings - Fork 20
/
SemanticAttributes.java.j2
127 lines (115 loc) · 4.97 KB
/
SemanticAttributes.java.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{%- macro to_java_return_type(type) -%}
{%- if type == "string" -%}
String
{%- elif type == "string[]" -%}
List<String>
{%- elif type == "boolean" -%}
boolean
{%- elif type == "int" -%}
long
{%- elif type == "double" -%}
double
{%- else -%}
{{type}}
{%- endif -%}
{%- endmacro %}
{%- macro to_java_key_type(type) -%}
{%- if type == "string" -%}
stringKey
{%- elif type == "string[]" -%}
stringArrayKey
{%- elif type == "boolean" -%}
booleanKey
{%- elif type == "int" -%}
longKey
{%- elif type == "double" -%}
doubleKey
{%- else -%}
{{type | to_camelcase(False)}}Key
{%- endif -%}
{%- endmacro %}
{%- macro stable_class_ref(const_name, separator) -%}
{{stablePkg}}.{{ root_namespace | to_camelcase(True) }}Attributes{{separator}}{{const_name}}
{%- endmacro %}
{%- if filter != 'any' %}
{%- set filtered_attributes = attributes_and_templates | select(filter) | list %}
{%- else %}
{%- set filtered_attributes = attributes_and_templates | list %}
{%- endif %}
{%- set filtered_enums = filtered_attributes | selectattr('is_enum', 'equalto', true) | list %}
{%- set excluded_namespaces_list = excluded_namespaces.replace("\"", "").split(' ') %}
{%- if root_namespace not in excluded_namespaces_list and filtered_attributes | count > 0 %}
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package {{pkg | trim}};
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{{template}}
@SuppressWarnings("unused")
public final class {{ root_namespace | to_camelcase(True) }}{{ classPrefix }}Attributes {
{%- for attribute in filtered_attributes %}
{% set attribute_const_name = attribute.fqn | to_const_name -%}
/**
* {{attribute.brief | render_markdown(code="{{@code {0}}}", paragraph="{0}")}}
{%- if attribute.note %}
*
* <p>Notes:
{# NOTE: replace("> ", "") removes the following problematic characters which produce mangled javadoc: #}
{# https://github.com/open-telemetry/semantic-conventions/blob/c83a10a9c33c18a769835e959200d0e24dc708fe/model/resource/k8s.yaml#L34-L38 #}
<ul> {{attribute.note | replace("> ", "") | render_markdown(code="{{@code {0}}}", paragraph="<li>{0}</li>", list="{0}")}} </ul>
{%- endif %}
*
{%- if attribute | is_deprecated %}
* @deprecated {{attribute.brief | to_doc_brief}}.
{%- elif attribute | is_stable and stablePkg != "" %}
* @deprecated deprecated in favor of stable {@link {{stable_class_ref(attribute_const_name, '#')}}} attribute.
{%- endif %}
*/
{%- if attribute | is_deprecated or attribute | is_stable and stablePkg != "" %}
@Deprecated
{%- endif %}
{%- if attribute | is_template %}
public static final AttributeKeyTemplate<{{to_java_return_type(attribute.instantiated_type | string) | first_up}}> {{attribute_const_name}} = {{to_java_key_type(attribute.instantiated_type | string)}}Template("{{attribute.fqn}}");
{%- else %}
public static final AttributeKey<{{to_java_return_type(attribute.attr_type | string) | first_up}}> {{attribute_const_name}} = {{to_java_key_type(attribute.attr_type | string)}}("{{attribute.fqn}}");
{%- endif %}
{%- endfor %}
{%- if filtered_enums | count > 0 %}
// Enum definitions
{%- endif %}
{%- for enum_attribute in filtered_enums %}
{%- set class_name = enum_attribute.fqn | to_camelcase(True) ~ "Values" %}
{%- set type = to_java_return_type(enum_attribute.attr_type.enum_type) %}
/**
* Values for {@link #{{ enum_attribute.fqn | to_const_name }}}.
*
{%- if enum_attribute | is_deprecated %}
* @deprecated {{enum_attribute.brief | to_doc_brief}}.
{%- elif enum_attribute | is_stable and stablePkg != "" %}
* @deprecated deprecated in favor of stable {@link {{stable_class_ref(class_name, '.')}}} attribute.
{%- endif %}
*/
{%- if enum_attribute | is_deprecated or enum_attribute | is_stable and stablePkg != "" %}
@Deprecated
{%- endif %}
public static final class {{class_name}} {
{%- for member in enum_attribute.attr_type.members %}
/** {% filter escape %}{{member.brief | to_doc_brief}}.{% endfilter %} */
public static final {{ type }} {{ member.member_id | to_const_name }} = {{ enum_attribute | print_member_value(member) }};
{%- endfor %}
private {{ class_name }}() {}
}
{%- endfor %}
private {{ root_namespace | to_camelcase(True) }}{{ classPrefix }}Attributes() {}
}
{%- endif %}