#tracing #opentelemetry #faker #mock

fake-opentelemetry-collector

A Fake (basic) opentelemetry collector, useful to test what is collected opentelemetry

9 releases (5 breaking)

new 0.17.1 Feb 24, 2024
0.16.0 Dec 30, 2023
0.15.2 Feb 11, 2024
0.15.0 Nov 25, 2023
0.12.0 Jul 2, 2023

#182 in Testing

Download history 9/week @ 2023-11-11 4/week @ 2023-11-18 43/week @ 2023-11-25 10/week @ 2023-12-02 11/week @ 2023-12-09 10/week @ 2023-12-23 38/week @ 2023-12-30 1/week @ 2024-01-06 1/week @ 2024-01-13 1/week @ 2024-01-20 19/week @ 2024-01-27 6/week @ 2024-02-03 94/week @ 2024-02-10 169/week @ 2024-02-17

288 downloads per month

CC0 license

15KB
239 lines

fake-opentelemetry-collector

A Fake (basic) opentelemetry collector, useful to test what is collected opentelemetry

Usage example with insta (snapshot testing)

    #[tokio::test(flavor = "multi_thread")]
    async fn test_fake_tracer_and_collector() {
        let fake_collector = FakeCollectorServer::start()
            .await
            .expect("fake collector setup and started");
        let tracer = setup_tracer(&fake_collector).await;

        debug!("Sending span...");
        let mut span = tracer
            .span_builder("my-test-span")
            .with_kind(SpanKind::Server)
            .start(&tracer);
        span.add_event("my-test-event", vec![]);
        span.end();

        shutdown_tracer_provider();

        let otel_spans = fake_collector.exported_spans();
        //insta::assert_debug_snapshot!(otel_spans);
        insta::assert_yaml_snapshot!(otel_spans, {
            "[].start_time_unix_nano" => "[timestamp]",
            "[].end_time_unix_nano" => "[timestamp]",
            "[].events[].time_unix_nano" => "[timestamp]",
            "[].trace_id" => insta::dynamic_redaction(|value, _path| {
                assert2::let_assert!(Some(trace_id) = value.as_str());
                format!("[trace_id:lg{}]", trace_id.len())
            }),
            "[].span_id" => insta::dynamic_redaction(|value, _path| {
                assert2::let_assert!(Some(span_id) = value.as_str());
                format!("[span_id:lg{}]", span_id.len())
            }),
            "[].links[].trace_id" => insta::dynamic_redaction(|value, _path| {
                assert2::let_assert!(Some(trace_id) = value.as_str());
                format!("[trace_id:lg{}]", trace_id.len())
            }),
            "[].links[].span_id" => insta::dynamic_redaction(|value, _path| {
                assert2::let_assert!(Some(span_id) = value.as_str());
                format!("[span_id:lg{}]", span_id.len())
            }),
        });
    }

Dependencies

~11–23MB
~298K SLoC