open-telemetry / opentelemetry-java-examples

https://opentelemetry.io
Apache License 2.0
199 stars 120 forks source link

[Contribution idea] Example showing telemetry integration testing #42

Closed Izzzu closed 1 year ago

Izzzu commented 2 years ago

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~ Pull Request 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.

trask commented 2 years ago

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)

Izzzu commented 1 year ago

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