semantic_attributes-h.j2 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_attributes-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. #}
  29. {# ========================================================================== #}
  30. {% set debug = false %}
  31. {% set file_name = ctx.output + (ctx.root_namespace | snake_case) ~ "_attributes.h" %}
  32. {{ template.set_file_name(file_name) }}
  33. {% set attributes = ctx.attributes | list %}
  34. {% set enum_attributes = attributes | select("enum") | rejectattr("name", "in", ctx.excluded_attributes) | list %}
  35. {% macro attribute_namespace(ctx) %}
  36. {{ ctx.root_namespace | snake_case }}
  37. {% endmacro %}
  38. {% macro attribute_name(attribute) %}
  39. k{{ attribute.name | pascal_case }}
  40. {% endmacro %}
  41. {% macro attribute_type(attribute) %}
  42. {{ attribute.type | enum_type | map_text("cpp_types") }}
  43. {% endmacro %}
  44. {% macro enum_namespace_name(attribute) %}
  45. {{ attribute.name | pascal_case ~ "Values"}}
  46. {% endmacro %}
  47. {% macro enum_name(member) %}
  48. k{{ member.id | pascal_case }}
  49. {% endmacro %}
  50. {% set cpp_attribute_namespace = attribute_namespace(ctx) %}
  51. {# ========================================================================== #}
  52. #pragma once
  53. #include "opentelemetry/common/macros.h"
  54. #include "opentelemetry/version.h"
  55. OPENTELEMETRY_BEGIN_NAMESPACE
  56. namespace semconv
  57. {
  58. namespace {{ cpp_attribute_namespace -}}
  59. {
  60. {% for attribute in attributes %}
  61. {% if debug %}
  62. // DEBUG: {{ attribute }}
  63. {% endif %}
  64. {% set cpp_attr_name = attribute_name(attribute) %}
  65. {% set excluded = attribute.name in ctx.excluded_attributes %}
  66. {% if excluded %}
  67. #if 0
  68. // Excluded attribute:
  69. {% endif %}
  70. {% if attribute is deprecated %}
  71. {{ [attribute.brief, "\n", "@deprecated", attribute.deprecated, "\n", attribute.note] | comment(ident=2) }}
  72. OPENTELEMETRY_DEPRECATED
  73. {% else %}
  74. {{ [attribute.brief, "\n", attribute.note] | comment(ident=2) }}
  75. {% endif %}
  76. static constexpr const char *{{cpp_attr_name}} = "{{attribute.name}}";
  77. {% if excluded %}
  78. #endif
  79. {% endif %}
  80. {% endfor %}
  81. {% for attribute in enum_attributes %}
  82. {% set class_name = attribute.name | pascal_case ~ "Values" %}
  83. {% set cpp_enum_name = enum_namespace_name(attribute) %}
  84. {% set cpp_enum_type = attribute_type(attribute) %}
  85. {% if debug %}
  86. // DEBUG: {{ attribute }}
  87. {% endif %}
  88. namespace {{cpp_enum_name -}}
  89. {
  90. {% for member in attribute.type.members %}
  91. {% set member_name = enum_name(member) %}
  92. {% if debug %}
  93. // DEBUG: {{ member }}
  94. {% endif %}
  95. {% if member is deprecated %}
  96. {{ [member.brief, "\n", "@deprecated", member.deprecated] | comment(ident=2) }}
  97. OPENTELEMETRY_DEPRECATED
  98. {% else %}
  99. {{ member.brief | comment(ident=2) }}
  100. {% endif %}
  101. static constexpr {{ cpp_enum_type }} {{ member_name }} = {{ member.value | print_member_value }};
  102. {% endfor %}
  103. }
  104. {% endfor %}
  105. }
  106. }
  107. OPENTELEMETRY_END_NAMESPACE