A crate providing a tracing-subscriber layer for formatting events so Datadog can parse them

Overview

Datadog Formatting Layer

A crate providing a tracing-subscriber layer for formatting events so Datadog can parse them.

Features

  • Provides a layer for tracing-subscriber
  • Generates parsable "logs" for datadog and prints them to stdout
  • Enables log correlation between spans and "logs" (see datadog docs)

Why not just tracing_subscriber::fmt().json() ?

The problem is, that datadog expects the "logs" to be in a specific (mostly undocumented) json format.

This crates tries to mimic this format.

Usage

Simple

use datadog_formatting_layer::DatadogFormattingLayer;
use tracing::info;
use tracing_subscriber::prelude::*;

tracing_subscriber::registry()
    .with(DatadogFormattingLayer)
    .init();

info!(user = "Jack", "Hello World!");

Running this code will result in the following output on stdout:

{
  "timestamp": "2023-06-21T10:36:50.364874878+00:00",
  "level": "INFO",
  "message": "Hello World user=Jack",
  "target": "simple"
}

With Opentelemetry

use datadog_formatting_layer::DatadogFormattingLayer;
use opentelemetry::{
    global,
    sdk::{
        propagation::TraceContextPropagator,
        trace::{RandomIdGenerator, Sampler},
    },
};
use opentelemetry_datadog::ApiVersion;
use tracing::{debug, error, info, instrument, warn};
use tracing_subscriber::{prelude::*, util::SubscriberInitExt};

// Just some otel boilerplate
global::set_text_map_propagator(TraceContextPropagator::new());

let tracer = opentelemetry_datadog::new_pipeline()
    .with_service_name("my-service")
    .with_trace_config(
        opentelemetry::sdk::trace::config()
            .with_sampler(Sampler::AlwaysOn)
            .with_id_generator(RandomIdGenerator::default()),
    )
    .with_api_version(ApiVersion::Version05)
    .with_env("rls")
    .with_version("420")
    .install_simple()
    .unwrap();

// Use both the tracer and the formatting layer
tracing_subscriber::registry()
    .with(DatadogFormattingLayer)
    .with(tracing_opentelemetry::layer().with_tracer(tracer))
    .init();

// Here no span exists
info!(user = "Jack", "Hello World!");
some_test("fasel");

// This will create a span and a trace id which is attached to the "logs"
#[instrument(fields(hello = "world"))]
fn some_test(value: &str) {
    // Here some span exists
    info!(ola = "salve", value, "Bla {value}");
}

When running this code with an datadog agent installed the logs will be sent to datadog and parsed there.

Otherwise the following output will be printed to stdout

{"timestamp":"2023-06-21T10:36:50.363224217+00:00","level":"INFO","message":"Hello World! user=Jack","target":"otel"}
{"timestamp":"2023-06-21T10:36:50.363384118+00:00","level":"INFO","message":"Bla fasel user=Jack ola=salve value=Fasel hello=world","target":"otel","dd.trace_id":0,"dd.span_id":10201226522570980512}
You might also like...
Error propagation tracing in Rust.

Propagate Error propagation tracing in Rust. Why Propagate? Being able to trace the cause of an error is critical for many types of software written i

A tracing profiler for the Sega MegaDrive/Genesis
A tracing profiler for the Sega MegaDrive/Genesis

md-profiler, a tracing profiler for the Sega MegaDrive/Genesis This program, meant to be used with this fork of BlastEm, helps you finding bottlenecks

A patch to fix tracing LocalTime problem.

tracing-local-time A patch to fix tracing LocalTime problem. Tracing-subscriber now has a bug in LocalTime, so build ourselves' to fix it. In this pat

An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)
An example of a fairing for rocket to use tracing (as this pops up at many places in dicussions and questions)

Rocket Tracing Fairing Example This repository aims to give a short example of how you can add a Fairing to your Rocket for tracing and how to use it

A dynamic binary tracing tool

Backlight Backlight is a dynamic binary tracing tool. Install $ git clone [email protected]:JoshMcguigan/backlight.git $ cd backlight $ cargo install-b

tracing - a framework for instrumenting Rust programs to collect structured, event-based diagnostic information

tracing-appender Writers for logging events and spans Documentation | Chat Overview tracing is a framework for instrumenting Rust programs to collect

Middlewares and tools to integrate axum + tracing + opentelemetry

axum-tracing-opentelemetry Middlewares and tools to integrate axum + tracing + opentelemetry. Read OpenTelemetry header from incoming request Start a

A rust `tracing` compatible framework inspired by log4rs.

trace4rs This crate allows users to configure output from tracing in the same way as you would configure the output of log4rs. Overview For a usage ex

A convenient tracing config and init lib, with symlinking and local timezone.
A convenient tracing config and init lib, with symlinking and local timezone.

clia-tracing-config A convenient tracing config and init lib, with symlinking and local timezone. Use these formats default, and can be configured: pr

Releases(v1.0.1)
Owner
Open Schnick
Professional Netrunner in Night City
Open Schnick
AWS Cloudwatch layer for tracing-subscriber

tracing-cloudwatch tracing-cloudwatch is a custom tracing-subscriber layer that sends your application's tracing events(logs) to AWS CloudWatch Logs.

ymgyt 7 May 14, 2023
Utilities for integrating Datadog with opentelemetry + tracing in rust

Non-official datadog tracing and log correlation for Rust services. This crate contains the necessary glue to bridge the gap between OpenTelemetry, tr

willbank 5 Oct 31, 2023
Tracing layer to quickly inspect spans and events

tracing-texray First, a word of warning: This is alpha software. Don't run this in prod or anywhere where a panic would ruin your day. tracing-texray

Russell Cohen 23 Dec 3, 2022
Emit ETW events in tracing-enabled Rust applications.

tracing-etw Emit ETW events in tracing-enabled Rust applications. This crate depends on rust_win_etw. There are four ETW events. fn NewSpan(span_id: u

Microsoft 11 Aug 10, 2022
A tracing layer for macOS/iOS's `oslog`

tracing_oslog This is a tracing layer for the Apple OS logging framework. Activities are used to handle spans, Example use tracing_oslog::OsLogger; l

Lucy 12 Dec 6, 2022
mach-dump can parse Mach-O core dumps taken with lldb from macOS and iOS devices.

mach-dump mach-dump can parse Mach-O core dumps taken with lldb from macOS and iOS devices. It has no external dependencies. Example use std::path::Pa

Tobi 8 Sep 16, 2022
Create virtual serial ports, connect them to physical serial ports, and create routes between them all.

Virtual Serial Port Router (vsp-router) Create virtual serial ports, connect them to physical serial ports, and create routes between them all. vsp-ro

Rob Donnelly 3 Nov 24, 2022
This crate bridges between gstreamer and tracing ecosystems.

This crate provides a bridge between gstreamer and the tracing ecosystem. The goal is to allow Rust applications utilizing GStreamer to better integra

Standard Cognition OSS 17 Jun 7, 2022
Rust Hardware Abstraction Layer (HAL) crate for the Vorago VA108xx family of MCUs

HAL for the Vorago VA108xx MCU family This repository contains the Hardware Abstraction Layer (HAL), which is an additional hardware abstraction on to

Institute of Space Systems 0 Dec 22, 2021
Various extention traits for providing asynchronous higher-order functions

async-hofs Various extention traits for providing asynchronous higher-order functions. // This won't make any name conflicts since all imports inside

かわえもん 5 Jun 28, 2022