Community-created

How dd-trace Instruments Your Node.js Code Without Touching It

by Syavash
A hands-on deep dive into the machinery behind Datadog's zero-code-change tracing in Node.js. You'll build a mini auto-instrumenting tracer yourself: hooking the module loader, monkey-patching library functions safely, producing real spans, and tracking context across async boundaries. By the end, the 'magic' of dd-trace will look like engineering you could have written yourself.
Library
Course cover
Lesson 1
The Magic Trick: One Line That Sees Everything image

The Magic Trick: One Line That Sees Everything

One line at the top of a Node app and every HTTP request and database query starts reporting its own timing — how can code measure functions that were never asked to measure themselves?
Start
Lesson 2
Monkey-Patching 101 image

Monkey-Patching 101

The oldest trick in dynamic languages: swap a function for your own without anyone noticing.
Locked till you take the prior lesson
Lesson 3
How require Really Works image

How require Really Works

Whoever loads a module first wins. Discover the loader mechanics that make library-wide patching possible.
Locked till you take the prior lesson
Lesson 4
Hooking the Loader image

Hooking the Loader

Build the heart of dd-trace: a hook that intercepts every module load and hands you the exports first.
Locked till you take the prior lesson
Lesson 5
Wrapping Safely: The Shimmer Pattern image

Wrapping Safely: The Shimmer Pattern

Your patch works in the demo and breaks the app in production. Find out what naive wrappers get wrong.
Locked till you take the prior lesson
Lesson 6
Anatomy of a Plugin image

Anatomy of a Plugin

Put the pieces together: write a real instrumentation plugin the way dd-trace's http and pg plugins work.
Locked till you take the prior lesson
Lesson 7
What a Span Actually Is image

What a Span Actually Is

Your patches emit timings. Now turn them into the data structure that makes a trace a trace.
Locked till you take the prior lesson
Lesson 8
The Async Problem image

The Async Problem

Two requests hit your server at once. Whose trace does that database span belong to?
Locked till you take the prior lesson
Lesson 9
AsyncLocalStorage: Context That Follows Your Code image

AsyncLocalStorage: Context That Follows Your Code

Node has a built-in answer to the async problem. See how it works and how dd-trace rides on it.
Locked till you take the prior lesson
Lesson 10
When Context Gets Lost image

When Context Gets Lost

Sometimes a trace just... breaks in half. Learn where async context falls off a cliff and how dd-trace patches the gaps.
Locked till you take the prior lesson