2

I am using OpenCensus as recommended by Google Cloud to run StackDriver Trace (https://cloud.google.com/trace/docs/setup/java). My configuration is running on Google App Engine Standard Java 8. I have ensure the API is enabled on the project, used the initialization code and have created spans where I am trying to trace.

I simply create the span with

Span span = tracer.spanBuilder(spanName).startSpan();

and then finish it with

span.end();

It seems straight forward but none of my custom traces were visible in the Google Cloud Trace console, only the default RPC calls traced by Google. I then tried using Scopes instead of Span, initializing StackdriverTraceExporter with and without the project name, but nothing results in creating the custom traces.

Any guidance or suggestion on where to look would be greatly appreciated as this is the first time I am using OpenCensus.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
Brian Bauman
  • 1,000
  • 1
  • 9
  • 23
  • I have also tried to use the opencensus-exporter-trace-logging dependency instead of Stack Driver but that is not showing spans in the logs. I am not sure what I might be missing as I initialize the OpenCensus framework, get the Tracer, start the span with a name, then end the span. – Brian Bauman Aug 27 '18 at 15:01
  • Maybe, it is missing from the documentation. But, from which doc you are advised to call "span.end();" ? I didn't see that in the [documentation](https://cloud.google.com/trace/docs/setup/java). If you just follow the doc, let's see if you can see your custom traces in Google Cloud Trace console. – mehdi sharifi Aug 30 '18 at 23:27
  • This should work now. See the example here https://stackoverflow.com/questions/56278381/tracing-second-generation-java-app-engine – alexamies Jun 28 '19 at 00:25
  • This should work now. See the example [here](https://stackoverflow.com/questions/56278381/tracing-second-generation-java-app-engine/56799694#56799694). – alexamies Jun 28 '19 at 00:26

1 Answers1

3

I found that OpenCensus has a 5 seconds delay before flushing its cache to write to the exporter location. This means to get the traces to show up, you have to keep the thread alive for at least 5 seconds. The issue I had is in a multithreaded environment, the Threads were dying too fast.

OpenCensus is proposing a chance to that will allow you to pro grammatically flush the cache which will allow developers to flush the cache prior to returning the response which should ensure span data is written out reliably.

Brian Bauman
  • 1,000
  • 1
  • 9
  • 23
  • Did you get a solution to this? I too am trying to get custom spans to show up on GAE Standard (Java), with no luck. Using version 0.12.2 of OpenCensus (as advised on the Google Java setup page). – markvgti Apr 12 '19 at 06:57
  • 1
    I did not find a solution, I went back to the deprecated logging for GAE – Brian Bauman Apr 16 '19 at 02:48
  • 1
    Thanks for your reply. There was some mention of adding the capability to manually flush to Stackdriver Trace. Did that ever happen (can't find it anywhere)? – markvgti Apr 16 '19 at 06:33