opentelemetry.io icon indicating copy to clipboard operation
opentelemetry.io copied to clipboard

Document how to test that you're instrumenting traces correctly

Open cartermp opened this issue 3 years ago • 11 comments

Something I've seen come up a few times is: "How do I unit test that I'm adding the right attributes to a span?"

You can't test this with the tracing API because it doesn't give you access to this data. But you can depend on the "SDK trace API" in a language to get access to a read/write span.

This should probably be documented with an example in all the languages with stable tracing:

  • [ ] JS
  • [ ] Java
  • [ ] Go
  • [ ] .NET
  • [ ] Python
  • [x] Elixir
  • [ ] Ruby
  • [ ] C++

cartermp avatar Aug 18 '22 14:08 cartermp

Some specific things that would be covered:

  • How to establish a test harness with an in-memory exporter
  • Which packages to pull in to do this testing
  • Example of a simple bit of code that does a thing with otel tracing
  • Example of a test that tests that function that does the tracing

cartermp avatar Aug 18 '22 17:08 cartermp

@cartermp and I have been discussing this on the pollinators slack - I'm happy to write up some docs for Go if someone would be kind enough to point me to where they should live :)

wildefires avatar Aug 18 '22 17:08 wildefires

Put it in a subpage of https://opentelemetry.io/docs/instrumentation/go/, we can then still decide to move it somewhere else.

svrnm avatar Aug 18 '22 19:08 svrnm

I wrote a rough draft of I think what this issue is asking for in https://temporaryhack.com/blog/opentelemetry-testing, for elixir.

Happy to take some feedback on it, polish it, and submit it -- if it's what y'all are looking for.

akasprzok avatar Aug 27 '22 21:08 akasprzok

I wrote a rough draft of I think what this issue is asking for in https://temporaryhack.com/blog/opentelemetry-testing, for elixir.

Happy to take some feedback on it, polish it, and submit it -- if it's what y'all are looking for.

Can you put it as a (draft) PR here? makes the review easier for us.

svrnm avatar Aug 29 '22 08:08 svrnm

I wrote a rough draft of I think what this issue is asking for in https://temporaryhack.com/blog/opentelemetry-testing, for elixir. Happy to take some feedback on it, polish it, and submit it -- if it's what y'all are looking for.

Can you put it as a (draft) PR here? makes the review easier for us.

Done, submitted rough draft here

akasprzok avatar Aug 29 '22 20:08 akasprzok

Thanks @akasprzok - your doc is live!

cartermp avatar Sep 14 '22 05:09 cartermp

@cartermp: can we copy some of the content from elixir/erlang over to the other languages or is it too specific?

svrnm avatar Sep 14 '22 07:09 svrnm

The content can probably be copied over easily and tweaked as needed, but the code samples will be different since setting up a test harness can vary so wildly from language to language.

cartermp avatar Sep 14 '22 14:09 cartermp

Thank you all for making my first contribution such a fantastic experience!

akasprzok avatar Sep 14 '22 16:09 akasprzok