Skip to content

Commit 183773e

Browse files
committed
chore: add nuget trusted publishing
1 parent 1a5a276 commit 183773e

17 files changed

Lines changed: 1328 additions & 1085 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ jobs:
2929
uses: actions/upload-artifact@v4
3030
with:
3131
name: build-output
32-
path: src/Otel4Vsix/bin/Release/
32+
path: src/CodingWithCalvin.Otel4Vsix/bin/Release/net48
3333
retention-days: 7

.github/workflows/publish.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717

1818
permissions:
1919
contents: write
20+
id-token: write
2021

2122
steps:
2223
- name: Checkout
@@ -57,5 +58,16 @@ jobs:
5758
./nupkg/*.nupkg
5859
./nupkg/*.snupkg
5960
61+
# Get a short-lived NuGet API key
62+
- name: NuGet login (OIDC → temp API key)
63+
uses: NuGet/login@v1
64+
id: login
65+
with:
66+
user: ${{ secrets.NUGET_USERNAME }}
67+
6068
- name: Push to NuGet
61-
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
69+
run: |
70+
Get-ChildItem ./nupkg/*.nupkg | ForEach-Object {
71+
dotnet nuget push $_.FullName --api-key ${{steps.login.outputs.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate
72+
}
73+
shell: pwsh

CLAUDE.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,51 @@ The library follows a static facade pattern for ease of use:
9494
- Builds and packs with that version
9595
- Creates GitHub release with changelog
9696
- Publishes to NuGet.org
97+
98+
---
99+
100+
## Gotchas & Known Issues
101+
102+
### Visual Studio Bundles OpenTelemetry and Microsoft.Extensions.*
103+
104+
**Problem:** Visual Studio 2022+ bundles its own versions of OpenTelemetry and Microsoft.Extensions.* libraries in `PublicAssemblies` and `CommonExtensions`. If your extension ships different versions, you'll get `MissingMethodException` or assembly binding failures.
105+
106+
**VS Bundled Versions (as of Dec 2025):**
107+
| Library | VS 2022 | VS 2026 |
108+
|---------|---------|---------|
109+
| OpenTelemetry | 1.9.0 | 1.12.0 |
110+
| Microsoft.Extensions.* | 9.0 | 9.0 |
111+
| System.Diagnostics.DiagnosticSource | 9.0 | 9.0 |
112+
113+
**Solution:**
114+
- Use OpenTelemetry 1.10.0 (compatible with 9.0 dependencies)
115+
- Do NOT use OpenTelemetry 1.14.0+ (requires DiagnosticSource 10.0)
116+
- Ship OpenTelemetry DLLs separately (not merged) so they're found before VS's copies
117+
118+
### ILRepack Breaks Protobuf Serialization
119+
120+
**Problem:** Using ILRepack with `Internalize="true"` corrupts protobuf serialization, causing OTLP backends to reject requests with "failed to parse OTLP request body".
121+
122+
**Solution:** Disable ILRepack entirely (`<ILRepackEnabled>false</ILRepackEnabled>`). Ship all OpenTelemetry assemblies as separate NuGet dependencies.
123+
124+
### OTLP SDK Does Not Auto-Append Signal Paths
125+
126+
**Problem:** When configuring `OtlpExporterOptions.Endpoint` programmatically, the OpenTelemetry .NET SDK does NOT automatically append signal-specific paths (`/v1/traces`, `/v1/metrics`, `/v1/logs`). All signals get sent to the same URL, causing HTTP 400 errors.
127+
128+
**Solution:** Manually append signal paths in `ConfigureOtlpExporter()` based on signal type:
129+
```csharp
130+
var signalPath = signalType switch
131+
{
132+
OtlpSignalType.Traces => "/v1/traces",
133+
OtlpSignalType.Metrics => "/v1/metrics",
134+
OtlpSignalType.Logs => "/v1/logs",
135+
_ => "/v1/traces"
136+
};
137+
endpoint = baseUrl.TrimEnd('/') + signalPath;
138+
```
139+
140+
### Google.Protobuf Must Flow as Dependency
141+
142+
**Problem:** If Google.Protobuf is merged via ILRepack or not available at runtime, protobuf serialization fails.
143+
144+
**Solution:** Reference Google.Protobuf as a regular NuGet dependency (not `PrivateAssets="all"`) so it flows to consumers and ships with the extension.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using System;
2+
using System.Diagnostics;
3+
using OtelTrace = OpenTelemetry.Trace;
4+
5+
namespace CodingWithCalvin.Otel4Vsix;
6+
7+
/// <summary>
8+
/// Extension methods for <see cref="Activity"/> that wrap OpenTelemetry functionality.
9+
/// These extensions allow consumers to use telemetry features without directly
10+
/// referencing OpenTelemetry namespaces.
11+
/// </summary>
12+
public static class ActivityExtensions
13+
{
14+
/// <summary>
15+
/// Records an exception on the activity.
16+
/// </summary>
17+
/// <param name="activity">The activity to record the exception on.</param>
18+
/// <param name="exception">The exception to record.</param>
19+
/// <returns>The activity for method chaining.</returns>
20+
public static Activity RecordException(this Activity activity, Exception exception)
21+
{
22+
if (activity == null || exception == null)
23+
{
24+
return activity;
25+
}
26+
27+
// Use the OpenTelemetry extension method via explicit call
28+
activity.AddException(exception);
29+
return activity;
30+
}
31+
32+
/// <summary>
33+
/// Sets the activity status to error with the specified message.
34+
/// </summary>
35+
/// <param name="activity">The activity to set the status on.</param>
36+
/// <param name="errorMessage">The error message.</param>
37+
/// <returns>The activity for method chaining.</returns>
38+
public static Activity SetErrorStatus(this Activity activity, string errorMessage)
39+
{
40+
if (activity == null)
41+
{
42+
return activity;
43+
}
44+
45+
activity.SetStatus(ActivityStatusCode.Error, errorMessage);
46+
return activity;
47+
}
48+
49+
/// <summary>
50+
/// Sets the activity status to OK.
51+
/// </summary>
52+
/// <param name="activity">The activity to set the status on.</param>
53+
/// <returns>The activity for method chaining.</returns>
54+
public static Activity SetOkStatus(this Activity activity)
55+
{
56+
if (activity == null)
57+
{
58+
return activity;
59+
}
60+
61+
activity.SetStatus(ActivityStatusCode.Ok);
62+
return activity;
63+
}
64+
65+
/// <summary>
66+
/// Records an exception and sets the activity status to error.
67+
/// </summary>
68+
/// <param name="activity">The activity.</param>
69+
/// <param name="exception">The exception to record.</param>
70+
/// <returns>The activity for method chaining.</returns>
71+
public static Activity RecordError(this Activity activity, Exception exception)
72+
{
73+
if (activity == null || exception == null)
74+
{
75+
return activity;
76+
}
77+
78+
activity.SetStatus(ActivityStatusCode.Error, exception.Message);
79+
activity.RecordException(exception);
80+
return activity;
81+
}
82+
}
Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project Sdk="Microsoft.NET.Sdk">
32

3+
<Project Sdk="Microsoft.NET.Sdk">
44
<PropertyGroup>
55
<TargetFramework>net48</TargetFramework>
66
<LangVersion>latest</LangVersion>
7-
<RootNamespace>Otel4Vsix</RootNamespace>
8-
<AssemblyName>Otel4Vsix</AssemblyName>
7+
<RootNamespace>CodingWithCalvin.Otel4Vsix</RootNamespace>
8+
<AssemblyName>CodingWithCalvin.Otel4Vsix</AssemblyName>
99
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1010

11-
<!-- NuGet Package Properties -->
1211
<PackageId>CodingWithCalvin.Otel4Vsix</PackageId>
13-
<Version>1.0.0</Version>
12+
<Version>0.0.15-local</Version>
1413
<Authors>Calvin A. Allen</Authors>
1514
<Company>Coding With Calvin</Company>
16-
<Product>Otel4Vsix</Product>
15+
<Product>CodingWithCalvin.Otel4Vsix</Product>
1716
<Description>OpenTelemetry support library for Visual Studio 2022+ extensions. Provides tracing, metrics, logging, and exception tracking capabilities.</Description>
1817
<PackageTags>OpenTelemetry;VisualStudio;VSIX;Telemetry;Tracing;Metrics;Logging</PackageTags>
1918
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -23,14 +22,10 @@
2322
<RepositoryUrl>https://github.com/CodingWithCalvin/Otel4Vsix</RepositoryUrl>
2423
<ProjectUrl>https://github.com/CodingWithCalvin/Otel4Vsix</ProjectUrl>
2524
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
26-
<IncludeSymbols>true</IncludeSymbols>
27-
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
2825

29-
<!-- Documentation -->
3026
<GenerateDocumentationFile>true</GenerateDocumentationFile>
3127
<NoWarn>$(NoWarn);CS1591</NoWarn>
3228

33-
<!-- SourceLink -->
3429
<PublishRepositoryUrl>true</PublishRepositoryUrl>
3530
<EmbedUntrackedSources>true</EmbedUntrackedSources>
3631
<DebugType>embedded</DebugType>
@@ -42,26 +37,13 @@
4237
</ItemGroup>
4338

4439
<ItemGroup>
45-
<!-- OpenTelemetry Core -->
46-
<PackageReference Include="OpenTelemetry" Version="1.7.0" />
47-
<PackageReference Include="OpenTelemetry.Api" Version="1.7.0" />
48-
49-
<!-- Exporters -->
50-
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0" />
51-
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0" />
52-
53-
<!-- Extensions -->
54-
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
55-
56-
<!-- Logging -->
57-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
58-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
59-
60-
<!-- Visual Studio SDK (optional integration) -->
61-
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.32112.339" />
62-
63-
<!-- SourceLink -->
64-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
40+
<PackageReference Include="OpenTelemetry" Version="1.10.0" />
41+
<PackageReference Include="OpenTelemetry.Api" Version="1.10.0" />
42+
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
43+
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.10.0" />
44+
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
45+
<PackageReference Include="Google.Protobuf" Version="3.22.5" />
46+
<PackageReference Include="Grpc.Core.Api" Version="2.52.0" />
47+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
6548
</ItemGroup>
66-
6749
</Project>

0 commit comments

Comments
 (0)