Eliza Weisman bfd6802570
subscriber, serde: add valuable support to the JSON formatter (#1862)
This branch introduces support for `valuable` in `tracing-subscriber`'s
JSON formatter, and in `tracing-serde`, using the `valuable-serde`
bridge.

This allows the `fmt::Json` subscriber to actually record `valuable`
values as structured JSON. Here's an example, where a field is first
recorded using `fmt::Debug`, and then again using `field::valuable`:

```
:; RUSTFLAGS="--cfg tracing_unstable" cargo run --example valuable_json | jq
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/examples/valuable_json`
{
  "timestamp": "2022-01-25T21:36:30.729658Z",
  "level": "INFO",
  "fields": {
    "valuable": false,
    "user": "User { name: \"Arwen Undomiel\", age: 3000, address: Address { country: \"Middle Earth\", city: \"Rivendell\", street: \"leafy lane\" } }"
  },
  "target": "valuable_json"
}
{
  "timestamp": "2022-01-25T21:36:30.729720Z",
  "level": "INFO",
  "fields": {
    "valuable": true,
    "user": {
      "name": "Arwen Undomiel",
      "age": 3000,
      "address": {
        "country": "Middle Earth",
        "city": "Rivendell",
        "street": "leafy lane"
      }
    }
  },
  "target": "valuable_json"
}
```

As a side note, this branch also nicely validates that recording `Valuable`
values from a subscriber is actually possible, which the previous valuable PR
didn't have an example of. 

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-02-03 22:27:41 +00:00
..

Tracing Examples

This directory contains a collection of examples that demonstrate the use of the tracing ecosystem:

  • tracing:
    • counters: Implements a very simple metrics system to demonstrate how subscribers can consume field values as typed data.
    • sloggish: A demo Subscriber implementation that mimics the output of slog-term's Compact formatter.
  • tracing-attributes:
    • attrs-basic: A simple example of the #[instrument] attribute.
    • attrs-literal-field-names: Demonstrates using literal field names rather than rust tokens..
    • attrs-args: An example implementing a simple recursive calculation of Fibonacci numbers, to demonstrate how the #[instrument] attribute can record function arguments.
  • tracing-subscriber:
    • fmt: Demonstrates the use of the fmt module in tracing-subscriber, which provides a subscriber implementation that logs traces to the console.
    • fmt-stderr: Demonstrates overriding the output stream used by the fmt subscriber.
    • fmt-custom-field: Demonstrates overriding how the fmt subscriber formats fields on spans and events.
    • fmt-custom-event: Demonstrates overriding how the fmt subscriber formats events.
    • fmt-multiple-writers.rs: demonstrates how fmt::Layer can write to multiple destinations (in this instance, stdout and a file) simultaneously.
    • fmt-source-locations.rs: demonstrates displaying source code locations with fmt::Layer.
    • subscriber-filter: Demonstrates the tracing-subscriber::filter module, which provides a layer which adds configurable filtering to a subscriber implementation.
    • tower-load: Demonstrates how dynamically reloadable filters can be used to debug a server under load in production.
    • journald: Demonstrates how to use fmt and journald layers to output to both the terminal and the system journal.
    • toggle-layers : Demonstrates how Layers can be wrapped with an Option allowing them to be dynamically toggled.
  • tracing-futures:
    • spawny-thing: Demonstrates the use of the #[instrument] attribute macro asynchronous functions.
    • tokio-spawny-thing.rs: Similar to spawny-thingy, but with the additional demonstration instrumenting concurrent tasks created with tokio::spawn.
    • futures-proxy-server: Demonstrates the use of tracing-futures by implementing a simple proxy server, based on this example from tokio.
    • async_fn: Demonstrates how asynchronous functions can be instrumented.
    • echo: Demonstrates a tracing-instrumented variant of Tokio's echo example.
  • tracing-flame:
    • infero-flame: Demonstrates the use of tracing-flame to generate a flamegraph from spans.
  • tracing-tower:
    • tower-client: Demonstrates the use of tracing-tower to instrument a simple tower HTTP/1.1 client.
    • tower-server: Demonstrates the use of tracing-tower to instrument a simple tower HTTP/1.1 server.
  • tracing-serde:
    • serde-yak-shave: Demonstrates the use of tracing-serde by implementing a subscriber that emits trace output as JSON.
  • tracing-log:
    • hyper-echo: Demonstrates how tracing-log can be used to record unstructured logs from dependencies as tracing events, by instrumenting this example from hyper, and using tracing-log to record logs emitted by hyper.
  • tracing-opentelemetry:
    • opentelemetry: Demonstrates how tracing-opentelemetry can be used to export and visualize tracing span data.
    • opentelemetry-remote-context: Demonstrates how tracing-opentelemetry can be used to extract and inject remote context when traces span multiple systems.