semantic_metrics-h.j2 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. {#
  2. Copyright The OpenTelemetry Authors
  3. SPDX-License-Identifier: Apache-2.0
  4. This file is:
  5. - a Jinja template,
  6. - used to generate semantic conventions,
  7. - using weaver.
  8. For doc on the template syntax:
  9. https://jinja.palletsprojects.com/en/3.0.x/
  10. For doc on the semantic conventions:
  11. https://github.com/open-telemetry/semantic-conventions
  12. For doc on weaver:
  13. https://github.com/open-telemetry/weaver
  14. #}
  15. /*
  16. * Copyright The OpenTelemetry Authors
  17. * SPDX-License-Identifier: Apache-2.0
  18. */
  19. /*
  20. * DO NOT EDIT, this is an Auto-generated file from:
  21. * buildscripts/semantic-convention/templates/registry/semantic_metrics-h.j2
  22. */
  23. {# ========================================================================== #}
  24. {#
  25. DESIGN NOTES:
  26. - Use the debug flag to dump the semantic convention data
  27. in the generated output, to inspect it.
  28. - Some instruments are not supported in the SDK.
  29. For these, we do not generate the code.
  30. #}
  31. {# ========================================================================== #}
  32. {% set debug = false %}
  33. {% set file_name = ctx.output + (ctx.root_namespace | snake_case) ~ "_metrics.h" %}
  34. {{ template.set_file_name(file_name) }}
  35. {% set metrics = ctx.metrics | list %}
  36. {% macro metric_namespace(ctx) %}
  37. {{ ctx.root_namespace | snake_case }}
  38. {% endmacro %}
  39. {% macro func_metric_name(metric) %}
  40. {{ metric.id | pascal_case }}
  41. {% endmacro %}
  42. {% macro var_metric_name(metric) %}
  43. k{{ metric.id | pascal_case }}
  44. {% endmacro %}
  45. {% macro descr_metric_name(metric) %}
  46. descr{{ metric.id | pascal_case }}
  47. {% endmacro %}
  48. {% macro unit_metric_name(metric) %}
  49. unit{{ metric.id | pascal_case }}
  50. {% endmacro %}
  51. {% macro sync_instrument_min_abi_version(metric) %}
  52. {{ metric.instrument | map_text("cpp_sync_min_abi_version") | trim }}
  53. {% endmacro %}
  54. {% macro sync_instrument_int64_type(metric) %}
  55. {{ metric.instrument | map_text("cpp_sync_instrument_to_int64_type") | trim }}
  56. {% endmacro %}
  57. {% macro sync_instrument_double_type(metric) %}
  58. {{ metric.instrument | map_text("cpp_sync_instrument_to_double_type") | trim }}
  59. {% endmacro %}
  60. {% macro sync_instrument_int64_factory(metric) %}
  61. {{ metric.instrument | map_text("cpp_sync_instrument_to_int64_factory") }}
  62. {% endmacro %}
  63. {% macro sync_instrument_double_factory(metric) %}
  64. {{ metric.instrument | map_text("cpp_sync_instrument_to_double_factory") }}
  65. {% endmacro %}
  66. {% macro async_instrument_min_abi_version(metric) %}
  67. {{ metric.instrument | map_text("cpp_async_min_abi_version") | trim }}
  68. {% endmacro %}
  69. {% macro async_instrument_type(metric) %}
  70. {{ metric.instrument | map_text("cpp_async_instrument_to_type") }}
  71. {% endmacro %}
  72. {% macro async_instrument_int64_factory(metric) %}
  73. {{ metric.instrument | map_text("cpp_async_instrument_to_int64_factory") }}
  74. {% endmacro %}
  75. {% macro async_instrument_double_factory(metric) %}
  76. {{ metric.instrument | map_text("cpp_async_instrument_to_double_factory") }}
  77. {% endmacro %}
  78. {% set cpp_metric_namespace = metric_namespace(ctx) %}
  79. {# ========================================================================== #}
  80. #pragma once
  81. #include "opentelemetry/common/macros.h"
  82. #include "opentelemetry/metrics/meter.h"
  83. #include "opentelemetry/version.h"
  84. OPENTELEMETRY_BEGIN_NAMESPACE
  85. namespace semconv
  86. {
  87. namespace {{ cpp_metric_namespace -}}
  88. {
  89. {% for metric in ctx.metrics %}
  90. {% if debug %}
  91. // DEBUG: {{ metric }}
  92. {% endif %}
  93. {% set f_metric_name = func_metric_name(metric) %}
  94. {% set v_metric_name = var_metric_name(metric) %}
  95. {% set descr = descr_metric_name(metric) %}
  96. {% set unit = unit_metric_name(metric) %}
  97. {% set sync_min_abi_version = (sync_instrument_min_abi_version(metric)) %}
  98. {% set async_min_abi_version = (async_instrument_min_abi_version(metric)) %}
  99. {% set sync_int64_type = sync_instrument_int64_type(metric) %}
  100. {% set sync_double_type = sync_instrument_double_type(metric) %}
  101. {% set async_type = async_instrument_type(metric) %}
  102. {% set sync_int64_factory = sync_instrument_int64_factory(metric) %}
  103. {% set sync_double_factory = sync_instrument_double_factory(metric) %}
  104. {% set async_int64_factory = async_instrument_int64_factory(metric) %}
  105. {% set async_double_factory = async_instrument_double_factory(metric) %}
  106. {% set excluded = metric.id in ctx.excluded_attributes %}
  107. {% if excluded %}
  108. #if 0
  109. // Excluded metric:
  110. {% endif %}
  111. {% if metric is deprecated %}
  112. {{ [metric.brief, "\n", "@deprecated", metric.deprecated, "\n", metric.note, "\n", metric.instrument] | comment(ident=2) }}
  113. OPENTELEMETRY_DEPRECATED
  114. {% else %}
  115. {{ [metric.brief, "\n", metric.note, "\n", metric.instrument] | comment(ident=2) }}
  116. {% endif %}
  117. static constexpr const char *{{v_metric_name}} = "{{metric.metric_name}}";
  118. {% if metric is deprecated %}
  119. OPENTELEMETRY_DEPRECATED
  120. {% endif %}
  121. static constexpr const char *{{descr}} = "{{metric.brief}}";
  122. {% if metric is deprecated %}
  123. OPENTELEMETRY_DEPRECATED
  124. {% endif %}
  125. static constexpr const char *{{unit}} = "{{metric.unit}}";
  126. {% if sync_min_abi_version|trim != "0" %}
  127. {% if sync_min_abi_version|trim != "1" %}
  128. #if OPENTELEMETRY_ABI_VERSION_NO >= {{sync_min_abi_version}}
  129. {% endif %}
  130. {% if metric is deprecated %}
  131. OPENTELEMETRY_DEPRECATED
  132. {% endif %}
  133. static inline nostd::unique_ptr<{{sync_int64_type-}}>
  134. CreateSyncInt64{{f_metric_name-}}(metrics::Meter *meter)
  135. {
  136. return meter->{{sync_int64_factory}}(
  137. {{v_metric_name}},
  138. {{descr}},
  139. {{unit}});
  140. }
  141. {% if metric is deprecated %}
  142. OPENTELEMETRY_DEPRECATED
  143. {% endif %}
  144. static inline nostd::unique_ptr<{{sync_double_type-}}>
  145. CreateSyncDouble{{f_metric_name-}}(metrics::Meter *meter)
  146. {
  147. return meter->{{sync_double_factory}}(
  148. {{v_metric_name}},
  149. {{descr}},
  150. {{unit}});
  151. }
  152. {% if sync_min_abi_version|trim != "1" %}
  153. #endif /* OPENTELEMETRY_ABI_VERSION_NO */
  154. {% endif %}
  155. {% endif %}
  156. {% if async_min_abi_version|trim != "0" %}
  157. {% if async_min_abi_version|trim != "1" %}
  158. #if OPENTELEMETRY_ABI_VERSION_NO >= {{async_min_abi_version}}
  159. {% endif %}
  160. {% if metric is deprecated %}
  161. OPENTELEMETRY_DEPRECATED
  162. {% endif %}
  163. static inline nostd::shared_ptr<{{async_type-}}>
  164. CreateAsyncInt64{{f_metric_name-}}(metrics::Meter *meter)
  165. {
  166. return meter->{{async_int64_factory}}(
  167. {{v_metric_name}},
  168. {{descr}},
  169. {{unit}});
  170. }
  171. {% if metric is deprecated %}
  172. OPENTELEMETRY_DEPRECATED
  173. {% endif %}
  174. static inline nostd::shared_ptr<{{async_type-}}>
  175. CreateAsyncDouble{{f_metric_name-}}(metrics::Meter *meter)
  176. {
  177. return meter->{{async_double_factory}}(
  178. {{v_metric_name}},
  179. {{descr}},
  180. {{unit}});
  181. }
  182. {% if async_min_abi_version|trim != "1" %}
  183. #endif /* OPENTELEMETRY_ABI_VERSION_NO */
  184. {% endif %}
  185. {% endif %}
  186. {% if excluded %}
  187. #endif /* 0 */
  188. {% endif %}
  189. {% endfor %}
  190. }
  191. }
  192. OPENTELEMETRY_END_NAMESPACE