-
Notifications
You must be signed in to change notification settings - Fork 327
How to test/use correctly OpenCensus stats in an application using opencensus-go? #462
Comments
Yeah I have had the same complaint writing tests. I don't like all the global state we use, and there's a lot. We try to hide it all internally. Of course, this makes it very difficult to write tests against the library. I have a few suggestions:
|
Hello, I'm currently integrating OpenCensus too and I would also like a way to test. I have thought of two options :
WDYT ? |
@Kuqd and @slok, we recently added Reader and IntervalReader. You can call ReadAndExport. Does that help? |
I'm not the original poster, but I just tried ReadAndExport and it's working for me without the sleep. |
Hi!
First of all, I want to let you know that I'm new to OpenCensus so maybe I'm taking a bad approach :)
I'm trying to add OpenCensus
stats
as part of instrumentation to one of the libraries I maintain.I started getting familiar with some of the concepts and reading internal library code so I could create a OpenCensus
Recorder
on Kooper.The problem is that I would like to inject an OpenCensus "registry", "recorder" or similar (the name doesn't matter) object, and (I think that) OpenCensus works at global level
opencensus-go/stats/internal/record.go
Line 12 in 904befa
opencensus-go/stats/view/worker.go
Lines 28 to 32 in 904befa
opencensus-go/stats/view/worker.go
Lines 156 to 166 in 904befa
I've checked the tests of the worker and they work at the same package as the worker itself (
go.opencensus.io/stats/view
) so they can create new worker instances without problem, but outside the library that's not possible.opencensus-go/stats/view/worker_test.go
Lines 579 to 583 in 30bf88b
So, in other words, I can't decouple my code correctly, inject the dependencies and make each test to be idempotent and independent without small hacks like reset functions. Appart from this, working in global context I can't make my tests run in parallel.
I'm missing something or there is an established approach when using and testing opencensus-go in other applications?
Is there out there any Go application or library using OpenCensus and tested so I can read the code as an example? I did not found.
Thank you for your time and OSS contributions!
The text was updated successfully, but these errors were encountered: