Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

No Trace output when running example with Logging Exporter #1387

Closed
briantq opened this issue Aug 27, 2018 · 7 comments
Closed

No Trace output when running example with Logging Exporter #1387

briantq opened this issue Aug 27, 2018 · 7 comments

Comments

@briantq
Copy link

briantq commented Aug 27, 2018

Please answer these questions before submitting a bug report.

What version of OpenCensus are you using?

0.15

What JVM are you using (java -version)?

1.8.0_162

What did you do?

If possible, provide a recipe for reproducing the error.

I am running the MultiSpansTracing.java example. I am using the logging exporter.

`
io.opencensus
opencensus-api
${opencensus.version}

    <dependency>
        <groupId>io.opencensus</groupId>
        <artifactId>opencensus-impl</artifactId>
        <version>${opencensus.version}</version>
    </dependency>

    <dependency>
        <groupId>io.opencensus</groupId>
        <artifactId>opencensus-exporter-trace-logging</artifactId>
        <version>${opencensus.version}</version>
    </dependency>`

What did you expect to see?

When I ran the project, I expected to see some indication in System.out to denote entering/leaving/or general interaction with the span or annotations that were referenced in code.

What did you see instead?

System.out was empty.

This could be my misunderstanding of OpenCensus but it seems that using the Logging exporter should write trace information into System.out. If that is not the expected output location, please let me know.

@songy23
Copy link
Contributor

songy23 commented Aug 27, 2018

Hi @briantq , please note that in Java Spans are exported every 5 seconds, and by now there's no flushing mechanism for Span exporting yet. If you can wait for >5s before exiting the main thread (like what we did in the helloworld example), I believe you would see some Spans printed to console.

FYI there's one issue about making the exporting interval configurable (#1304), and one for adding a flushing for exporting (census-instrumentation/opencensus-specs#126).

@mayurkale22
Copy link
Member

@briantq By default, OpenCensus provides a probabilistic sampler that will trace once in every 10,000 requests (https://github.com/census-instrumentation/opencensus-java/blob/master/api/src/main/java/io/opencensus/trace/config/TraceParams.java#L50).

You can set a custom probablistic sampler, prefer to always sample or not sample at all. There are two ways to set samplers:

  1. Global sampler: Global sampler is the global default.
    Example:
// For demo/test purposes, lets always sample.
TraceConfig traceConfig = Tracing.getTraceConfig();
traceConfig.updateActiveTraceParams(
    traceConfig.getActiveTraceParams().toBuilder().setSampler(Samplers.alwaysSample()).build());
  1. Span sampler: When starting a new span, a custom sampler can be provided.
    Example:
    Span rootSpan = tracer.spanBuilderWithExplicitParent("MyRootSpan", null).setSampler(Samplers.alwaysSample()).startSpan();

I will create a PR to add this into examples.

@briantq
Copy link
Author

briantq commented Aug 27, 2018

Combining both of those did output the trace information. Thank you @mayurkale22 and @songy23!

In addition to adding the Sampler to the example, you probably want to include the delay also.

While I have you, I was running this example to try to validate some code I was writing on Google App Engine and exporting to StackDriver through the exporter. None of my traces were coming through (https://stackoverflow.com/questions/52033621/opencensus-not-show-traces-on-google-app-engine-in-stack-driver). I did overwrite the Sampler to set it to sample always, but was not seeing any of my traces in StackDriver. I am wondering if there might be an issue with the timeout...

I can definitely open a new issue (since it is a different problem), but if one of you guys knew off hand, I would save the extra time triaging new issues.

@songy23
Copy link
Contributor

songy23 commented Aug 27, 2018

@briantq Could you try running the code example on your local workstation and see if the traces were successfully uploaded to Stackdriver Trace? We'd like to see if this issue is specific to GAE.

Potential reasons I can think of:

  1. Main thread exits before SpanData are exported?
  2. Cloud credentials are not set up correctly?

@briantq
Copy link
Author

briantq commented Aug 27, 2018

@songy23 Should I open another issue to discuss or should we continue here?

Do you have a code example for Google App Engine? If I understand correctly, Google App Engine simplifies the configuration for StackDriver, though I have tried it both with and without specifying the project. I also checked to make sure the Trace API was enabled for the project. Additionally, I am seeing RCP calls to CloudDatastore and such so believe OpenCensus CAN write to the project.

Maybe there is something with the multithreaded nature not flushing the span prior to the end of the request? If that is the case, I am curious how the Google Cloud SDK creates spans that show up in StackDriver.

@songy23
Copy link
Contributor

songy23 commented Aug 27, 2018

Should I open another issue to discuss or should we continue here?

That would be better, please open a new issue on this and we can continue discussion there.

Do you have a code example for Google App Engine?

I'm not quite familiar with GAE configuration, though I think the exporting should work the same way with default RPC calls. Or maybe it's because you're interacting with the appengine context "com.google.apphosting.api.CloudTrace" (not supported yet, see #989)?

@songy23
Copy link
Contributor

songy23 commented Aug 27, 2018

Closing - the GAE-Stackdriver Trace issue is tracked in #1391.

@songy23 songy23 closed this as completed Aug 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants