►
Description
Thomas is a member of the Node.js Tracing Working Group and a full time open source developer at Opbeat.
This video covers different approaches of instrumenting a Node.js application. It is a great lesson on tracing that focuses on discovering bottlenecks and tracking/logging application usage in production without sacrificing performance.
You can follow Thomas on Twitter @wa7son.
Thank you to Opbeat for sponsoring the videos for Node.js Live Paris, and IBM for sponsoring the Node.js Live Paris event.
A
A
I
went
for
this
company
called
upbeat
and
a
top
bead.
We
do
application
performance
monitoring
for
javascript,
and
so
one
of
the
things
we
do
is
we
like
to
when
a
request
comes
into
your
application,
we
like
to
break
it
down
for
you
and
show
you
exactly
what
goes
on
behind
the
scenes
when
that
request
is
being
processed.
So
what
goes
into
the
database
and
and
what
is
is
hitting
a
third
party,
so
the
third
party
aap,
I,
etc-
and
this
is
some
of
the
stuff
I'm
going
to
talk
about
today.
A
But
it's
not
I'm
not
going
to
talk
about
what
we
do
it
up,
but
I'm
going
to
talk
more
about
how
you
would
want
to
do
this
yourself.
So
this
is
not
going
to
be
a
product
demonstration.
I
promise
you
that
and
upbeat
I
am
responsible
for
the
note
yes
stack.
So
if
you
do
npm
install
upbeat,
you
install
install
the
code
that
that
I'm
writing
every
day.
A
So
the
topic
of
this
talk
is
instrumenting
node.js
in
production
and,
as
I
showed
you
before,
instrumenting
when
I
say
that
what
we
want
to
do
is
we
want
to
look
at
something
like
a
request,
for
example,
and
we
want
to
you-
want
to
see
what
goes
on
behind
the
scenes.
So
normally,
when
we
talk
about
this,
we
see
this
kind
of
like
a
waterfall
thing
going
on,
and
a
lot
of
stuff
can
happen
there.
A
And
if
the
problem
is
it's
really
hard
to
figure
out
what
request
was
active
when
we
got
to
like
the
third
stage,
all
the
way
down
in
the
machine
room,
and
sometimes
something
happens
down
there
and
we're
like
okay,
this
broke,
but
what
request
was
actually
making
making
that
happen?
Why
did
we
end
up
there?
What
URL
was
called
what
data
was
sent
to
the
server?
So
these
are
some
of
the
challenges
and
the
solution
for
figuring
for
making
this
work
normally.
A
Is
that
either
you
have
some
kind
of
cool
opal
or
you
have
a
singleton
object
where
you
store
some
kind
of
context,
and
that
context
includes,
for
instance,
are
the
requests
that
it's
active
and
then
you
can
always
get
back
to
that?
No
matter
where
you
are
in
your
application,
you
have
access
to
this
global
context
or
another
solution
that
are
like
a
little
more
but
still
have
some
problems.
Is
you
pass
around
the
context
between
each
function?
Call
the
problem
with
that,
of
course,
is
well.
You
have
to
like
do
that.
A
All
over
your
code
is
really
tedious,
so,
but
but
but
at
least
we
get
around
some
problems
with
having
like
this
global
global
thing
before
get
more
into
the
details,
I
just
want
to
run
some
vocabulary
by
you,
because
I'm
going
to
use
these
things
quite
a
lot
when
I
say
a
trace,
I
basically
mean
a
measure
of
time
from
something
started,
so
it
ended.
It
could
be
like
a
database
query
or
a
call
to
an
external
API
or
something
oh
and
when
I
say
a
transaction,
it's
basically
just
a
collection
of
traces.
A
So
it
could
be,
a
transaction
would
be
like
an
HTTP
requests
that
have
a
lot
of
traces
going
on
inside
the
HTTP
request,
but
there
is
a
problem
and
the
problem
is
called
no
tas.
I
love
note
years,
but
it
and
it's
really
nice,
because
you
can
run
everything
in
a
single
process,
but
with
that
comes
from
problems
and
those
problems
make
it
really
really
hard
to
instrument
almost.
How
many
here
are
have
a
coding
node.js
on
a
daily
basis
and
how
many
are
new
to
note?
A
Okay,
so
not
all
of
you
might
know
this
event
loops,
I'm
going
to
just
quickly
show
you
what
the
problem
is.
So
normally
when
you
do
a
web
server,
a
lot
of
the
stuff
is
not
actually
processing
stuff
on
the
cpu
you're,
not
like
crunching
prime
numbers
or
something
you're,
usually
waiting
for
database
to
to
return
or
for
doing
some
writing
some
stuff
to
the
disk.
So
there's
a
lot
of
I/o
going
on
that.
Actually,
the
CPU
is
not
really
doing
anything.
A
At
the
same
time,
all
the
time
so
and
oh
yeah,
and
and
by
the
way,
each
of
these
pieces
of
synchronous
code,
you
can
think
of
them
kind
of
like
as
a
little
piece
of
a
program
that
has
no
recollection
of
what
came
before
it.
So
when
you
enter
one
of
these
synchronous
blobs
the
the
code,
there
doesn't
really
have
a
reference
back
to
to
who
actually
put
it
there
in
the
first
place,
so
that
can
be
really
tricky
to
instrument.
A
Another
problem
that
we
usually
face
in
the
node.js
community
is
well
we
like
to
use
micro
services
because
microservices
are
cool
and
notice
like
wait,
so
it's
really
easy
for
us
to
build
microservices,
but
the
problem
is
that
we,
when
we
instrument
this,
we
have
an
HTTP
request
coming
in.
It
might
be
doing
a
couple
of
database
queries
and
then
we
see
the
result
of
the
of
the
instrumentation.
A
We
see
those
it's
like
a
huge
HTTP
request
going
on
before
we
can
respond
back
to
the
user,
but
what
is
going
on
they're,
recalling
a
micro
service
inside
our
our
network,
but
we
don't
actually
know
what's
going
on
what's
actually
going
on,
is
it
might
be
doing
some
database
queries?
Wouldn't
it
be
nice
to
know
those
sort
of
things,
and
this
is
this
is
the
same
looking
looking
at
it
from
a
kind
of
a
different
point
of
view.
A
You
have
your
web
application
and
then
you
have
a
couple
of
micro
services
that
is
calling
and
those
micro
services
might
be
calling
other
microservices.
So
you
have
this
whole
Christmas
tree
that
you're
trying
to
do
instrument
which
can
be
really
hard
to
trace
the
the
HTTP
request
over
all
these
steps.
A
So
the
goals
that
we
want
to
make
here
I
want
to
meet.
Is
we
want
to
track
HTTP
requests
using
these
transactions?
Are
we
want
to
instrument
I,
oh,
and
we
want-
maybe
also
in
some
cases,
to
instrument
CPU,
expensive
operations
or
potentially
CPU
expensive.
That
could
be
JSON
parsing,
for
example,
which
sometimes,
if
you
have
a
huge
digin
object,
can
can
take
quite
a
long
time.
We
also
want
to
keep
the
context
arm
across
inquests
to
micro
services
as
a
set,
and
we
want
to
associate
exceptions
with
the
HTTP
requests.
A
That
kind
of
made
that
exception
happen
in
the
first
place,
but
we
don't
want
to
manually
pass
this
context
around
in
the
app
that
would
be
really
really
irritating
and
we
will
litter
I
cook
with
a
lot
of
stuff
that
that
is
just
ugly
and
that
ties
into
the
to
the
second
to
the
point
below
is
we
want
this
to
be
plugging
play?
We
don't
want
to
like
add
tracing
I
start.
This
trace
here
and
int
that
trace
I,
don't
want
to
do
that
to
our
application
and,
finally,
just
to
make
it
even
harder.
A
So
the
problems
as
I
said,
is
you
have
multiple
HTP
request
happening
all
the
time.
It's
not
possible
to
associate
an
exception
with
the
origin
HTTP
request.
There
is
no
api
and
node
where
we
can
actually
pass
context
across
the
async
boundary.
And
how
do
we
keep
the
context
across
request
to
microservices?
A
A
That
is
simply
our.
If
it's
HTTP
request
that
is
going
on
here,
you
could
also
have
cues
that
you're,
where
you
up
we're
passing
stuff
to
microservices
using
cues.
But
if
is
if
it's
HTTP
request,
it's
actually
possible
to
go
in
and
I'm
going
to
say
a
dirty
word,
I'm
going
to
say
monkey
patch
HTTP.
That
request,
but
just
bear
with
me
and
automatically
add
a
transaction
ID
and
x
transaction
ID
header
to
all
outgoing
requests.
A
So
that
way
that
when
the
request
ends
up
and
your
other
servers,
you
can
kind
of
when
you
then
later
send
that
data
to
you
at
some
kind
of
collection
database
where
you
store
or
lyst
racing
information,
you
can
tie
these
things
back
together.
It
figure
what
actually
started
up
in
the
web
application
and
that
other
thing
here,
no
api
to
pass
contact
across
acing
boundary.
I'm
going
to
spend
the
rest
of
the
talk
making.
You
guys
believe
that
that
will
solve
everything
else.
If
we
can
just
get
that.
A
A
Every
time
something
is
cued
and
they've
been
looped,
so
that
was
when
you
have
the
asynchronous
code
that
is
queuing
something
to
be
run
later.
We
just
want
to
record
the
context
of
where
you
are
right
now,
when
we
are
queuing
that
callback
and
when
we
then
later,
restore
or
DQ
are
that
callback
from
the
event
loop
to
run
it.
We
want
to
restore
the
the
context
that
we
restore
Barry
cute
it.
A
So
in
your
talking
trend
transactions
consider
we
have
like
a
global
transaction
object
and
we
seeded
with
the
current
request
that
is
coming
in
then.
The
context
in
this
case
is
just
that
property.
So
what
we
want
to
do
is
we
just
want
to
every
time
we
store
something
on
the
event
loop.
We
just
want
to
remember
what
was
the
current
transaction
and
when
we
restore
that
we
just
sorry,
we
want
to
restore
the
current
transaction
profits
you
to
that
value.
A
So
how
do
we
do
that?
There
are
ways
to
do
that
now
today.
Well,
you
can
you?
Can
you
have
to
monkey
patch
a
lot
of
things
today?
If
you
want
to
do
that,
and
if
you
want
to
learn
more
about
how
you
could
do
that
in
the
current
version
of
note
come
and
talk
to
me
afterwards,
I
don't
have
time
to
go
into
the
details
of
that
very
messy
code.
A
A
We
don't
have
right
now
to
pass
state
across
the
async
boundary
ason
grab
is
a
project
I
developed
under
the
node.js
tracing
work
group
by
a
guy
called
Trevor
Norris,
and
you
can
go
into
this
github
repo
there
and
you
can
see
all
the
stuff
that
the
tracing
work
group
is
working
on
along
with
the
Asian
grab.
Stuff
they're
also
be
documentation
for
the
acing
rap
stuff
in
there.
If
you
want
to
play
with
it
now,
and
so,
let's
play
with
it,
it's
not
I'm
going
to
show
some
code
here.
A
I
hope
you
ok
with
that,
but
since
this
is
new-
and
this
is
not
really
in
note
yet
there
is
no
way
to
just
require
a
sing
rap
like
you
would
require
HTTP
your
require
net
or
whatever,
but
the
the
c++
code
for
making
this
happen
is
actually
there
and
you
can
access
our
connections
that
code
by
using
process
that
binding
and
it's
actually
already
now
in
version
four
and
version
5
of
note
it's
shipping
with
no,
you
just
don't
know
it.
But
beware!
This
is
like
highly
experimental
at
much.
A
Eddie
will
change
so,
but
you
can
play
around
with
it.
So
you
get
back
a
async
rap
object.
This
is
in
javascript
land.
Then
all
you
need
to
do
is
you
need
to
set
up
some
hooks
and
you
need
to
hook
a
pre
hook,
a
poster
can
destroy
hook,
and
then
you
just
need
to
enable
it
and
now
I
converted
my
slides
from
keynote
to
to
powerpoint.
A
So
my
my
transitions
here
are
going
to
be
a
bit
wonky,
but
let's
see
so
the
the
four
hooks
are
here,
so
the
init
hook
will
be
called
up
just
when
you
q,
something
on
the
event
loop
so
that
that
function
will
be
called.
You
get
a
lot
of
variables
or
arguments,
so
you
know
what
is
being
cute.
The
pre
hook
is
going
to
be
called
just
before
that
callback
is
going
to
be
called
so
after
its
being
DQ
and
just
before
the
callback
is
called,
you
will
get
a
call
to
the
pre
hook.
A
The
post
hook
will
be
called
just
after
the
call
back
helping
cold
and
remember
everything
inside
the
event
loop.
When
is
running,
the
synchronous
block
is
synchronous,
so
you
know
that
the
callback
hash
finished
running
and
then
the
post
hook
is
going
to
be
called
that.
That
callback
might
then
choose
some
other
stuff.
That
will
then
call
the
inert
hook
and
so
forth.
A
This
was
me
scrolling
up,
so
you
have
the
code
above
and
now
we
we're
trying
to
test
this
out.
So
we
require
the
file
system
module
and
we
just
try
to
open
a
file
that
is
asynchronous
a
node.
There
is
a
call
back
to
the
FS
that
open
that
would
be
cold
when
the
file
is
being
have
been
opened
and
just
before
we
write
a
user
before
and
just
after
we
write
user
after
and
then
when
the
call
back
at
some
point,
is
it's
called
ill
right
user
done?
So
how
will
this
work?
A
How
was
this
look
together
with
the
other
code?
We
saw
before
again
I'm
sorry
from
the
transact
transitions
here.
So
first
you
will
see
user
before
because
that's
actually
the
first
thing
that
is
being
run
down
here,
then
you
will
see
the
unit,
because
now
we
actually
queuing
a
call
back
then
you'll
see
after
which
is
down
below
here.
It's
being
for
some
reason,
cut
out
of
the
slide,
but
there's
a
user
after
at
the
bottom.
At
some
point
later
the
file
has
been
opened,
and
now
we
will
get
a
call
to
the
pre.
A
How
come
I
just
didn't
wrote
console
the
lock
in
the
past
lied.
I
wrote
just
luck.
What
is
this
magic
lock
thing?
What
happens
if
I
just
use
console.log?
I
normally
you
don't
like
block
stuff
here,
but
it's
nice
when
you're
debugging,
especially
this
stuff,
because
it
can
get
a
little
hairy.
So
what
would
happen
if
it
wrote
console
deadlock,
I,
guess:
there's
nice
error
message,
fatal
error,
node
Asian,
grab
Asian
grab
you
need
hook
through.
What
does
that
mean?
Well,
you
would
think
that
console
that
luck
was
a
synchronous.
A
Operation
right
turns
out
is
not
console.
That
lock
is
actually
a
synchronous.
So
it
means
that
when
you
go
into
the
init
function
because
something
is
being
cured
on
the
event
loop,
then
if
the
the
in
function
will
call
concert
that
log
which
will
again
call
the
init
function,
you
will
have
an
infinite
loop.
So
obviously
you
can't
use
console
that
luck.
So
how
do
we
get
around
this?
When
you
want
a
debug
this
code?
Well,
one
way
is
to
use
the
actual
EFS
that
right
sink
and
the
first
parameter.
A
There
is
a
file
descriptor
and
there's
two
magic
file
descriptors
in
begin.
Unix
I
think
they
work
the
same
on
Windows
one
is
standard
out
and
two
is
standard
error,
and
then
you
can
write
bytes
to
that
and
all
appear
on
your
screen
and
it's
synchronous.
The
problem
with
that
it
is
just
bite.
It
doesn't
have
all
the
niceties
that
we're
used
to
will
console
luck
with
all
the
formatting
all
that
stuff.
So
you
would
have
to
use
your
tilde
format.
A
It
can
get
a
little
hairy
when
you're
debugging
dried
all
that
stuff
just
to
like
output,
like
some
module
that
you
want
to
or
some
object.
You
want
to
see
what
it
contains
right.
So
what
I
like
to
do
is
use
this
secret
thing
called
process
underscore
raw
debug,
which
is
basically
just
a
synchronous
version
of
console
lock,
but
it
may
it
it's
easy
for
debugging
stuff
inside
casing
crap.
So
if
we
use
that
instead,
then
now
we
get
the
same,
the
same
output
again
good.
A
So,
what's
all
these
things
inside
the
the
init
function,
you
will
have
that
this
property
will,
which
will
be
set
to
what's
called
the
handle.
I'll
go
back
to
that.
Then
you
have
the
UID,
which
is
Stan
incrementing
integer
from
the
lifetime
of
your
application,
so
start
at
one
and
goes
up
and
you
will
see
the
UID
appearing
in
all
the
other
hooks.
So
that
way
you
can,
when
you
have
the
pre
hook
and
the
post
hook,
you
will,
if
you
see
the
same
uid
you'll
see.
A
This
is
the
same
call
back
out,
so
you
can
refer
to
the
same
call
back
across
these
hooks.
Then
you
will
have
a
provider.
Currently
that's
the
number
between
0
and
23.
Are
that
might
change?
But
if
you
look,
you
can
always
look
at
providers
on
the
async
wrap
up
yet,
and
you
will
see
all
these
things,
so
the
providers
actually
true
is
actually
right.
Now
queuing
this.
It
could
be
related
to
making
a
TCP
connection
or
you
see,
number
17,
that's
a
timer,
so
there
will
be
like
your
set
timeout
or
set
interval.
A
That
is
trying
to
do
this
and
then
in
some
cases
you
will
have
a
parent
view
ide
and
a
parent
handle
on
if
not
they'll
be
set
to
null
and
in
most
cases
it's
at
all.
There
are
certain
cases
where
they
used
I'm
going
to
get
back
to
that,
so
handle
objects.
What
are
handle
objects
so
I,
don't
know
mate.
A
How
many
people
know
this,
but
some
of
the
stuff
in
well,
some
of
the
stuff
in
node,
is
written
in
C++
and
at
some
of
the
service
written
in
JavaScript
and
there's
this
like
this
magic
line
where
JavaScript
land
ends
and
C++
land
start,
and
you
also
see
that
that
v8
is
also
down
here.
So
the
stuff
that
is
written
in
C++
is
what's
called
leap,
UV
and
Libya.
V
is
where
all
the
IO
stuff
lives,
because
JavaScript
as
a
language
was
born
in
the
browser,
didn't
have
any
I/o.
A
There
is
no
talking
to
the
disk
or
making
TCP
connections
and
stuff
like
that,
so
that
when
OGS
were
developed,
we
had
to
make
that
and
from
from
the
bottom,
and
that
is
written
in
c
plus,
plus
and
lives.
In
did
you
be
so?
How
do
how
do
we
communicate?
How
do
we
send
data
from
the
note
chord
down
to
the
C++
layer?
We
use
these
handle
objects
under
those
handle
objects.
A
We
can
set
properties
so
the
data
we
want
to
pass
across
this
boundary
or
back
again,
we
can
set
that
on
properties
on
this
handle
up.
Yet
so,
let's
look
at
how
that
that
looks.
This
is
a
code
lifted
from
from
the
TCP
module
or
the
net
module
which,
for
some
reason,
is
called
net,
but
it's
all
the
TCP
stuff-
and
this
is
for
setting
up
a
new
TCP
socket
and
you
can
see
they
use
the
same
process
that
binding
here
are
and
the
opening
up
TCP
wrap.
We
get
to
handle
objects
out.
A
A
TCP
connect,
trap,
object
in
a
TCP
object
and
we
stand
she
ate
them,
and
then
we
set
some
properties
on
them.
For
example,
the
TCP
connection
connect
wrap,
we
said
the
address
and
the
port
we
are
trying
to
connect
to
arm
and
this
wreck
and
this
socket
is
actually
the
disk.
So
that
means
that
you
can
get
the
address
and
the
port
you're
trying
to
connect
you
using
the
disk
keyword-
and
this
is
actually
also
an
example
of
one
of
those
cases
where
you
have
a
parent
handle.
A
So
in
the
case
of
you're
making
a
tcp
connection
first,
the
connection
will
have
made
and
then
later
the
socket
will
be
open
and
when
the
socket
is
opened,
that's
actually
then
the
TC,
then
the
TCP
connect
wrap
handle
is
actually
the
parent
of
the
socket.
So
in
those
cases
you
will
you
will
have,
you
will
have
a
parent,
but
it's
very
rare,
some
things
to
watch
out
for
here
we
have
two
timers.
So
how
would
we
do
spec
this
this
code
to
to
look?
A
When
are
the
output
of
this
code
to
look
many
when
you
run
it
well
before
one
then
the
unit,
because
we're
curing
that
they'll
be
accusing
the
state
timeout
function,
then
after
one?
Ok,
that's
cool,
then,
before
too
ok,
that's
cool,
but
then
there's
no
in
it
and
then
there's
a
aptitude.
So
there's
no
in
it
there.
Why
is
there
is
no
in
it
and
then
after
two
seconds
has
parsed,
we
will
see?
A
So
the
handle
creation
time
is
the
time
where
the
init
function
is
called.
For
example,
if
you
have
a
TCP
server,
it
is
not
calling
the
inner
function
until
we
actually
bind
to
a
port.
So
until
you
call
listen,
that's
that's
when
they
need
function
is
called
a
console
log.
We
already
been
through
that
process.
Next
tick
is
currently
not
covered
by
this,
so
you
would
have
to
if
you
want
to
know
when
process
next
tick
is
called.
A
A
8
doesn't
really
give
us
any
way
to
hook
into
these
promises
right
now,
but
this
is
again
something
that
we're
working
on
so
hopefully
that'll
be
part
of
the
the
final
asian
grab
API,
but
maybe
not
so
watch
out
for
that
and
then
right
now,
multiple
ace
and
grab.
So
if
you
start
acing
wrapped
twice
in
your
application,
it
was
be
the
last
one
that
takes
precedence
so
only
the
last
one.
To
add,
the
hooks
will
be
the
one
who's
hooks
are
called,
so
those
are
some
things
to
watch
out
for
and.