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

trace: exporter for unit testing #293

Open
semistrict opened this issue Jan 5, 2018 · 5 comments
Open

trace: exporter for unit testing #293

semistrict opened this issue Jan 5, 2018 · 5 comments
Milestone

Comments

@semistrict
Copy link
Contributor

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

@rakyll rakyll added this to the R2 milestone Jan 5, 2018
@semistrict
Copy link
Contributor Author

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

@rakyll
Copy link
Contributor

rakyll commented Jan 5, 2018

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.

@atrakh
Copy link

atrakh commented Jul 20, 2018

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?

@semistrict
Copy link
Contributor Author

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.

@henrahmagix
Copy link

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.

view.Unregister(v) // trigger exporting

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 =)

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

5 participants