Dash0 seamlessly integrates with your Bun applications, providing clear visibility into your system's activity and performance.
Instrumenting your Bun application to generate traces, logs, and metrics is a powerful way to gain deep insights into its behavior and performance. By adding instrumentation, you enable your application to emit valuable data that can be used for monitoring, troubleshooting, and optimization.
Dash0 supports instrumentation of Bun applications through OpenTelemetry's open-source and vendor-agnostic packages. Bun applications require manual setup of an initialization file to properly configure OpenTelemetry.
To instrument your Bun application, you'll need to install the OpenTelemetry SDK and the Node.js auto-instrumentation packages, as Bun is compatible with most Node.js packages:
Unlike Node.js, Bun requires a manual initialization file since it doesn't support the same --require
flag that Node.js uses for auto-instrumentation. You'll need to create a separate initialization file and preload it.
1. Create an initialization file
Create a file named otel.ts
in your project root with the following content:
2. Configure environment variables
Set the following environment variables before starting your application:
3. Run your application with the preloaded initialization file
In case you are not using the Dash0 operator for Kubernetes to deploy your application, you should extend the OpenTelemetry resource attributes to include the Pod UID. This is important to merge the resources between logs, traces, and metrics.
You need to modify your otel.ts
file to include these attributes:
And update your Kubernetes deployment:
Since Bun uses the Node.js auto-instrumentation package, it supports most of the same libraries and frameworks. However, compatibility may vary as Bun continues to evolve.
To understand which libraries are automatically instrumented, please refer to the OpenTelemetry documentation.