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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# If this file is renamed, the incrementing run attempt number will be reset.

name: CI

on:
push:
branches: [ "dev", "main" ]
pull_request:
branches: [ "dev", "main" ]

env:
CI_BUILD_NUMBER_BASE: ${{ github.run_number }}
CI_TARGET_BRANCH: ${{ github.head_ref || github.ref_name }}

jobs:
build:

# The build must run on Windows so that .NET Framework targets can be built and tested.
runs-on: windows-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v4
- name: Setup
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Compute build number
shell: bash
run: |
echo "CI_BUILD_NUMBER=$(($CI_BUILD_NUMBER_BASE+2300))" >> $GITHUB_ENV
- name: Build and Publish
env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
./Build.ps1
87 changes: 61 additions & 26 deletions Build.ps1
Original file line number Diff line number Diff line change
@@ -1,44 +1,79 @@
Write-Output "build: Tool versions follow"

dotnet --version
dotnet --list-sdks

Write-Output "build: Build started"

Push-Location $PSScriptRoot
try {
if(Test-Path .\artifacts) {
Write-Output "build: Cleaning ./artifacts"
Remove-Item ./artifacts -Force -Recurse
}

if(Test-Path .\artifacts) {
Write-Output "build: Cleaning ./artifacts"
Remove-Item ./artifacts -Force -Recurse
}
& dotnet restore --no-cache

& dotnet restore --no-cache
$dbp = [Xml] (Get-Content .\Directory.Version.props)
$versionPrefix = $dbp.Project.PropertyGroup.VersionPrefix

$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:APPVEYOR_REPO_BRANCH];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "main" -and $revision -ne "local"]
Write-Output "build: Package version prefix is $versionPrefix"

Write-Output "build: Package version suffix is $suffix"
$branch = @{ $true = $env:CI_TARGET_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:CI_TARGET_BRANCH];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:CI_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:CI_BUILD_NUMBER];
$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)) -replace '([^a-zA-Z0-9\-]*)', '')-$revision"}[$branch -eq "main" -and $revision -ne "local"]
$commitHash = $(git rev-parse --short HEAD)
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]

foreach ($src in Get-ChildItem src/*) {
Push-Location $src
Write-Output "build: Package version suffix is $suffix"
Write-Output "build: Build version suffix is $buildSuffix"

Write-Output "build: Packaging project in $src"
& dotnet build -c Release --version-suffix=$buildSuffix /p:ContinuousIntegrationBuild=true
if($LASTEXITCODE -ne 0) { throw "Build failed" }

if ($suffix) {
& dotnet pack -c Release --include-source -o ../../artifacts --version-suffix=$suffix
} else {
& dotnet pack -c Release --include-source -o ../../artifacts
foreach ($src in Get-ChildItem src/*) {
Push-Location $src

Write-Output "build: Packaging project in $src"

if ($suffix) {
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts --version-suffix=$suffix
} else {
& dotnet pack -c Release --no-build --no-restore -o ../../artifacts
}
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }

Pop-Location
}
if($LASTEXITCODE -ne 0) { throw "Packaging failed" }

Pop-Location
}
foreach ($test in Get-ChildItem test/*.Tests) {
Push-Location $test

Write-Output "build: Testing project in $test"

& dotnet test -c Release --no-build --no-restore
if($LASTEXITCODE -ne 0) { throw "Testing failed" }

Pop-Location
}

if ($env:NUGET_API_KEY) {
# GitHub Actions will only supply this to branch builds and not PRs. We publish
# builds from any branch this action targets (i.e. main and dev).

foreach ($test in Get-ChildItem test/*.Tests) {
Push-Location $test
Write-Output "build: Publishing NuGet packages"

Write-Output "build: Testing project in $test"
foreach ($nupkg in Get-ChildItem artifacts/*.nupkg) {
& dotnet nuget push -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json "$nupkg"
if($LASTEXITCODE -ne 0) { throw "Publishing failed" }
}

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { throw "Testing failed" }
if (!($suffix)) {
Write-Output "build: Creating release for version $versionPrefix"

iex "gh release create v$versionPrefix --title v$versionPrefix --generate-notes $(get-item ./artifacts/*.nupkg) $(get-item ./artifacts/*.snupkg)"
}
}
} finally {
Pop-Location
}

Pop-Location
13 changes: 11 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<Project>
<!-- Properties in this file are expected to be identical for all Serilog organization projects. If
a property value is project-specific, please record it in the CSPROJ file instead. -->
<Import Project="$(MSBuildThisFileDirectory)Directory.Version.props" />
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<SignAssembly>true</SignAssembly>
<!-- The condition is required to support BenchmarkDotNet -->
<SignAssembly Condition="Exists('$(MSBuildThisFileDirectory)assets/Serilog.snk')">true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)assets/Serilog.snk</AssemblyOriginatorKeyFile>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
</Project>
5 changes: 5 additions & 0 deletions Directory.Version.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<VersionPrefix>4.2.0</VersionPrefix>
</PropertyGroup>
</Project>
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Serilog.Sinks.OpenTelemetry [![Build status](https://ci.appveyor.com/api/projects/status/sqmrvw34pcuatwl5/branch/dev?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-opentelemetry/branch/dev) [![NuGet Version](https://img.shields.io/nuget/vpre/Serilog.Sinks.OpenTelemetry.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.OpenTelemetry/)
# Serilog.Sinks.OpenTelemetry&nbsp;[![Build status](https://github.com/serilog/serilog-sinks-opentelemetry/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/serilog/serilog-sinks-opentelemetry/actions)&nbsp;[![NuGet Version](https://img.shields.io/nuget/vpre/Serilog.Sinks.OpenTelemetry.svg?style=flat)](https://www.nuget.org/packages/Serilog.Sinks.OpenTelemetry/)

This Serilog sink transforms Serilog events into OpenTelemetry
`LogRecord`s and sends them to an OTLP (gRPC or HTTP) endpoint.
Expand Down Expand Up @@ -142,9 +142,9 @@ Serilog `LogEvent` | OpenTelemetry `LogRecord` |
`MessageTemplate` | `Attributes[ "message_template.text"]` | Requires `IncludedData. MessageTemplateText` (enabled by default) |
`MessageTemplate` (MD5) | `Attributes[ "message_template.hash.md5"]` | Requires `IncludedData. MessageTemplateMD5 HashAttribute` |
`Properties` | `Attributes` | Each property is mapped to an attribute keeping the name; the value's structure is maintained |
`SpanId` (`Activity.Current`) | `SpanId` | Requires `IncludedData.SpanId` (enabled by default) |
`SpanId` (`Activity.Current`) | `SpanId` | Requires `IncludedData.SpanIdField` (enabled by default) |
`Timestamp` | `TimeUnixNano` | .NET provides 100-nanosecond precision |
`TraceId` (`Activity.Current`) | `TraceId` | Requires `IncludedData.TraceId` (enabled by default) |
`TraceId` (`Activity.Current`) | `TraceId` | Requires `IncludedData.TraceIdField` (enabled by default) |

### Configuring included data

Expand All @@ -156,8 +156,8 @@ Log.Logger = new LoggerConfiguration()
.WriteTo.OpenTelemetry(options =>
{
options.Endpoint = "http://127.0.0.1:4317";
options.IncludedData: IncludedData.MessageTemplate |
IncludedData.TraceId | IncludedData.SpanId;
options.IncludedData: IncludedData.MessageTemplateTextAttribute |
IncludedData.SpecRequiredResourceAttributes;
})
.CreateLogger();
```
Expand Down
25 changes: 0 additions & 25 deletions appveyor.yml

This file was deleted.

5 changes: 2 additions & 3 deletions example/Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFramework>net9.0</TargetFramework>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.401",
"version": "9.0.200",
"allowPrerelease": false,
"rollForward": "latestFeature"
}
Expand Down
11 changes: 10 additions & 1 deletion serilog-sinks-opentelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5
ProjectSection(SolutionItems) = preProject
.gitattributes = .gitattributes
.gitignore = .gitignore
appveyor.yml = appveyor.yml
Build.ps1 = Build.ps1
LICENSE = LICENSE
README.md = README.md
assets\Serilog.snk = assets\Serilog.snk
global.json = global.json
Directory.Build.props = Directory.Build.props
Directory.Version.props = Directory.Version.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{7D0692CD-F95D-4BF9-8C63-B4A1C078DF23}"
Expand All @@ -27,6 +28,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "example", "example", "{CC7B
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "example\Example\Example.csproj", "{C45B5103-C0CE-40CB-ACB8-4ED17B81AB7B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{84C182D9-BA28-4E90-B505-1DB18EA1E6C8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{5809900F-4557-4B45-B01A-E3B5C0EB74B1}"
ProjectSection(SolutionItems) = preProject
.github\workflows\ci.yml = .github\workflows\ci.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -53,6 +61,7 @@ Global
{866A028E-27DB-49A0-AC78-E5FEF247C099} = {037440DE-440B-4129-9F7A-09B42D00397E}
{1D56534C-4009-42C2-A573-789CAE6B8AA9} = {7D0692CD-F95D-4BF9-8C63-B4A1C078DF23}
{C45B5103-C0CE-40CB-ACB8-4ED17B81AB7B} = {CC7B094D-FD20-4053-9749-F9098927CA5E}
{5809900F-4557-4B45-B01A-E3B5C0EB74B1} = {84C182D9-BA28-4E90-B505-1DB18EA1E6C8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {43C32ED4-D39A-4E27-AE99-7BB8C883833C}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
<PropertyGroup>
<Description>This Serilog sink transforms Serilog events into OpenTelemetry
logs and sends them to an OTLP (gRPC or HTTP) endpoint.</Description>
<VersionPrefix>4.1.1</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<!-- .NET Framework version targeting is frozen at these two TFMs. -->
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT'">net471;net462</TargetFrameworks>
<!-- Policy is to trim TFM-specific builds to `netstandard2.0`, `net6.0`,
all active LTS versions, and optionally the latest RTM version, when releasing new
major Serilog versions. -->
<TargetFrameworks>$(TargetFrameworks);net8.0;net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);net9.0;net8.0;net6.0;netstandard2.0</TargetFrameworks>
<PackageTags>serilog;sink;opentelemetry</PackageTags>
<PackageIcon>serilog-sink-nuget.png</PackageIcon>
<PackageProjectUrl>https://github.com/serilog/serilog-sinks-opentelemetry</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<RepositoryUrl>https://github.com/serilog/serilog-sinks-opentelemetry</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RootNamespace>Serilog</RootNamespace>
<PackageReadmeFile>README.md</PackageReadmeFile>
<LangVersion>12</LangVersion>
<NoWarn>CS8981</NoWarn>
</PropertyGroup>

Expand All @@ -31,15 +26,19 @@
<DefineConstants>$(DefineConstants);FEATURE_CWT_ADDORUPDATE;FEATURE_ACTIVITY;FEATURE_HALF;FEATURE_DATE_AND_TIME_ONLY;FEATURE_SYNC_HTTP_SEND;FEATURE_SOCKETS_HTTP_HANDLER</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<DefineConstants>$(DefineConstants);FEATURE_CWT_ADDORUPDATE;FEATURE_ACTIVITY;FEATURE_HALF;FEATURE_DATE_AND_TIME_ONLY;FEATURE_SYNC_HTTP_SEND;FEATURE_SOCKETS_HTTP_HANDLER</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net471' or '$(TargetFramework)' == 'net462' ">
<Using Include="System.Net.Http" />
</ItemGroup>

<ItemGroup>
<None Include="../../assets/serilog-sink-nuget.png" Pack="true" Visible="false" PackagePath="/" />
<None Include="../../README.md" Pack="true" Visible="false" PackagePath="/" />
<PackageReference Include="Google.Protobuf" Version="3.26.1" />
<PackageReference Include="Grpc.Net.Client" Version="2.62.0" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Google.Protobuf" Version="3.30.1" />
<PackageReference Include="Grpc.Net.Client" Version="2.70.0" />
<PackageReference Include="Serilog" Version="4.2.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.

using System.Diagnostics;
using OpenTelemetry.Proto.Common.V1;
using Serilog.Events;

namespace Serilog.Sinks.OpenTelemetry;

Expand Down Expand Up @@ -82,5 +84,11 @@ public enum IncludedData
/// Preserve the value of the <c>SourceContext</c> property, in addition to using it as the OTLP <c>InstrumentationScope</c> name. If
/// not specified, the <c>SourceContext</c> property will be omitted from the individual log record attributes.
/// </summary>
SourceContextAttribute = 128
SourceContextAttribute = 128,

/// <summary>
/// Include <see cref="StructureValue.TypeTag"/> as <c>$type</c> when converting event properties to
/// OTLP <see cref="AnyValue.KvlistValue"/> values.
/// </summary>
StructureValueTypeTags = 256,
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ ParentSpanIdPropertyName or
continue;
}

var v = PrimitiveConversions.ToOpenTelemetryAnyValue(property.Value);
var v = PrimitiveConversions.ToOpenTelemetryAnyValue(property.Value, includedData);
addAttribute(PrimitiveConversions.NewAttribute(property.Key, v));
}
}
Expand Down
Loading