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

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.



Solution 1:[1]

You are rendering all three routers at the same time, and the third one includes the Navbar component, which is also always rendered. You should use a single router to render all the routes. If you want different layouts for specific routes then you can use a wrapper component to render the Navbar. Render the last set of routes into a generic route that matches anything not more specifically matched, along with the Navbar.

function App() {
  return (
    <>
      <Router>
        <Routes>
          <Route path="/" element={<CirclePage />} />
          <Route path="/homepage-clubs" element={<HomepageClubs />} />
          <Route
            path="*"
            element={
              <>
                <Navbar />
                <Routes>
                  <Route path="/homepage" element={<Homepage />} />
                  <Route path="/events" element={<Events />} />
                  <Route path="/clubs" element={<Clubs />} />
                  <Route path="/notifications" element={<Notifications />} />
                  <Route path="/profile" element={<Profile />} />
                </Routes>
              </>
            }
          />
        </Routes>
      </Router>
    </>
  );
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Drew Reese