Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions .config/mise/tasks/semconv/check
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
#MISE description="Validate the semantic convention registry and generated constants"

set -eu

root=$(CDPATH='' cd -- "$(dirname -- "$0")/../../../.." && pwd)
expected="$root/src/TrogonEventStore.SemanticConventions/Generated"
generated=$(mktemp -d)
trap 'rm -rf "$generated"' EXIT HUP INT TERM

"$root/.config/mise/tasks/semconv/generate" "$generated"
diff -ru "$expected" "$generated"
35 changes: 35 additions & 0 deletions .config/mise/tasks/semconv/generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
#MISE description="Generate the reusable semantic convention constants"

set -eu

root=$(CDPATH='' cd -- "$(dirname -- "$0")/../../../.." && pwd)
output=${1:-"$root/src/TrogonEventStore.SemanticConventions/Generated"}
registry_version=$(sed -n '1p' "$root/otel/semconv/registry-version")
registry="https://github.com/open-telemetry/semantic-conventions@${registry_version}[model]"
staging=$(mktemp -d)
trap 'rm -rf "$staging"' EXIT HUP INT TERM

weaver registry check \
--future \
--registry "$registry"

weaver registry generate csharp "$staging" \
--future \
--registry "$registry" \
--templates "$root/otel/semconv/templates"

set -- "$staging"/*.g.cs
[ -e "$1" ] || exit 1

mkdir -p "$output"
for generated_file in "$output"/*.g.cs
do
[ -e "$generated_file" ] || break
rm "$generated_file"
done

for generated_file
do
mv "$generated_file" "$output/"
Comment thread
yordis marked this conversation as resolved.
done
19 changes: 19 additions & 0 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ permissions:
packages: read

jobs:
semantic-conventions:
runs-on: ubuntu-latest
name: Semantic Conventions
steps:
- name: Checkout
uses: actions/checkout@v7
Comment thread
coderabbitai[bot] marked this conversation as resolved.
with:
persist-credentials: false
- name: Install repository tools
uses: jdx/mise-action@v4.2.1
Comment thread
coderabbitai[bot] marked this conversation as resolved.
with:
cache: false
- name: Verify semantic conventions
run: mise run semconv:check

csharp-quality:
runs-on: ubuntu-latest
name: C# Quality
Expand Down Expand Up @@ -66,6 +81,10 @@ jobs:
- name: Verify C# formatting
run: |
./ci/csharp-format-changed.sh src/EventStore.sln "${{ steps.refs.outputs.base }}" "${{ steps.refs.outputs.head }}"
- name: Verify semantic convention package
run: |
dotnet pack --no-restore --configuration Release --output artifacts/packages \
src/TrogonEventStore.SemanticConventions/TrogonEventStore.SemanticConventions.csproj

vulnerability-scan:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[tools]
"github:open-telemetry/weaver" = "0.24.2"

[tasks."ui:dev"]
description = "Run a local file-backed node for Razor UI testing"
run = '''
Expand Down
1 change: 1 addition & 0 deletions otel/semconv/registry-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v1.43.0
13 changes: 13 additions & 0 deletions otel/semconv/templates/registry/csharp/attribute-names.cs.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// <auto-generated />

namespace TrogonEventStore.SemanticConventions
{
public static class AttributeNames
{
{% for group in ctx %}
{% for attribute in group.attributes %}
public const string {{ attribute.name | pascal_case }} = "{{ attribute.name }}";
{% endfor %}
{% endfor %}
}
}{{ "\n" }}
19 changes: 19 additions & 0 deletions otel/semconv/templates/registry/csharp/weaver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
whitespace_control:
trim_blocks: true
lstrip_blocks: true

templates:
- template: attribute-names.cs.j2
filter: >
semconv_grouped_attributes
| map({
root_namespace: .root_namespace,
attributes: [.attributes[] | select(
.name == "service.name" or
.name == "service.instance.id" or
.name == "service.version"
)]
})
| map(select(.attributes | length > 0))
application_mode: single
file_name: AttributeNames.g.cs
1 change: 1 addition & 0 deletions src/EventStore.Core/EventStore.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<ProjectReference Include="..\EventStore.Transport.Tcp\EventStore.Transport.Tcp.csproj" />
<ProjectReference Include="..\EventStore.NETCore.Compatibility\EventStore.NETCore.Compatibility.csproj" />
<ProjectReference Include="..\EventStore.SourceGenerators\EventStore.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\TrogonEventStore.SemanticConventions\TrogonEventStore.SemanticConventions.csproj" />
</ItemGroup>
<ItemGroup>
<Protobuf Include="..\Protos\ClientAPI\ClientMessageDtos.proto">
Expand Down
7 changes: 4 additions & 3 deletions src/EventStore.Core/Log/OpenTelemetryLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Serilog;
using Serilog.Filters;
using Serilog.Sinks.OpenTelemetry;
using TrogonEventStore.SemanticConventions;

namespace EventStore.Common.Log;

Expand Down Expand Up @@ -37,9 +38,9 @@ public static LoggerConfiguration AddOpenTelemetryLogger(
{
options.ResourceAttributes = new Dictionary<string, object>
{
["service.name"] = "eventstore",
["service.instance.id"] = componentName,
["service.version"] = VersionInfo.Version
[AttributeNames.ServiceName] = "eventstore",
[AttributeNames.ServiceInstanceId] = componentName,
[AttributeNames.ServiceVersion] = VersionInfo.Version
};
options.Protocol = otlpExporterConfig.Protocol switch
{
Expand Down
14 changes: 14 additions & 0 deletions src/EventStore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventStore.SystemRuntime.Te
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{CB56B2BD-5ABA-49C7-BD57-21B9CD5C3205}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrogonEventStore.SemanticConventions", "TrogonEventStore.SemanticConventions\TrogonEventStore.SemanticConventions.csproj", "{05D9513D-A26A-410A-A145-4A17548EB79C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -349,6 +351,18 @@ Global
{CA966906-51C8-4520-924E-988FA396B712}.Release|ARM64.Build.0 = Release|ARM64
{CA966906-51C8-4520-924E-988FA396B712}.Release|x64.ActiveCfg = Release|x64
{CA966906-51C8-4520-924E-988FA396B712}.Release|x64.Build.0 = Release|x64
{05D9513D-A26A-410A-A145-4A17548EB79C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Debug|ARM64.Build.0 = Debug|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Debug|x64.ActiveCfg = Debug|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Debug|x64.Build.0 = Debug|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Release|Any CPU.Build.0 = Release|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Release|ARM64.ActiveCfg = Release|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Release|ARM64.Build.0 = Release|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Release|x64.ActiveCfg = Release|Any CPU
{05D9513D-A26A-410A-A145-4A17548EB79C}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// <auto-generated />

namespace TrogonEventStore.SemanticConventions
{
public static class AttributeNames
{
public const string ServiceInstanceId = "service.instance.id";
public const string ServiceName = "service.name";
public const string ServiceVersion = "service.version";
}
}
5 changes: 5 additions & 0 deletions src/TrogonEventStore.SemanticConventions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# TrogonEventStore Semantic Conventions

This package gives TrogonEventStore components one generated source for OpenTelemetry attribute names. It has no runtime dependencies.

The pinned OpenTelemetry registry version and C# templates under `otel/semconv` are the source of truth. Regenerate the committed constants with `mise run semconv:generate` and verify them with `mise run semconv:check`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<VersionPrefix>0.1.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<IsPackable>true</IsPackable>
<PackageId>TrogonEventStore.SemanticConventions</PackageId>
<RootNamespace>TrogonEventStore.SemanticConventions</RootNamespace>
<AssemblyName>TrogonEventStore.SemanticConventions</AssemblyName>
<Authors>Straw Hat, LLC</Authors>
<Company>Straw Hat, LLC</Company>
<Copyright>Copyright Straw Hat, LLC</Copyright>
<Description>Shared OpenTelemetry semantic convention constants for TrogonEventStore components.</Description>
<PackageProjectUrl>https://github.com/TrogonStack/TrogonEventStore</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageTags>opentelemetry;semantic-conventions;weaver</PackageTags>
<RepositoryUrl>https://github.com/TrogonStack/TrogonEventStore</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\" />
<None Remove="..\..\ouro.png" />
</ItemGroup>
</Project>
Loading