Skip to content

Fix bug related to the crate tracing-test for writing assertions for logs #1430

Closed

Description

@josecelano

Relates to:

Some time ago I tried to use the tracing-test for writing assertions for logs. I could it use it because I had a bug described here:

#1148 (comment)

In the end, I decided to implement our own logging setup for testing, I copied part of the code from the tracing-test:

https://github.com/dbrgn/tracing-test/blob/main/tracing-test/src/subscriber.rs

That was included here:

https://github.com/torrust/torrust-tracker/blob/develop/packages/test-helpers/src/logging.rs

However I limited the buffer because I was planning to use it also in production.

I think I decided to copy because it gives us more control on the logging setup. If I remember well, the crate does its own initialization. And there's not much code.

One thing I could not make it work was using an span to identify logs for the tests we are writing the log assertions. It described on:

#1148 (comment)

We are using natural identifiers in the log lines to identify the logs related to the test we are running. For example the "request id".

@da2ce7 has opened an PR that might solve the problem. I guess we can test it adding a new test like this:

#[tokio::test]
async fn should_blab_bla() {
    logging::setup();

    let span = tracing::info_span!("unique scope");
    let _guard = span.enter();
    
    // test ...
    
    assert!(logs_contains_a_line_with(
        &["unique scope", "ERROR", "tower_http", "response failed"]
    ));    
}

It seems blocking functions could be the problem but I don't think so. As I mentioned in this comment I think the problem could be spans are not into the spawned threads when we run the test environments.

This is the PR opened by @da2ce7

I would keep our logging setup that gives us more flexibility but I would try to fix the problem using spans to identify logs for a tests.

cc @dbrgn

Activity

  1. added
    Testing
    on Apr 4, 2025
  2. self-assigned this
    on Aug 26, 2026
  3. josecelano commented on Aug 26, 2026

    @josecelano
    MemberAuthor

    Closing this as a documented decision, rather than implementing automatic test-span propagation.

    The tracker retains its repository-owned bounded test log capture helper and uses explicit identifiers selected by the test author, such as request IDs or info hashes, to associate expected records with assertions. This approach remains customizable and debuggable without requiring pervasive span propagation across the tracker's nested concurrent tasks.

    The decision, alternatives, and reopening criteria are recorded in ADR 20260826124959_use_explicit_identifiers_for_test_log_assertions.md (commit 87827cb1). We can reconsider the approach when a concrete logging-test requirement cannot be met using an explicit identifier.

  4. josecelano commented on Aug 26, 2026

    @josecelano
    MemberAuthor

    Correction: the earlier close used the wrong lifecycle and state reason. This issue is reopened and will remain open until the documentation PR containing ADR 20260826124959_use_explicit_identifiers_for_test_log_assertions.md is reviewed and merged. That PR will use Closes #1430, so GitHub records the decision and its rationale through the linked PR.

  5. added theissue type on Aug 26, 2026
  6. added a commit that references this issue on Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Testing

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions