Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generated Semantic Conventions #2069

Merged
merged 43 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7e2b190
Introduce SemanticConventions project
joaopgrassi May 24, 2021
4a0305f
Merge branch 'main' into feat/autogen_semconv
cijothomas Oct 18, 2021
a26aa03
Merge branch 'main' into feat/autogen_semconv
cijothomas Oct 19, 2021
03ffc5d
Add missing PublicAPI entries
joaopgrassi Oct 20, 2021
00dfd83
Add auto-generated to template
joaopgrassi Oct 20, 2021
3e0f044
Update files
joaopgrassi Oct 20, 2021
6298fe0
Fix resource semconv specification URL
joaopgrassi Oct 20, 2021
9fe5607
Fix markdown issues
joaopgrassi Oct 20, 2021
3abccc5
PR fixes and using the dotnet format tool
joaopgrassi Oct 22, 2021
546fc19
Fix trailing space in remarks
joaopgrassi Oct 22, 2021
9f77cf4
Adapt bash script and README
joaopgrassi Oct 26, 2021
a179623
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Oct 27, 2021
7a78dfe
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Nov 2, 2021
6ea49ef
Add support for prefixes and event name
joaopgrassi Nov 5, 2021
e8e5cf2
Merge branch 'feat/autogen_semconv' of github.com:joaopgrassi/opentel…
joaopgrassi Nov 5, 2021
356b406
Merge remote-tracking branch 'upstream/main' into feat/autogen_semconv
joaopgrassi Nov 5, 2021
89b189f
Update public api files
joaopgrassi Nov 5, 2021
5837c79
Missing fixed .sln after merge conflict resolution
joaopgrassi Nov 5, 2021
1d3e949
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Jan 10, 2022
f94fb9f
Improve prefix and event attr generation template
joaopgrassi Feb 5, 2022
2f16f30
Use format from .NET SDK
joaopgrassi Feb 5, 2022
4c991c3
Re-generate after template changes
joaopgrassi Feb 5, 2022
9c91f90
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Feb 5, 2022
5ee7692
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Feb 15, 2022
2bed012
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Jun 29, 2022
38b3846
Improve whitespace in the template
joaopgrassi Jun 29, 2022
fe2778e
Adapt script
joaopgrassi Jul 25, 2022
1a2a971
Merge branch 'main' into feat/autogen_semconv
cijothomas Sep 2, 2022
5d6b064
Merge branch 'main' into feat/autogen_semconv
cijothomas Sep 2, 2022
99de7b6
Bump tool version and format remarks better
joaopgrassi Sep 6, 2022
28f921f
Escape chars in remarks
joaopgrassi Sep 6, 2022
b9880f1
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Sep 6, 2022
3b99dc8
Merge branch 'main' into feat/autogen_semconv
cijothomas Sep 21, 2022
c558b57
Use spec version 1.13, net462, update PublicApi files
joaopgrassi Sep 26, 2022
cf422d9
Appease build with missing blank line
joaopgrassi Sep 26, 2022
d850232
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Sep 26, 2022
af99f52
Merge branch 'main' into feat/autogen_semconv
cijothomas Sep 30, 2022
6494bd4
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Oct 3, 2022
7cbfc4c
Merge branch 'main' into feat/autogen_semconv
cijothomas Oct 10, 2022
3d7956b
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Oct 18, 2022
110db72
Merge branch 'main' into feat/autogen_semconv
cijothomas Oct 18, 2022
d3af237
Merge branch 'main' into feat/autogen_semconv
cijothomas Oct 18, 2022
459cf85
Merge branch 'main' into feat/autogen_semconv
joaopgrassi Oct 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions OpenTelemetry.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

<PackProjects Include="src\**\*.csproj" />

<!-- Windows specific projects -->
<PackProjects Remove="src\OpenTelemetry.Instrumentation.AspNet\OpenTelemetry.Instrumentation.AspNet.csproj" Condition="'$(OS)' != 'Windows_NT'" />

<!-- Not pack SemanticConventions project for now -->
<SolutionProjects Remove="src\OpenTelemetry.SemanticConventions\OpenTelemetry.SemanticConventions.csproj" />
<PackProjects Remove="src\OpenTelemetry.SemanticConventions\OpenTelemetry.SemanticConventions.csproj" Condition="'$(OS)' != 'Windows_NT'" />

</ItemGroup>

<Target Name="Build">
Expand Down
6 changes: 6 additions & 0 deletions OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "source-generation", "docs\l
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "getting-started-prometheus-grafana", "docs\metrics\getting-started-prometheus-grafana\getting-started-prometheus-grafana.csproj", "{41B784AA-3301-4126-AF9F-1D59BD04B0BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.SemanticConventions", "src\OpenTelemetry.SemanticConventions\OpenTelemetry.SemanticConventions.csproj", "{D4519DF6-CC72-4AC4-A851-E21383098D11}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "customizing-the-sdk", "docs\logs\customizing-the-sdk\customizing-the-sdk.csproj", "{6C7A1595-36D6-4229-BBB5-5A6B5791791D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Propagators", "src\OpenTelemetry.Extensions.Propagators\OpenTelemetry.Extensions.Propagators.csproj", "{E91B2E40-E428-43B3-8A43-09709F0E69E4}"
Expand Down Expand Up @@ -434,6 +436,10 @@ Global
{41B784AA-3301-4126-AF9F-1D59BD04B0BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41B784AA-3301-4126-AF9F-1D59BD04B0BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41B784AA-3301-4126-AF9F-1D59BD04B0BF}.Release|Any CPU.Build.0 = Release|Any CPU
{D4519DF6-CC72-4AC4-A851-E21383098D11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4519DF6-CC72-4AC4-A851-E21383098D11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4519DF6-CC72-4AC4-A851-E21383098D11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4519DF6-CC72-4AC4-A851-E21383098D11}.Release|Any CPU.Build.0 = Release|Any CPU
{6C7A1595-36D6-4229-BBB5-5A6B5791791D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C7A1595-36D6-4229-BBB5-5A6B5791791D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C7A1595-36D6-4229-BBB5-5A6B5791791D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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>
34 changes: 34 additions & 0 deletions src/OpenTelemetry.SemanticConventions/README.md
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 src/OpenTelemetry.SemanticConventions/Resource/ResourceSemanticConventions.cs

Large diffs are not rendered by default.

1,878 changes: 1,878 additions & 0 deletions src/OpenTelemetry.SemanticConventions/Trace/TraceSemanticConventions.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opentelemetry-specification/
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
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
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 %}
}
}