opencensus-go icon indicating copy to clipboard operation
opencensus-go copied to clipboard

trace: exporter for unit testing

Open semistrict opened this issue 6 years ago • 5 comments

Supply a trace.Exporter useful for testing that just collects all spans and events in memory for later validation.

semistrict avatar Jan 05 '18 22:01 semistrict

We will probably need similar things for stats and tag so maybe we should collect all these under a single mocks package.

semistrict avatar Jan 05 '18 22:01 semistrict

Adding it to R2 for now, we will move it to R3 if we can't deliver.

The Go style is having the testing packages near the actual package, see net/http and net/http/httptest. We should have a trace/tracetest and stats/statstest.

Not sure if we need to provide anything for the tag package for testing.

rakyll avatar Jan 05 '18 22:01 rakyll

Hi there!

I've been working on implementing OpenCensus, and would like to unit test to make sure metrics are being sent over to exporters correctly. Has there been any traction on this?

atrakh avatar Jul 20 '18 19:07 atrakh

Not that I know of. I think partially the reason is that the interface is so simple to implement that most people just create an implementation themselves in test code.

semistrict avatar Jul 20 '18 19:07 semistrict

the interface is so simple to implement

This is true, but there's another part required to trigger the exporter, which I didn't realise until just now after looking through the test code here: it's best to unregister the view to trigger the exporting. https://github.com/census-instrumentation/opencensus-go/blob/7c764632b5a454dfa7c14e9ad2bf05218fceeedf/plugin/ochttp/route_test.go#L53

Before, I was trying to trigger exporting with view.SetReportingPeriod(), but then you must also time.Sleep() for a duration longer than the reporting period, and the exporter will be called every time the reporting time passes, rather than just once with the above method.

I'd love it if such a test exporter would automatically do this, or some variant, so the test doesn't have to trigger exporting =)

henrahmagix avatar Oct 22 '18 09:10 henrahmagix