-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-generated Semantic Conventions (#2069)
- Loading branch information
1 parent
6d6222f
commit 2377d00
Showing
14 changed files
with
4,229 additions
and
0 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
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
Empty file.
526 changes: 526 additions & 0 deletions
526
src/OpenTelemetry.SemanticConventions/.publicApi/net462/PublicAPI.Unshipped.txt
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
526 changes: 526 additions & 0 deletions
526
src/OpenTelemetry.SemanticConventions/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt
Large diffs are not rendered by default.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
src/OpenTelemetry.SemanticConventions/OpenTelemetry.SemanticConventions.csproj
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks> | ||
<Description>OpenTelemetry Semantic Conventions</Description> | ||
<PackageTags>$(PackageTags);semantic-conventions</PackageTags> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,34 @@ | ||
# Semantic Conventions for OpenTelemetry .NET | ||
|
||
This project contains the generated code for the Semantic Conventions | ||
defined by the OpenTelemetry specification. | ||
|
||
## Installation | ||
|
||
```shell | ||
dotnet add package OpenTelemetry.SemanticConventions | ||
``` | ||
|
||
## Generating the files | ||
|
||
This project uses the | ||
[Semantic Convention Generator](https://github.com/open-telemetry/build-tools/blob/main/semantic-conventions/README.md). | ||
The folder `scripts` at the top level of the project contains | ||
the templates and the script file used in the process. | ||
|
||
To generate the code files, run: | ||
|
||
```shell | ||
./scripts/semantic-conventions/generate.sh | ||
``` | ||
|
||
Or, with PowerShell: | ||
|
||
```shell | ||
./scripts/semantic-conventions/generate.ps1 | ||
``` | ||
|
||
## References | ||
|
||
* [OpenTelemetry Project](https://opentelemetry.io/) | ||
* [Build tools](https://github.com/open-telemetry/build-tools) |
1,028 changes: 1,028 additions & 0 deletions
1,028
src/OpenTelemetry.SemanticConventions/Resource/ResourceSemanticConventions.cs
Large diffs are not rendered by default.
Oops, something went wrong.
1,878 changes: 1,878 additions & 0 deletions
1,878
src/OpenTelemetry.SemanticConventions/Trace/TraceSemanticConventions.cs
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
src/OpenTelemetry.SemanticConventions/scripts/semantic-conventions/.gitignore
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/ |
51 changes: 51 additions & 0 deletions
51
src/OpenTelemetry.SemanticConventions/scripts/semantic-conventions/generate.ps1
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,51 @@ | ||
|
||
$SCRIPT_DIR=$PSScriptRoot | ||
$ROOT_DIR="${SCRIPT_DIR}/../../" | ||
|
||
# freeze the spec & generator tools versions to make SemanticAttributes generation reproducible | ||
$SPEC_VERSION="v1.13.0" | ||
$SCHEMA_URL="https://opentelemetry.io/schemas/$SPEC_VERSION" | ||
$GENERATOR_VERSION="0.14.0" | ||
|
||
Set-Location $SCRIPT_DIR | ||
|
||
Remove-Item -r -fo opentelemetry-specification | ||
mkdir opentelemetry-specification | ||
Set-Location 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 | ||
Set-Location ${SCRIPT_DIR} | ||
|
||
docker run --rm ` | ||
-v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/trace:/source ` | ||
-v ${SCRIPT_DIR}/templates:/templates ` | ||
-v ${ROOT_DIR}/Trace:/output ` | ||
otel/semconvgen:$GENERATOR_VERSION ` | ||
-f /source code ` | ||
--template /templates/SemanticConventions.cs.j2 ` | ||
--output /output/TraceSemanticConventions.cs ` | ||
--trim-whitespace ` | ||
-D class=TraceSemanticConventions ` | ||
-D schemaUrl=$SCHEMA_URL ` | ||
-D pkg=OpenTelemetry.Trace | ||
|
||
docker run --rm ` | ||
-v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/resource:/source ` | ||
-v ${SCRIPT_DIR}/templates:/templates ` | ||
-v ${ROOT_DIR}/Resource:/output ` | ||
otel/semconvgen:$GENERATOR_VERSION ` | ||
-f /source code ` | ||
--template /templates/SemanticConventions.cs.j2 ` | ||
--output /output/ResourceSemanticConventions.cs ` | ||
--trim-whitespace ` | ||
-D class=ResourceSemanticConventions ` | ||
-D schemaUrl=$SCHEMA_URL ` | ||
-D pkg=OpenTelemetry.Resources | ||
|
||
Set-Location ${ROOT_DIR} | ||
|
||
# Write-Host "Running dotnet-format on the generated files" | ||
# dotnet format --severity warn |
47 changes: 47 additions & 0 deletions
47
src/OpenTelemetry.SemanticConventions/scripts/semantic-conventions/generate.sh
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,47 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
ROOT_DIR="${SCRIPT_DIR}/../../" | ||
|
||
# freeze the spec & generator tools versions to make SemanticAttributes generation reproducible | ||
SPEC_VERSION=v1.13.0 | ||
SCHEMA_URL=https://opentelemetry.io/schemas/$SPEC_VERSION | ||
GENERATOR_VERSION=0.14.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}/Trace:/output \ | ||
otel/semconvgen:$GENERATOR_VERSION \ | ||
-f /source code \ | ||
--template /templates/SemanticConventions.cs.j2 \ | ||
--output /output/TraceSemanticConventions.cs \ | ||
--trim-whitespace \ | ||
-Dclass=TraceSemanticConventions \ | ||
-DschemaUrl=$SCHEMA_URL \ | ||
-Dpkg=OpenTelemetry.Trace | ||
|
||
docker run --rm \ | ||
-v ${SCRIPT_DIR}/opentelemetry-specification/semantic_conventions/resource:/source \ | ||
-v ${SCRIPT_DIR}/templates:/templates \ | ||
-v ${ROOT_DIR}/Resource:/output \ | ||
otel/semconvgen:$GENERATOR_VERSION \ | ||
-f /source code \ | ||
--template /templates/SemanticConventions.cs.j2 \ | ||
--output /output/ResourceSemanticConventions.cs \ | ||
--trim-whitespace \ | ||
-Dclass=ResourceSemanticConventions \ | ||
-DschemaUrl=$SCHEMA_URL \ | ||
-Dpkg=OpenTelemetry.Resources |
116 changes: 116 additions & 0 deletions
116
...etry.SemanticConventions/scripts/semantic-conventions/templates/SemanticConventions.cs.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,116 @@ | ||
{%- macro print_value(type, value) -%} | ||
{{ "\"" if type == "string"}}{{value}}{{ "\"" if type == "string"}} | ||
{%- endmacro %} | ||
|
||
{%- macro format_remarks(text) -%} | ||
{%- set notes = '\n /// '.join(text.splitlines()).encode('ascii', 'xmlcharrefreplace').decode() -%} | ||
{{notes}} | ||
{%- endmacro -%} | ||
|
||
{%- macro format_xml_doc(text) -%} | ||
{%- set escaped = text.encode('ascii', 'xmlcharrefreplace').decode() -%} | ||
{%- if not escaped.endswith('.')-%} | ||
{{escaped + '.'}} | ||
{%- else -%} | ||
{{escaped}} | ||
{%- endif -%} | ||
{%- endmacro -%} | ||
|
||
// <copyright file="{{class}}.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
// <auto-generated> This file has been auto generated from buildscripts/semantic-conventions{{template}}</auto-generated> | ||
|
||
using System; | ||
|
||
namespace {{pkg | trim}} | ||
{ | ||
/// <summary> | ||
/// Constants for semantic attribute names outlined by the OpenTelemetry specifications. | ||
{% if class == "TraceSemanticConventions" %} | ||
/// <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/README.md"/>. | ||
{% elif class == "ResourceSemanticConventions" %} | ||
/// <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md"/>. | ||
{% endif %} | ||
/// </summary> | ||
/// <remarks> | ||
/// Schema and specification version: {{schemaUrl}}. | ||
/// </remarks> | ||
public static class {{class}} | ||
{ | ||
{% if class == "TraceSemanticConventions" %} | ||
/// <summary> | ||
/// Attribute for db.instance. | ||
/// </summary> | ||
public const string AttributeDbInstance = "db.instance"; | ||
|
||
{% endif %} | ||
{% for attribute in attributes if attribute.is_local and not attribute.ref %} | ||
{% if not loop.first %}{{"\n"}}{% endif %} | ||
/// <summary> | ||
/// {{format_xml_doc(attribute.brief | render_markdown(code="<c>{0}</c>", paragraph="{0}"))}} | ||
/// </summary> | ||
{% if attribute.note %} | ||
/// <remarks> | ||
/// {{format_remarks(attribute.note | to_doc_brief | escape | render_markdown(code="<c>{0}</c>", paragraph="{0}"))}}. | ||
/// </remarks> | ||
{% endif %} | ||
{% if attribute.deprecated %} | ||
[Obsolete("{{attribute.deprecated | to_doc_brief}}")] | ||
{% endif %} | ||
public const string Attribute{{attribute.fqn | replace("-","_") | to_camelcase(True)}} = "{{attribute.fqn}}"; | ||
{% endfor %} | ||
{% for semconv in semconvs.values() | unique(attribute="prefix") %} | ||
{% if semconv.prefix %} | ||
|
||
/// <summary> | ||
/// Prefix for '{{semconv.semconv_id}}'. | ||
/// </summary> | ||
public static readonly string Prefix{{semconv.semconv_id | replace("-","_") | to_camelcase(True)}} = "{{semconv.prefix}}"; | ||
{% endif %} | ||
{% endfor %} | ||
{% for semconv in semconvs.values() %} | ||
{% if semconv.GROUP_TYPE_NAME == 'event' %} | ||
|
||
/// <summary> | ||
/// Event name for '{{semconv.semconv_id}}'. | ||
/// </summary> | ||
public static readonly string Event{{semconv.semconv_id | replace("-","_") | to_camelcase(True)}} = "{{semconv.name}}"; | ||
{% endif %} | ||
{% endfor %} | ||
{% for attribute in attributes if attribute.is_local and not attribute.ref %} | ||
{% if attribute.is_enum %} | ||
{% set class_name = attribute.fqn | to_camelcase(True) ~ "Values" %} | ||
{% set type = attribute.attr_type.enum_type %} | ||
|
||
/// <summary> | ||
/// {{format_xml_doc(attribute.brief | render_markdown(code="<c>{0}</c>", paragraph="{0}"))}} | ||
/// </summary> | ||
public static class {{class_name}} | ||
{ | ||
{% for member in attribute.attr_type.members %} | ||
/// <summary> | ||
/// {{format_xml_doc(member.brief | render_markdown(code="<c>{0}</c>", paragraph="{0}"))}} | ||
/// </summary> | ||
public const {{ type }} {{ member.member_id | to_camelcase(True) }} = {{ print_value(type, member.value) }}; | ||
{% if not loop.last %}{{"\n"}}{% endif %} | ||
{% endfor %} | ||
} | ||
{% endif %} | ||
{% endfor %} | ||
} | ||
} | ||
|