Now Easier to Instrument Complex Serverless Apps with IOpipe

Mx Kas Perch
IOpipe Blog
Published in
2 min readMay 24, 2018

--

Here at IOpipe, we’re constantly working to shape a developer experience that makes it easier to add observability to AWS Lambda functions in NodeJS. One of the ways we’ve done this is we’ve added access our plugins as properties of the iopipe instantiated object. Before this change, you were able to access IOpipe-related functions from context.iopipe inside your AWS Lambda functions (this still works!):

const iopipe = require('@iopipe/iopipe')({token: 'xxx'});exports.handler = iopipe((event, context) => {
context.iopipe.metric('my metric', 42);
context.succeed('Hello from my serverless function!');
})

But you can also now access them straight of the iopipe object, as our Node.JS agent handles wrangling the context for you:

const iopipe = require('@iopipe/iopipe')({token: 'xxx'});exports.handler = iopipe((event, context) => {
iopipe.mark.start('db-call');
myDb.query('select * from Users', (err, data) => {
iopipe.mark.end('db-call');
});
})

Another effect of this change is the ability to use ES6 module syntax with transpiled ES6 code — as shown by our Node.JS agent’s documentation:

import iopipe, {mark, metric, label} from '@iopipe/iopipe';

exports.handler = iopipe({token: 'xxx'})(async (event, context) => {
// add a trace measurement for the database call
mark.start('db-call');
// fetch some data from the database
const rows = await sql(`select * from dogs where status = 'goodboy'`);
mark.end('db-call');

// add a custom metric for IOpipe search and alerts
metric('rows-from-db', rows.length);

context.succeed('This is my serverless function!');
});

Finally, this is a useful change for complex serverless applications where keeping track of the context object can get confusing. A prime example of this is a monolithic, singular function that does many things and branches down many paths — hanging on to the context object can be tough for longer functions!

Another example is a function that is split up very granularly — a lambda function that calls many other functions; including functions that are not lambdas! This would make it really hard to keep the context object without passing it around from function to function — which is why we instrumented this out! We want you to be able to use IOpipe with your existing AWS Lambda architecture.

We’re happy to continue honing our developer experience to allow all users of IOpipe to instrument and add observability to their AWS Lambda functions. If you’d like to try this out, we have a free trial waiting for you. Questions? Feel free to ask in our community slack.

--

--

Dev🥑. Robotics Author and Maker. Yells at robots occasionally.