opentelemetry-java/buildscripts/semantic-convention/templates/SemanticAttributes.java.j2

119 lines
3.6 KiB
Django/Jinja

/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
{%- macro to_java_return_type(type) -%}
{%- if type == "string" -%}
String
{%- elif type == "string[]" -%}
List<String>
{%- elif type == "boolean" -%}
boolean
{%- elif type == "number" -%}
long
{%- else -%}
{{type}}
{%- endif -%}
{%- endmacro %}
{%- macro to_java_key_type(type) -%}
{%- if type == "string" -%}
stringKey
{%- elif type == "string[]" -%}
stringArrayKey
{%- elif type == "boolean" -%}
booleanKey
{%- elif type == "number" -%}
longKey
{%- else -%}
{{lowerFirst(type)}}Key
{%- endif -%}
{%- endmacro %}
{%- macro print_value(type, value) -%}
{{ "\"" if type == "String"}}{{value}}{{ "\"" if type == "String"}}
{%- endmacro %}
{%- macro upFirst(text) -%}
{{ text[0]|upper}}{{text[1:] }}
{%- endmacro %}
{%- macro lowerFirst(text) -%}
{{ text[0]|lower}}{{text[1:] }}
{%- endmacro %}
package {{pkg | trim}};
import static io.opentelemetry.api.common.AttributeKey.booleanKey;
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 io.opentelemetry.api.common.AttributeKey;
import java.util.List;
// DO NOT EDIT, this is an Auto-generated file from {{template}}
public final class {{class}} {
{%- for attribute in attributes | unique(attribute="fqn") %}
/**
* {% filter escape %}{{attribute.brief | to_doc_brief}}.{% endfilter %}
{%- if attribute.note %}
*
* Note: {% filter escape %}{{attribute.note | to_doc_brief}}.{% endfilter %}
{%- endif %}
{%- if attribute.deprecated %}
*
* @deprecated {{attribute.deprecated | to_doc_brief}}.
{%- endif %}
*/
{%- if attribute.deprecated %}
@Deprecated
{%- endif %}
public static final AttributeKey<{{upFirst(to_java_return_type(attribute.attr_type | string))}}> {{attribute.fqn | to_const_name}} = {{to_java_key_type(attribute.attr_type | string)}}("{{attribute.fqn}}");
{%- endfor %}
// Enum definitions
{%- for attribute in attributes | unique(attribute="fqn") %}
{%- if attribute.is_enum %}
{%- set class_name = attribute.fqn | to_camelcase(True) ~ "Values" %}
{%- set type = to_java_return_type(attribute.attr_type.enum_type) %}
{%- if attribute.attr_type.custom_values %}
public static final class {{class_name}} {
{%- for member in attribute.attr_type.members %}
/** {% filter escape %}{{member.brief | to_doc_brief}}.{% endfilter %} */
public static final {{ type }} {{ member.member_id | to_const_name }} = {{ print_value(type, member.value) }};
{%- endfor %}
private {{ class_name }}() {}
}
{%- else -%}
public enum {{class_name}} {
{%- for member in attribute.attr_type.members %}
/** {% filter escape %}{{member.brief | to_doc_brief}}.{% endfilter %} */
{{ member.member_id | to_const_name }}({{ print_value(type, member.value) }}),
{%- endfor %}
;
private final {{ type }} value;
{{class_name}}({{ type }} value) {
this.value = value;
}
public {{ type }} getValue() {
return value;
}
}
{% endif %}
{% endif %}
{%- endfor %}
// Manually defined and not YET in the YAML
/**
* The name of an event describing an exception.
*
* <p>Typically an event with that name should not be manually created. Instead {@link
* io.opentelemetry.api.trace.Span#recordException(Throwable)} should be used.
*/
public static final String EXCEPTION_EVENT_NAME = "exception";
private {{class}}() {}
}