opentelemetry

command module
v0.0.0-...-45c406b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2025 License: BSD-2-Clause Imports: 12 Imported by: 0

README ΒΆ

Bun SQL Client OpenTelemetry Monitoring Example

A complete example demonstrating how to instrument and monitor Bun SQL client performance using OpenTelemetry and Uptrace. This setup provides real-time observability into your database operations, including query performance, errors, and connection metrics.

πŸš€ Features

  • SQL Query Monitoring: Track query execution times, errors, and patterns
  • Database Performance Insights: Identify slow queries and bottlenecks
  • Distributed Tracing: Full request-to-database visibility
  • Real-time Metrics: Connection pools, query counts, and error rates
  • Visual Dashboards: Interactive UI for exploring traces and metrics

πŸ“‹ Prerequisites

  • Docker and Docker Compose
  • Go (for running the example)
  • Git

πŸ› οΈ Quick Start

1. Clone the Repository
git clone https://github.com/uptrace/bun.git
cd example/opentelemetry
2. Start Infrastructure Services

Launch PostgreSQL, ClickHouse, and Uptrace using Docker Compose:

docker compose pull
docker compose up -d

Note: Remove sudo if your user is in the docker group.

3. Verify Uptrace is Running

Check the Uptrace service logs to ensure it started successfully:

docker compose logs uptrace

You should see logs indicating Uptrace is ready and listening on port 14318.

4. Run the Example Application

Execute the Bun client example with OpenTelemetry instrumentation:

UPTRACE_DSN="http://project1_secret@localhost:14318?grpc=14317" go run client.go

The application will:

  • Connect to PostgreSQL
  • Execute sample SQL operations
  • Send telemetry data to Uptrace
  • Display a trace URL in the console
5. View the Results

The CLI will output a direct link to view the generated trace:

trace: http://localhost:14318/traces/ee029d8782242c8ed38b16d961093b35

Click the link or copy it to your browser to see the detailed trace visualization.

Bun OpenTelemetry Trace Visualization

6. Explore the Uptrace Dashboard

Open the main Uptrace UI at http://localhost:14318 to explore:

  • Traces: Detailed request flows and SQL operations
  • Metrics: Database performance statistics
  • Logs: Application and database logs
  • Service Map: Visual representation of service dependencies

πŸ“Š What You'll See

The example demonstrates monitoring of common database operations:

  • Connection establishment and pool management
  • Query execution with timing and parameters
  • Transaction handling and rollback scenarios
  • Error tracking for failed operations
  • Batch operations and prepared statements

πŸ”§ Configuration

The example uses these key configuration values:

Parameter Value Description
Uptrace DSN http://project1_secret@localhost:14318?grpc=14317 Connection string for Uptrace
PostgreSQL localhost:5432 Database server endpoint
Uptrace UI http://localhost:14318 Web interface URL

πŸš€ Next Steps

  • Customize the example: Modify client.go to test your specific use cases
  • Add more databases: Extend monitoring to MySQL, SQLite, or other supported databases
  • Production setup: Review the production deployment guide
  • Advanced features: Explore custom metrics, alerts, and dashboards

🧹 Cleanup

To stop and remove all services:

docker compose down -v

This removes containers, networks, and volumes created by the example.

πŸ“š Additional Resources

🀝 Contributing

Found an issue or want to improve this example? Please open an issue or submit a pull request on the Bun repository.


⭐ Star the project on GitHub if this example helped you!

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL