Today I had to make some changes to an existing ASP.NET Core application still using .NET 6 and a preview version of the OpenTelemetry.Extensions.Hosting nuget package.
I thought it was a good time to update to .NET 8 and to the latest OpenTelemetry version so updated both the targetframework and the used package versions.
After the changes my csproj
file looked like this:
However when I tried to compile and run my application I got the following error message:
'IServiceCollection' does not contain a definition for 'AddOpenTelemetryTracing' and no accessible extension method 'AddOpenTelemetryTracing' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)
Here is the code that caused the error:
Turns out that the OpenTelemetry API has changed quite significantly since the preview and that AddOpenTelemetryTracing
has been removed in favour of AddOpenTelemetry
since version 1.4.0.
If fixed the error by updating my code to the following:
More information
.NET Observability with OpenTelemetry - .NET | Microsoft Learn