Adding metrics
With databases, it’s common to monitor connections and query execution count and duration, contention, and resource utilization in addition to technology-specific things. The MongoDB cluster reports a set of such metrics that you can receive with OpenTelemetry Collector (check it out at https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/mongodbreceiver). These metrics provide the server side of the story. We should also add client-side duration metrics. It’d help us account for connectivity issues and network latency.
OpenTelemetry semantic conventions only document connection metrics for now. We could record them by implementing an IEventSubscriber
interface and listening to connection events.
Instead, we’re going to record the basic operation duration, which also allows us to derive the throughput and failure rate and slice and dice by operation, database, or collection name.
Let’s get back to the...