forked from open-telemetry/opentelemetry-cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SemanticAttributes.h.j2
112 lines (99 loc) · 3.07 KB
/
SemanticAttributes.h.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
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
{#
Adapted from:
https://github.com/open-telemetry/semantic-conventions-java/blob/main/buildscripts/templates/SemanticAttributes.java.j2
for opentelemetry-cpp
For doc on the template syntax:
https://jinja.palletsprojects.com/en/3.0.x/
For doc on the semantic convention:
https://github.com/open-telemetry/build-tools/tree/main/semantic-conventions
#}
{%- macro to_cpp_return_type(type) -%}
{%- if type == "string" -%}
char *
{%- elif type == "string[]" -%}
char *[]
{%- elif type == "boolean" -%}
bool
{%- elif type == "int" -%}
int
{%- elif type == "double" -%}
double
{%- else -%}
{{type}}
{%- endif -%}
{%- endmacro %}
{%- macro print_value(type, value) -%}
{{ "\"" if type == "char *"}}{{value}}{{ "\"" if type == "char *"}}
{%- endmacro %}
{%- macro upFirst(text) -%}
{{ text[0]|upper}}{{text[1:] }}
{%- endmacro %}
{%- macro lowerFirst(text) -%}
{{ text[0]|lower}}{{text[1:] }}
{%- endmacro %}
/*
DO NOT EDIT, this is an Auto-generated file
from buildscripts/semantic-convention{{template}}
*/
#pragma once
#include "opentelemetry/common/macros.h"
#include "opentelemetry/version.h"
OPENTELEMETRY_BEGIN_NAMESPACE
{{namespace_open}}
namespace {{class}}
{
/**
* The URL of the OpenTelemetry schema for these keys and values.
*/
static constexpr const char *kSchemaUrl = "{{schemaUrl}}";
{%- for attribute in attributes if attribute.is_local and not attribute.ref %}
/**
* {{attribute.brief | render_markdown(code="{{@code {0}}}", paragraph="{0}")}}
{%- if attribute.note %}
*
* <p>Notes:
<ul> {{attribute.note | render_markdown(code="{{@code {0}}}", paragraph="<li>{0}</li>", list="{0}")}} </ul>
{%- endif %}
{%- if (attribute.deprecated) %}
*
* @deprecated {{attribute.brief | to_doc_brief}}.
{%- endif %}
*/
{%- if (attribute.deprecated) %}
OPENTELEMETRY_DEPRECATED
{%- endif %}
static constexpr const char *k{{attribute.fqn | to_camelcase(True)}} = "{{attribute.fqn}}";
{%- endfor %}
// Enum definitions
{%- for attribute in attributes if attribute.is_local and not attribute.ref %}
{%- if attribute.is_enum %}
{%- set enum_name = attribute.fqn | to_camelcase(True) ~ "Values" %}
{%- set type = to_cpp_return_type(attribute.attr_type.enum_type) %}
namespace {{enum_name}}
{
{%- for member in attribute.attr_type.members %}
/** {% filter escape %}{{member.brief | to_doc_brief}}.{% endfilter %} */
static constexpr const {{ type }} k{{ member.member_id | to_camelcase(True) }} = {{ print_value(type, member.value) }};
{%- endfor %}
}
{% endif %}
{%- endfor %}
{#
{%- if class == "SemanticAttributes" %}
// 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.
*/
static constexpr const char *EXCEPTION_EVENT_NAME = "exception";
{% endif %}
#}
} // namespace {{class}}
{{namespace_close}}
OPENTELEMETRY_END_NAMESPACE