Git Product home page Git Product logo

Comments (8)

krojew avatar krojew commented on July 29, 2024

After registering layers, you should call init().

tracing_subscriber::registry()
        .with(stdout_layer)
        .with(another_layer)
        .with(another_another_layer)
        .with(tracing_elastic_apm_layer)
        .init();       // you should call init here

from tracing-elastic-apm.

ufoscout avatar ufoscout commented on July 29, 2024

@krojew
Calling init() sets the subscriber as the global default one which is exactly what I don't want to do. This issue is indeed about the fact that the tracing-elastic-apm works when the subscriber is global but it does not work when using a default non-global one:

let _guard = tracing::subscriber::set_default(subscriber);

from tracing-elastic-apm.

krojew avatar krojew commented on July 29, 2024

What other layers you found working in such case?

from tracing-elastic-apm.

ufoscout avatar ufoscout commented on July 29, 2024

This is a small snippet of our real code:

        // Log to a file
        let file_appender = tracing_appender::rolling::never(dir, filename);
        let (non_blocking, guard) = tracing_appender::non_blocking(file_appender);
        let file_layer = Layer::new().with_ansi(false).with_writer(non_blocking);

        // Log to stdout
        let (non_blocking, stdout_guard) = tracing_appender::non_blocking(std::io::stdout());
        let stdout_layer = Layer::new().with_ansi(false).with_writer(non_blocking);

    let subscriber = tracing_subscriber::registry()
        .with(env_filter) // EnvFilter
        .with(file_layer) 
        .with(apm_layer)
        .with(stdout_layer);

everything works except the apm_layer.

from tracing-elastic-apm.

krojew avatar krojew commented on July 29, 2024

Can you try calling set_default() directly on subscriber, rather than tracing::subscriber::set_default(subscriber)?

from tracing-elastic-apm.

ufoscout avatar ufoscout commented on July 29, 2024

Tried, the issue is still present.

from tracing-elastic-apm.

krojew avatar krojew commented on July 29, 2024

After some investigation, it looks like https://docs.rs/tracing-subscriber/0.2.20/tracing_subscriber/fmt/struct.Layer.html works a bit differently than this crate. It's hard to tell if this is the reason, or if any of those two behaviors is wrong. If you use with_writer, everything that happens to spans gets converted to events and written to given writer (https://docs.rs/tracing-subscriber/0.2.20/src/tracing_subscriber/fmt/fmt_layer.rs.html#587). tracing-elastic-apm, on the other hand, distinguishes between events and spans, and sends span data only when a span gets closed.

Therefore we're left with some open questions:

  • Is this the reason for this behavior?
  • Is fmt::Layer implementation actually correct?

It's possible you found either a bug or undocumented behavior in tracing-subscriber. I'm not sure if there's anything I can do in this case.

from tracing-elastic-apm.

ufoscout avatar ufoscout commented on July 29, 2024

@krojew
After in-depth investigations, we found that the issue is not in this crate but, somehow, in tracing-actix-web that does not log the HTTP request info when the subscriber is not global.

from tracing-elastic-apm.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.