Giter VIP home page Giter VIP logo

Comments (9)

ramosbugs avatar ramosbugs commented on June 12, 2024 1

Cloning the provider before passing it to set_tracer_provider works. Thanks again!

from opentelemetry-rust.

cijothomas avatar cijothomas commented on June 12, 2024

https://github.com/open-telemetry/opentelemetry-rust/blob/main/examples/tracing-jaeger/src/main.rs#L46 Could you see if this is what you are looking for?

from opentelemetry-rust.

ramosbugs avatar ramosbugs commented on June 12, 2024

@cijothomas: Thanks for the quick reply!

The use case here is FaaS/"serverless" (e.g., AWS Lambda). Specifically, we need a way to flush traces after a request completes, but before AWS Lambda freezes the container to wait for the next request (which may never come, in which case unflushed traces are lost). Prior to the 0.18 release, I would have called opentelemetry::global::tracer_provider().force_flush() here, but that's no longer possible.

Shutting down and registering a new tracing provider for each request seems like it would introduce a lot of unnecessary overhead, when we just need access to the force_flush method.

from opentelemetry-rust.

ramosbugs avatar ramosbugs commented on June 12, 2024

Also, I'm willing to contribute a PR to get this done once there's consensus on the API changes.

from opentelemetry-rust.

jtescher avatar jtescher commented on June 12, 2024

@ramosbugs how/where is the tracer provider being created in this case?

from opentelemetry-rust.

ramosbugs avatar ramosbugs commented on June 12, 2024

I'm using the following code when the Lambda process starts (i.e., from main), before it enters its request loop:

let batch = BatchSpanProcessor::builder(exporter, opentelemetry::runtime::Tokio)
  .with_max_queue_size(MAX_SPAN_QUEUE_SIZE)
  .build();

let provider = TracerProvider::builder()
  .with_span_processor(batch)
  .with_config(tracer_config)
  .build();

opentelemetry::global::set_tracer_provider(provider);

from opentelemetry-rust.

ramosbugs avatar ramosbugs commented on June 12, 2024

One possible solution is to impl<T> TracerProvider for Arc<T> where T: TracerProvider. Then, we can just pass a copy of the Arc<opentelemetry_sdk::trace::TracerProvider> to set_tracer_provider and maintain our own copy for access to force_flush.

I don't see anything that requires a mutable reference to the provider, so an Arc seems like it should work?

from opentelemetry-rust.

jtescher avatar jtescher commented on June 12, 2024

TracerProvider is already clone, so you don't need the Arc, you can pass a clone to set_tracer_provider directly 👍

from opentelemetry-rust.

ramosbugs avatar ramosbugs commented on June 12, 2024

Oh, I totally missed that! Thank you, I will confirm that this works and then close the issue or report back otherwise.

from opentelemetry-rust.

Related Issues (20)

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.