{"slug": "til-ruby-s-tracepoint", "title": "TIL: Ruby's TracePoint", "summary": "A developer discovered Ruby's TracePoint class while investigating cryptic CI warnings. TracePoint provides a powerful API for instrumenting key Ruby program events like method calls and raises without modifying the source code. The developer demonstrated how to use TracePoint to trace specific method calls, noting its potential for advanced metaprogramming.", "body_md": "Today I was looking into some cryptic warnings we're getting on CI, and querying GPT about possible ways to understand where they're being emitted from I was pointed to [TracePoint](https://docs.ruby-lang.org/en/master/TracePoint.html) class.\n\nIt's an extremely powerful API that allows instrumenting many key Ruby program events such as raises, method calls, block entries etc. (see docs for the full list) without polluting (or knowing, hehe) the defining code.\n\nFor example, we know an offending instance method name `example_method`\n\n, but naught else. We can instrument all method calls and look for a match\n\n```\ndef example_method\n  \"yay\"\nend \n\nTracePoint.new(:call) do |tp|\n  puts [tp.lineno, tp.defined_class, tp.method_id, tp.event].to_s if tp.method_id == :example_method\nend.enable do\n  example_method\nend\n# [1, Object, :example_method, :call]\n#=> \"yay\"\n```\n\nI imagine you could (ab)use this for some fancy framework meta- programming to gracefully achieve reactions to macro calls etc.", "url": "https://wpnews.pro/news/til-ruby-s-tracepoint", "canonical_source": "https://dev.to/epigene/til-rubys-tracepoint-397e", "published_at": "2026-07-07 13:53:58+00:00", "updated_at": "2026-07-07 13:58:35.151299+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Ruby", "TracePoint"], "alternates": {"html": "https://wpnews.pro/news/til-ruby-s-tracepoint", "markdown": "https://wpnews.pro/news/til-ruby-s-tracepoint.md", "text": "https://wpnews.pro/news/til-ruby-s-tracepoint.txt", "jsonld": "https://wpnews.pro/news/til-ruby-s-tracepoint.jsonld"}}