Code Explainers

Code explainers tagged #instrumentation

ruby
module SlowQueryLogger
  SLOW_QUERY_THRESHOLD_MS = 200.0
  IGNORED_PAYLOAD_NAMES = %w[SCHEMA TRANSACTION].freeze
 

Logging slow SQL queries in Rails

instrumentation logging pub-sub
Intermediate 7 steps
typescript
type AsyncMethod = (...args: any[]) => Promise<any>;
 
function LogExecutionTime(thresholdMs = 0) {
  return function <T extends AsyncMethod>(

A method decorator that times async calls

decorators higher-order-functions async
Advanced 9 steps
python
import time
 
from flask import Flask, g, request
 

Timing requests with Flask hooks

middleware request-lifecycle instrumentation
Intermediate 5 steps
ruby
class ApplicationJob < ActiveJob::Base
  retry_on ActiveRecord::Deadlocked, wait: 5.seconds, attempts: 3
  discard_on ActiveJob::DeserializationError
 

Instrumenting every job in Rails

active-job structured-logging retries
Intermediate 6 steps
rust
use std::time::Instant;
 
use axum::{
    body::Body,

Prometheus request metrics in Axum

middleware observability prometheus
Intermediate 7 steps
go
package middleware
 
import (
	"strconv"

Instrumenting a Gin API with Prometheus

middleware observability metrics
Intermediate 6 steps
ruby
module Instrumentation
  module Timing
    def self.[](*method_names)
      Module.new do

Timing methods with a prepended module in Ruby in Rails

metaprogramming prepend instrumentation
Advanced 7 steps
rust
use std::sync::{Arc, Mutex, MutexGuard};
use std::time::Instant;
 
pub struct TimedGuard<'a, T> {

A self-timing mutex guard in Rust

raii mutex deref
Advanced 7 steps
rust
use std::time::Instant;
use tracing::info;
 
pub struct Timer {

A scope-guard timer with Drop in Rust

raii drop-guard timing
Intermediate 7 steps