forked from open-telemetry/opentelemetry-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically generate semantic conventions from the spec (open-telem…
- Loading branch information
Showing
16 changed files
with
2,027 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,140 changes: 1,140 additions & 0 deletions
1,140
api/include/opentelemetry/trace/semantic_conventions.h
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
opentelemetry-specification/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Adapted from: | ||
# opentelemetry-java/buildscripts/semantic-convention/generate.sh | ||
# for opentelemetry-cpp | ||
# | ||
|
||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
ROOT_DIR="${SCRIPT_DIR}/../../" | ||
|
||
# freeze the spec & generator tools versions to make SemanticAttributes generation reproducible | ||
SEMCONV_VERSION=1.9.0 | ||
SPEC_VERSION=v$SEMCONV_VERSION | ||
SCHEMA_URL=https://opentelemetry.io/schemas/$SEMCONV_VERSION | ||
GENERATOR_VERSION=0.7.0 | ||
|
||
cd ${SCRIPT_DIR} | ||
|
||
rm -rf opentelemetry-specification || true | ||
mkdir opentelemetry-specification | ||
cd opentelemetry-specification | ||
|
||
git init | ||
git remote add origin https://github.com/open-telemetry/opentelemetry-specification.git | ||
git fetch origin "$SPEC_VERSION" | ||
git reset --hard FETCH_HEAD | ||
cd ${SCRIPT_DIR} | ||
|
||
docker run --rm \ | ||
-v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/trace:/source \ | ||
-v ${SCRIPT_DIR}/templates:/templates \ | ||
-v ${ROOT_DIR}/api/include/opentelemetry/trace/:/output \ | ||
otel/semconvgen:$GENERATOR_VERSION \ | ||
-f /source code \ | ||
--template /templates/SemanticAttributes.h.j2 \ | ||
--output /output/semantic_conventions.h \ | ||
-Dclass=SemanticConventions \ | ||
-DschemaUrl=$SCHEMA_URL \ | ||
-Dnamespace_open="namespace trace {" \ | ||
-Dnamespace_close="}" | ||
|
||
docker run --rm \ | ||
-v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/resource:/source \ | ||
-v ${SCRIPT_DIR}/templates:/templates \ | ||
-v ${ROOT_DIR}/sdk/include/opentelemetry/sdk/resource/:/output \ | ||
otel/semconvgen:$GENERATOR_VERSION \ | ||
-f /source code \ | ||
--template /templates/SemanticAttributes.h.j2 \ | ||
--output /output/semantic_conventions.h \ | ||
-Dclass=SemanticConventions \ | ||
-DschemaUrl=$SCHEMA_URL \ | ||
-Dnamespace_open="namespace sdk { namespace resource {" \ | ||
-Dnamespace_close="} }" | ||
|
109 changes: 109 additions & 0 deletions
109
buildscripts/semantic-convention/templates/SemanticAttributes.h.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
{# | ||
Adapted from: | ||
opentelemetry-java/buildscripts/semantic-convention/templates/SemanticAttributes.java.j2 | ||
for opentelemetry-cpp | ||
#} | ||
{%- 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}} | ||
*/ | ||
|
||
/* clang-format off */ | ||
|
||
#pragma once | ||
|
||
#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* SCHEMA_URL = "{{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.deprecated | to_doc_brief}}. | ||
{%- endif %} | ||
*/ | ||
{%- if attribute.deprecated %} | ||
@Deprecated | ||
{%- endif %} | ||
static constexpr const char* {{attribute.fqn | to_const_name}} = "{{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 }} {{ member.member_id | to_const_name }} = {{ 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 | ||
|
||
/* clang-format on */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.