opentelemetry-java-examples icon indicating copy to clipboard operation
opentelemetry-java-examples copied to clipboard

[Contribution idea] Example showing telemetry integration testing

Open Izzzu opened this issue 3 years ago • 1 comments

I would like to propose a contribution of a java code example that shows telemetry integration testing with MockServer library. This example could help users with testing their mission critical telemetry data in applications that use OpenTelemetry Agent.

Here’s the draft code showing the integration testing approach. The OpenTelemetry java agent is configured to use the OTLP exporter with http/protobuf protocol and uses the default exporter endpoint which is http://localhost:4318/. The telemetry collector web server is mocked with this endpoint using MockServer library. With MockServer library we can easily retrieve the recorded requests from the mocked collector and verify the traces and metrics.

Do you think such an example would be useful in opentelemetry-java-docs? Happy to hear your thoughts on this.

Izzzu avatar Sep 06 '22 15:09 Izzzu

hi @Izzzu, this looks very nice! we have more complicated testing infra at https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/testing-common, the primary advantage of that infra is that it allows writing assertions on the SpanData model instead of on the protobuf model, which allows you to use the custom opentelemetry sdk assertions provided in https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk/testing

I like your approach from a simplicity perspective, and I think it could be a nice addition in this repository until we work out the story for reusing the instrumentation repo infra in https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/4560 (and would love your thoughts over there if you are interested in exploring that)

trask avatar Sep 14 '22 18:09 trask

Hi @trask! I raised a PR some time ago. Happy to hear your feedback

Izzzu avatar Nov 16 '22 06:11 Izzzu