...

Text file src/go.opentelemetry.io/otel/semconv/template.j2

Documentation: go.opentelemetry.io/otel/semconv

     1{%- macro keyval_method(type) -%}
     2  {%- if type == "string" -%}
     3    String
     4  {%- elif type == "string[]" -%}
     5    StringSlice
     6  {%- elif type == "int" -%}
     7    Int
     8  {%- elif type == "int[]" -%}
     9    IntSlice
    10  {%- elif type == "double" -%}
    11    Float64
    12  {%- elif type == "double[]" -%}
    13    Float64Slice
    14  {%- elif type == "boolean" -%}
    15    Bool
    16  {%- elif type == "boolean[]" -%}
    17    BoolSlice
    18  {%- endif -%}
    19{%- endmacro -%}
    20{%- macro to_go_attr_type(type, val) -%}
    21{{keyval_method(type)}}({% if type == "string" %}"{{val}}"{% else %}{{val}}{% endif %})
    22{%- endmacro -%}
    23{%- macro to_go_name(fqn) -%}
    24{{fqn | replace(".", " ") | replace("_", " ") | title | replace(" ", "")}}
    25{%- endmacro -%}
    26{%- macro it_reps(brief) -%}
    27It represents {% if brief[:2] == "A " or brief[:3] == "An " or brief[:4] == "The " -%}
    28  {{ brief[0]|lower }}{{ brief[1:] }}
    29{%- else -%}
    30  the {{ brief[0]|lower }}{{ brief[1:] }}
    31{%- endif -%}
    32{%- endmacro -%}
    33{%- macro keydoc(attr) -%}
    34{{ to_go_name(attr.fqn) }}Key is the attribute Key conforming to the "{{ attr.fqn }}" semantic conventions. {{ it_reps(attr.brief) }}
    35{%- endmacro -%}
    36{%- macro keydetails(attr) -%}
    37{%- if attr.attr_type is string %}
    38Type: {{ attr.attr_type }}
    39{%- else %}
    40Type: Enum
    41{%- endif %}
    42{%- if attr.requirement_level == RequirementLevel.REQUIRED %}
    43RequirementLevel: Required
    44{%- elif attr.requirement_level == RequirementLevel.CONDITIONALLY_REQUIRED %}
    45RequirementLevel: ConditionallyRequired
    46  {%- if attr.requirement_level_msg != "" %} ({{ attr.requirement_level_msg }}){%- endif %}
    47{%- elif attr.requirement_level == RequirementLevel.RECOMMENDED %}
    48RequirementLevel: Recommended
    49  {%- if attr.requirement_level_msg != "" %} ({{ attr.requirement_level_msg }}){%- endif %}
    50{%- else %}
    51RequirementLevel: Optional
    52{%- endif %}
    53{{ attr.stability |  replace("Level.", ": ") | capitalize }}
    54{%- if attr.deprecated != None %}
    55Deprecated: {{ attr.deprecated }}
    56{%- endif %}
    57{%- if attr.examples is iterable %}
    58Examples: {{ attr.examples | pprint | trim("[]")  }}
    59{%- endif %}
    60{%- if attr.note %}
    61Note: {{ attr.note }}
    62{%- endif %}
    63{%- endmacro -%}
    64{%- macro fndoc(attr) -%}
    65// {{ to_go_name(attr.fqn) }} returns an attribute KeyValue conforming to the "{{ attr.fqn }}" semantic conventions. {{ it_reps(attr.brief) }}
    66{%- endmacro -%}
    67{%- macro to_go_func(type, name) -%}
    68{%- if type == "string" -%}
    69func {{name}}(val string) attribute.KeyValue {
    70{%- elif type == "string[]" -%}
    71func {{name}}(val ...string) attribute.KeyValue {
    72{%- elif type == "int" -%}
    73func {{name}}(val int) attribute.KeyValue {
    74{%- elif type == "int[]" -%}
    75func {{name}}(val ...int) attribute.KeyValue {
    76{%- elif type == "double" -%}
    77func {{name}}(val float64) attribute.KeyValue {
    78{%- elif type == "double[]" -%}
    79func {{name}}(val ...float64) attribute.KeyValue {
    80{%- elif type == "boolean" -%}
    81func {{name}}(val bool) attribute.KeyValue {
    82{%- elif type == "boolean[]" -%}
    83func {{name}}(val ...bool) attribute.KeyValue {
    84{%- endif -%}
    85	return {{name}}Key.{{keyval_method(type)}}(val)
    86}
    87{%- endmacro -%}
    88{%- macro sentence_case(text) -%}
    89    {{ text[0]|upper}}{{text[1:] }}
    90{%- endmacro -%}
    91// Copyright The OpenTelemetry Authors
    92//
    93// Licensed under the Apache License, Version 2.0 (the "License");
    94// you may not use this file except in compliance with the License.
    95// You may obtain a copy of the License at
    96//
    97//     http://www.apache.org/licenses/LICENSE-2.0
    98//
    99// Unless required by applicable law or agreed to in writing, software
   100// distributed under the License is distributed on an "AS IS" BASIS,
   101// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   102// See the License for the specific language governing permissions and
   103// limitations under the License.
   104
   105// Code generated from semantic convention specification. DO NOT EDIT.
   106
   107package semconv  // import [[IMPORTPATH]]
   108
   109import "go.opentelemetry.io/otel/attribute"
   110
   111{% for semconv in semconvs -%}
   112{%- if semconvs[semconv].attributes | rejectattr("ref") | selectattr("is_local") | sort(attribute=fqn) | length > 0 -%}
   113// {{ sentence_case(semconvs[semconv].brief | replace("This document defines ", "")) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }}
   114const (
   115{%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref %}
   116	// {{ keydoc(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }}
   117	// {{ keydetails(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }}
   118	{{to_go_name(attr.fqn)}}Key = attribute.Key("{{attr.fqn}}")
   119{% endfor -%}
   120)
   121{%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref -%}
   122{%- if attr.attr_type is not string %}
   123
   124var (
   125{%- for val in attr.attr_type.members %}
   126    // {{ val.brief | to_doc_brief }}
   127    {{to_go_name("{}.{}".format(attr.fqn, val.member_id))}} = {{to_go_name(attr.fqn)}}Key.{{to_go_attr_type(attr.attr_type.enum_type, val.value)}}
   128{%- endfor %}
   129)
   130{%- endif -%}
   131{%- endfor %}
   132{%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref -%}
   133{%- if attr.attr_type is string %}
   134
   135{{ fndoc(attr) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }}
   136{{to_go_func(attr.attr_type, to_go_name(attr.fqn))}}
   137{%- endif -%}
   138{%- endfor %}
   139
   140{% endif %}
   141{% endfor -%}
   142

View as plain text