-
Notifications
You must be signed in to change notification settings - Fork 194
Add trace validation to testcontainer example #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d84f1c8
Add traces to testcontainer example
jaydeluca 97d9eee
hit tempo directly
jaydeluca 5c8344a
readme fix
jaydeluca f05426f
Merge branch 'main' into update-test
zeitlinger 9429007
Merge branch 'main' into update-test
zeitlinger bdde7d5
Merge branch 'main' into update-test
jaydeluca 7a50a8c
reformat
jaydeluca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,41 @@ | ||
| # Using Testcontainers | ||
|
|
||
| The provided code demonstrates how to use **Testcontainers** with **Grafana's LGTM stack** to test OpenTelemetry metrics in a Java application. Here's a step-by-step explanation: | ||
| The provided code demonstrates how to use **Testcontainers** with **Grafana's LGTM stack** to test OpenTelemetry metrics | ||
| in a Java application. Here's a step-by-step explanation: | ||
|
|
||
| 1. **Set Up the Testcontainers Environment**: | ||
|
|
||
| - The `@Testcontainers` annotation enables the Testcontainers extension for JUnit 5. | ||
| - The `@Container` annotation is used to define a `LgtmStackContainer` that runs the Grafana LGTM stack in a Docker container. | ||
| - The `@Testcontainers` annotation enables the Testcontainers extension for JUnit 5. | ||
| - The `@Container` annotation is used to define a `LgtmStackContainer` that runs the Grafana LGTM stack in a Docker | ||
| container. | ||
|
|
||
| 2. **Configure OpenTelemetry**: | ||
|
|
||
| - In the `@BeforeEach` method, system properties are set to configure the OpenTelemetry exporter to send metrics to the LGTM stack running in the container. | ||
| - In the `@BeforeEach` method, system properties are set to configure the OpenTelemetry exporter to send metrics to | ||
| the LGTM stack running in the container. | ||
|
|
||
| 3. **Run the Application**: | ||
|
|
||
| - The `OtelApp` class initializes OpenTelemetry and generates a custom metric (`sold_items`) with attributes (e.g., `tenant`). | ||
| - The `OtelApp` class initializes OpenTelemetry and generates a custom metric (`sold_items`) with attributes (e.g., | ||
| `tenant`) as well as a span representing the block the code. | ||
|
|
||
| 4. **Test the Metrics Export**: | ||
| 4. **Test Exporting Metrics and Traces**: | ||
|
|
||
| - The test method `testExportMetric` runs the application and queries the Prometheus endpoint in the LGTM stack to verify that the metric (`sold_items`) has been exported successfully. | ||
| - The `Awaitility` library is used to poll the Prometheus endpoint until the metric is found or a timeout occurs. | ||
| - The test method `testExportMetricsAndTraces` runs the application and queries the Prometheus and Tempo endpoints | ||
| in the LGTM stack to verify that the metric (`sold_items`) and span have been exported successfully. | ||
| - The `Awaitility` library is used to poll the endpoints until the telemetry is found or a timeout occurs. | ||
|
|
||
| 5. **Debugging with Grafana**: | ||
| - The test outputs the Grafana URL (`lgtm.getGrafanaHttpUrl()`) to the console, allowing you to manually inspect the metrics in the Grafana UI. | ||
|
|
||
| - The test outputs the Grafana URL (`lgtm.getGrafanaHttpUrl()`) to the console, allowing you to manually inspect the | ||
| telemetry in the Grafana UI if needed. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| 1. Start the test using `mvn test`. | ||
| 2. Check the console output for the Grafana URL. | ||
| 3. Open the Grafana UI, navigate to the Explore tab, and query the metrics. | ||
| 4. The test will pass if the metric is successfully exported and found in Prometheus. | ||
| 3. Open the Grafana UI, navigate to the Explore tab, and query the metrics or traces. | ||
| 4. The test will pass if the metric and span are successfully exported and found in Prometheus and Tempo. | ||
|
|
||
| This setup is useful for validating OpenTelemetry instrumentation and ensuring metrics are correctly exported to a monitoring system. | ||
| This setup is useful for validating OpenTelemetry instrumentation and ensuring metrics are correctly exported to a | ||
| monitoring system. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.