Summary
In this chapter, we explored database instrumentation. We started by looking into OpenTelemetry semantic conventions for databases and implemented tracing for MongoDB. Then, we added similar instrumentation for Redis and encompassing calls. We saw how to provide application-specific context on encompassing spans and record whether data was retrieved from the cache or database to improve performance analysis across traces.
Then, we added metrics, including client duration histograms for MongoDB and Redis along with server-side metrics for Redis that help analyze and optimize cache usage, starting with the hit ratio, which we were able to measure.
Finally, we simulated a Redis outage and saw how collecting telemetry makes it easy to detect and analyze what went wrong and how the outage progressed. We also found several issues in our application that make it unreliable.
Now you’re ready to start instrumenting database calls in your application or enrich auto-collected...