|
| 1 | +//! Generated from OpenTelemetry semantic conventions specification v{{ params.schema_url | replace('https://opentelemetry.io/schemas/', '') }} |
| 2 | +//! This file contains semantic convention attribute definitions. |
| 3 | + |
| 4 | +const std = @import("std"); |
| 5 | +const types = @import("types.zig"); |
| 6 | + |
| 7 | +{% for root_ns in ctx -%} |
| 8 | +{%- for attr in root_ns.attributes | rejectattr("name", "in", params.excluded_attributes) %} |
| 9 | +{%- set attr_name = attr.name | replace('.', '_') | replace('-', '_') %} |
| 10 | + |
| 11 | +{%- if attr.type is mapping and attr.type.members is defined %} |
| 12 | +pub const {{ attr_name }}Value = enum { |
| 13 | +{%- for member in attr.type.members %} |
| 14 | + {%- set member_id = member.id | replace('-', '_') | replace('.', '_') %} |
| 15 | + {%- if member_id in ['type', 'align', 'async', 'await', 'break', 'const', 'continue', 'defer', 'else', 'enum', 'error', 'export', 'extern', 'fn', 'for', 'if', 'inline', 'noalias', 'null', 'or', 'orelse', 'packed', 'pub', 'resume', 'return', 'struct', 'suspend', 'switch', 'test', 'threadlocal', 'try', 'union', 'unreachable', 'usingnamespace', 'var', 'volatile', 'while'] or '.' in member.id %} |
| 16 | + @"{{ member_id }}", |
| 17 | + {%- else %} |
| 18 | + {{ member_id }}, |
| 19 | + {%- endif %} |
| 20 | +{%- endfor %} |
| 21 | + |
| 22 | + pub fn toString(self: @This()) []const u8 { |
| 23 | + return switch (self) { |
| 24 | +{%- for member in attr.type.members %} |
| 25 | + {%- set member_id = member.id | replace('-', '_') | replace('.', '_') %} |
| 26 | + {%- if member_id in ['type', 'align', 'async', 'await', 'break', 'const', 'continue', 'defer', 'else', 'enum', 'error', 'export', 'extern', 'fn', 'for', 'if', 'inline', 'noalias', 'null', 'or', 'orelse', 'packed', 'pub', 'resume', 'return', 'struct', 'suspend', 'switch', 'test', 'threadlocal', 'try', 'union', 'unreachable', 'usingnamespace', 'var', 'volatile', 'while'] or '.' in member.id %} |
| 27 | + .@"{{ member_id }}" => "{{ member.value }}", |
| 28 | + {%- else %} |
| 29 | + .{{ member_id }} => "{{ member.value }}", |
| 30 | + {%- endif %} |
| 31 | +{%- endfor %} |
| 32 | + }; |
| 33 | + } |
| 34 | +}; |
| 35 | + |
| 36 | +/// {{ attr.brief }} |
| 37 | +pub const {{ attr_name }} = types.EnumAttribute({{ attr_name }}Value){ |
| 38 | + .base = types.StringAttribute{ |
| 39 | + .name = "{{ attr.name }}", |
| 40 | + .brief = "{{ attr.brief | replace('"', '\\"') | replace('\n', ' ') | trim }}", |
| 41 | + {%- if attr.note %} |
| 42 | + .note = {{ '"' + attr.note | replace('\\', '\\\\') | replace('<', '[') | replace('>', ']') | replace('"', '\\"') | replace('\n', ' ') | trim + '"' }}, |
| 43 | + {%- endif %} |
| 44 | + .stability = {{ '.stable' if attr.stability == 'stable' else '.development' }}, |
| 45 | + .requirement_level = {{ '.required' if attr.requirement_level == 'required' else '.recommended' if attr.requirement_level == 'recommended' else '.opt_in' if attr.requirement_level == 'opt_in' else '.conditionally_required' if attr.requirement_level == 'conditionally_required' else '.recommended' }}, |
| 46 | + }, |
| 47 | + .well_known_values = {{ attr_name }}Value.{% set first_member = attr.type.members[0].id | replace('-', '_') | replace('.', '_') %}{% if first_member in ['type', 'align', 'async', 'await', 'break', 'const', 'continue', 'defer', 'else', 'enum', 'error', 'export', 'extern', 'fn', 'for', 'if', 'inline', 'noalias', 'null', 'or', 'orelse', 'packed', 'pub', 'resume', 'return', 'struct', 'suspend', 'switch', 'test', 'threadlocal', 'try', 'union', 'unreachable', 'usingnamespace', 'var', 'volatile', 'while'] or '.' in attr.type.members[0].id %}@"{{ first_member }}"{% else %}{{ first_member }}{% endif %}, |
| 48 | +}; |
| 49 | + |
| 50 | +{%- else %} |
| 51 | + |
| 52 | +/// {{ attr.brief }} |
| 53 | +pub const {{ attr_name }} = types.StringAttribute{ |
| 54 | + .name = "{{ attr.name }}", |
| 55 | + .brief = "{{ attr.brief | replace('"', '\\"') | replace('\n', ' ') | trim }}", |
| 56 | + {%- if attr.note %} |
| 57 | + .note = {{ '"' + attr.note | replace('\\', '\\\\') | replace('<', '[') | replace('>', ']') | replace('"', '\\"') | replace('\n', ' ') | trim + '"' }}, |
| 58 | + {%- endif %} |
| 59 | + .stability = {{ '.stable' if attr.stability == 'stable' else '.development' }}, |
| 60 | + .requirement_level = {{ '.required' if attr.requirement_level == 'required' else '.recommended' if attr.requirement_level == 'recommended' else '.opt_in' if attr.requirement_level == 'opt_in' else '.conditionally_required' if attr.requirement_level == 'conditionally_required' else '.recommended' }}, |
| 61 | +}; |
| 62 | + |
| 63 | +{%- endif %} |
| 64 | + |
| 65 | +{%- endfor %} |
| 66 | +{%- endfor %} |
| 67 | + |
| 68 | +test "semantic attributes" { |
| 69 | + std.testing.refAllDecls(@This()); |
| 70 | +} |
0 commit comments