| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
This is an example how to test the telemetry data using MockServer.
The example contains a simple SpringBoot application that exposes an API available at GET http://localhost:8080/ping
When the API is called, auto instrumentation from the OpenTelemetry Java Agent records traces and metrics.
The method doWork() in Controller class is annotated with the @WithSpan annotation which automatically generates the trace when the method is called. Counter meter apiCounter increments the metric on each API call.
Go to test folder and execute the test from ApplicationTest class.
ApplicationTest contains 1 test testTelemetry() which verifies that:
when the API was called.
Gradle build script contains a task to download the OpenTelemetry Java Agent jar, which is added to the jvm arguments in the test task.
Additionally, the OpenTelemetry is configured with properties:
The MockServer library is used to mock the collector web server. It's configured with port 4318, because for http/protobuf protocol, the otel exporter endpoint is by default set to http://localhost:4318.
The collector mock server is configured with expectation to reply with http code 200 on every request.
To verify that the telemetry was sent to the collector we retrieve the requests from the mock server and assert the traces and metrics names.
| Back | FazBrowse Home | New Git URL |