Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ Project versioning information and stability guarantees can be found

## Getting Started

If you are new to OpenTelemetry, start with the [Stdout
Example](./opentelemetry-stdout/examples/basic.rs). This example demonstrates
how to use OpenTelemetry for logs, metrics, and traces, and display
telemetry data on your console.
If you are new to OpenTelemetry, start with the getting started examples for
[logs](./examples/logs-basic/README.md),
[metrics](./examples/metrics-basic/README.md) or
[traces](./examples/tracing-grpc/README.md). This example demonstrates how to
use OpenTelemetry for logs, metrics, and traces, and display telemetry data on
your console.

For those using OTLP, the recommended OpenTelemetry Exporter for production
scenarios, refer to the [OTLP Example -
Expand Down
51 changes: 42 additions & 9 deletions examples/logs-basic/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,50 @@
# OpenTelemetry Log Appender for tracing - Example
# Getting started with OpenTelemetry Rust Logging

This example shows how to use the opentelemetry-appender-tracing crate, which is a
[logging
appender](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#log-appender--bridge)
that bridges logs from the [tracing crate](https://tracing.rs/tracing/#events) to
OpenTelemetry. The example setups a LoggerProvider with stdout exporter, so logs
are emitted to stdout.
This example demonstrates the basics of logging with OpenTelemetry in Rust. If
you're new to OpenTelemetry logging, this is a great place to start!

## Understanding OpenTelemetry Logging

**Important**: OpenTelemetry does not provide its own end-user facing logging
API. Instead, it integrates with existing, popular logging libraries in the Rust
ecosystem. This example uses the [tracing
crate](https://docs.rs/tracing/latest/tracing/), one of the most widely-used
logging frameworks in Rust.

The way this works is through a [log appender (or
bridge)](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/glossary.md#log-appender--bridge) - in this case, the `opentelemetry-appender-tracing` crate. The appender
captures logs emitted through the `tracing` crate and forwards them to
OpenTelemetry's logging pipeline.

## What This Example Does

This example:

1. Sets up an OpenTelemetry `LoggerProvider` with resource attributes (like
service name)
2. Configures a **stdout exporter** to output logs to the console (for
simplicity)
3. Bridges the `tracing` crate to OpenTelemetry using
`opentelemetry-appender-tracing`
4. Emits a sample log event using the `tracing` library's `error!` macro
5. Properly shuts down the logging pipeline

**Note on Exporters**: This example uses the stdout exporter for demonstration
purposes. In production scenarios, you would typically use other exporters such
as:

- **OTLP exporter** (`opentelemetry-otlp`) to send logs to an OpenTelemetry
Collector or compatible backend
- Other vendor-specific exporters for your observability platform

## Usage

Run the following, and Logs emitted using [tracing](https://docs.rs/tracing/latest/tracing/)
will be written out to stdout.
Run the example to see logs emitted through the `tracing` crate being captured
and output via OpenTelemetry:

```shell
cargo run
```

You'll see the log output in your console, demonstrating how OpenTelemetry
captures and processes logs from the `tracing` library.
Loading