Learn how to send your logs to Datadog with Roberto.
written by Roberto Huertas
shuttle logs --follow
, you will be able to see something like this:
As a disclaimer, I must say that I’m currently working at Datadog, so I’m a bit biased, but I’m also a huge fan of the product and I think it’s a great tool for developers 😅.Most of the time, the easiest way to send anything to the Datadog platform is by using the Datadog Agent, but in this case, as we cannot install it in any way, we will use a small library I created for the occasion called dd-tracing-layer, which happens to be using the Datadog HTTP API under the hood to send logs to the Datadog platform.
Shuttle will record anything your application writes to stdout, e.g. a tracing or log crate configured to write to stdout, or simply println!. By default, Shuttle will set up a global tracing subscriber behind the scenes.
You can check the Datadog docs for log collection and integrations if you want to learn more.Those solutions are generally great because they allow us to remove the burden of sending our logs to Datadog from our application, thus becoming the responsibility of the platform itself. If we could do something like that with Shuttle, it would be great. But, as we just mentioned, in the case of Shuttle, we don’t have access to the underlying infrastructure, so we need to find a way to send our logs to Datadog from our application. And that’s what we are going to try to do in this post.
shuttle-runtime
crate.
shuttle-datadog-logs
, but use the name you want.
Cargo.toml
file:
#[instrument]
macro to the hello_world
function and added a tracing::info!
and a tracing::debug!
log to it. We have also added an info log to the axum
function.
shuttle run
command, you should see none of our logs.
That’s ok, as we haven’t initialized a tracing subscriber yet.
axum
function looks like this:
Secrets.toml
file in the root of our project containing all the secrets, and it also supports having a Secrets.dev.toml
file for local development. You can learn more about this convention in the Shuttle Secrets documentation.
So, let’s create two files in the root of our project:
Remember to add these files to your .gitignore
file!
shuttle run
and go to http://localhost:8000
in your browser to see our “Hello, world!” message.
Alternatively, you can also use curl
to test the endpoint: