Bun Performance Monitoring
What is OpenTelemetry?
OpenTelemetry is designed to be language- and framework-agnostic, supporting multiple programming languages and frameworks. It offers language-specific software development kits (SDKs) that make it easier to integrate telemetry collection into applications written in different languages.
OpenTelemetry also provides exporters and integrations to send telemetry data to various OpenTelemetry backend systems and observability platforms, including popular tools like Prometheus, Grafana, Jaeger, Zipkin, Elasticsearch, and more.
By using OpenTelemetry, developers can adopt a standardized approach to observability, making it easier to collect and analyze telemetry data across different components of a distributed system. It helps improve troubleshooting, performance optimization, and monitoring of applications, providing valuable insights into their behavior and performance.
Bun comes with an OpenTelemetry instrumentation called bunotel that is distributed as a separate module:
go get github.com/uptrace/bun/extra/bunotel
To instrument Bun database, you need to add the hook provided by bunotel:
import "github.com/uptrace/bun/extra/bunotel" db := bun.NewDB(sqldb, dialect) db.AddQueryHook(bunotel.NewQueryHook(bunotel.WithDBName("mydb")))
To make tracing work, you must use an active span context when executing queries, for example:
ctx := req.Context() err := db.NewSelect().Scan(ctx)
Uptrace is an open source APM for OpenTelemetry that supports distributed tracing, metrics, and logs. You can use it to monitor applications and troubleshoot issues.
Uptrace comes with an intuitive query builder, rich dashboards, alerting rules, notifications, and integrations for most languages and frameworks.
Uptrace can process billions of spans and metrics on a single server and allows you to monitor your applications at 10x lower cost.
OpenTelemetry can also integrate with Prometheus, a popular monitoring and alerting system, to collect and export telemetry data.
By integrating OpenTelemetry with Prometheus, you can leverage the powerful monitoring and alerting capabilities of Prometheus while benefiting from the flexibility and standardization provided by OpenTelemetry. This integration enables you to collect, store, visualize, and analyze metrics from your applications and systems, gaining valuable insights into their performance and behavior.
You can send OpenTelemetry metrics to Prometheus using OpenTelemetry Prometheus exporter.
Overall, monitoring SQL performance is crucial for optimizing query execution, improving application responsiveness, ensuring scalability, troubleshooting issues, and maintaining the security and compliance of your database environment. It enables you to proactively manage and optimize your SQL infrastructure, leading to better application performance, efficient resource utilization, and enhanced user satisfaction.