Manual setup of OpenTelemetry with/without Microsoft.Extensions.Hosting in a Console application
After seeing Aspire I have decided to see how OpenTelemetry, and i first created a console application following the docs on https://opentelemetry.io/docs/instrumentation/net/manual/.
However, when I tried to move it into an easier setup using the extensionsmethod available in OpenTelemetry.Extensions.Hosting i could not get it to work. I think I might just misunderstand something about how it works.
So I have this working console application, which outputs the Actitivy in the console:
I then tried using the Generic Host builder and it does not write the activity to the console:
Does anyone know why I don't see the Activity in the console output? Or maybe know how I should set the Generic Host example up?
1 Reply
Note: It does not seem to matter if I StartAsync or not, but I feel like that could be related to the issue I have.
I am also using the following imports:
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="OpenTelemetry" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.7.0-alpha.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0-alpha.1" />
Alright, I actually found the solution myself
I had forgotten to register my actitivy-source with the AddSource-method.
So it should have looked like this:
And It does apear to be neccesary to call StartAsync for OTL to listen to the Acitivy.
But if anyone has any suggestions to things I can improve / look into I would of course not mind that :)