Google Cloud Tracing in a .net 6 (or at least .net core 3+) Console App

773 Views Asked by At

I've been trying to implement Cloud Trace in a .net 6 Console App that works as a listener for events coming through a Publisher Subscriber pattern. I have been following Googles docs for their Diagnostics NuGet https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest but to no success. When I apply this on a WebAPI project it works like a charm but using this on the Console App posts nothing to GCP Cloud Trace. I'm trying to use the IManagedTracer.StartSpan() method to force the code to start a trace span and send something to GCP but nothing happens. No error and no trace. I've also tried doing this using the https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest which from what I understood looking at the code of its basically the underlying lib of the Google.Cloud.Diagnostics.AspNetCore which wraps that stuff and sets some extra stuff through IOC.

Anyone knows of any sample projects using Google Cloud trace and .net? Or if I'm clearly missing something basic?

Just for context... I'm running this locally connected to the project on GCP using the projectId hardcoded and with my account authenticated on my machine and with Owner Role assigned to it so permissions should not be an issue. My machine can post traces because I've successfully pushed traces from a sample WebAPI I did to test this out first.

1

There are 1 best solutions below

0
On BEST ANSWER

https://github.com/googleapis/google-cloud-dotnet/issues/6367#issuecomment-903852079 This github thread pretty much answers my question and provides a solution for this.

The Google packages do not support Console apps out of the box so we have to do some work to setup the tracing manually in the code.