Zerolog and Vector example
This example demonstrates how to collect Zerolog logs with
Vector.
Because Zerolog does not support
context, we have to propagate
trace_id
and span_id
in the log message:
logger.Error().
// trace_id and span_id are needed to properly link the log message with the span.
Str("trace_id", child1.SpanContext().TraceID().String()).
Str("span_id", child1.SpanContext().SpanID().String()).
Str("foo", "bar").
Msg("message from zerolog")
That is not very convenient, so we recommend to use
Zap or
logrus instead.
Running this example
Step 1. Replace headers.uptrace-dsn
in vector.toml with your Uptrace DSN.
Step 2. Start Vector:
vector --config vector.toml
Step 3. Run the example:
UPTRACE_DSN="https://<token>@uptrace.dev/<project_id>" go run .
Click the link in your terminal to open Uptrace. See
Structured Logging for details.