| Crates.io | opentelemetry-testing |
| lib.rs | opentelemetry-testing |
| version | 0.1.0 |
| created_at | 2025-10-02 05:31:38.173943+00 |
| updated_at | 2025-10-02 05:31:38.173943+00 |
| description | A library for testing OpenTelemetry integrations with tracing, metrics, and logging. |
| homepage | https://github.com/jdrouet/opentelemetry-testing |
| repository | https://github.com/jdrouet/opentelemetry-testing |
| max_upload_size | |
| id | 1863895 |
| size | 92,689 |
This project provides a testing framework for OpenTelemetry instrumentation, enabling you to validate and debug your telemetry setup. It includes utilities for setting up an OpenTelemetry Collector, exporting traces, and verifying telemetry data.
testcontainers to spin up an OpenTelemetry Collector for testing.testcontainers)Add this crate to your Cargo.toml:
[dependencies]
opentelemetry-testing = "0.1.0"
Use the OpenTelemetryBuilder to configure and install OpenTelemetry providers:
let builder = OpenTelemetryBuilder {
otel_collector_endpoint: "http://127.0.0.1:4317".into(),
otel_internal_level: "off".into(),
};
let provider = builder.build().unwrap();
provider.install().unwrap();
The ObservabilityContainer struct simplifies setting up an OpenTelemetry Collector for testing:
#[tokio::test]
async fn test_traces() {
let container = ObservabilityContainer::create().await;
let provider = container.install().await;
// Your test logic here
provider.flush();
let traces = container.json_traces();
assert!(traces.resource_spans.len() > 0);
}
You can parse and validate traces exported to a file:
let traces = container.json_traces();
let scope_span = traces.find_scope_span("my-instrumentation");
assert!(scope_span.is_some());
The OpenTelemetry Collector is configured using the otelcol-config.yml file. By default, it exports traces to a JSON file at /tmp/output/traces.json.
Example configuration:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
exporters:
file/traces:
path: /tmp/output/traces.json
format: json
service:
pipelines:
traces:
receivers: [otlp]
exporters: [file/traces]
Run the tests using cargo:
cargo test
Ensure your code is formatted:
cargo fmt
Check for common issues:
cargo clippy
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.