lumigo-io / lumigo-node

Lumigo's Node.js Distributed Tracing and Performance Agent
https://lumigo.io
Apache License 2.0
76 stars 12 forks source link
debugging distributed-tracing instrumentation lumigo monitoring node serverless tracer

lumigo-node :stars:

CircleCI codecov npm version License semantic-release

This is @lumigo/tracer, Lumigo's Node.js agent for distributed tracing and performance monitoring.

Supported NodeJS runtimes: 12.x, 14.x, 16.x, and 18.x

Usage

The @lumigo/tracer package allows you to pursue automated metric gathering through Lambda Layers, automated metric gathering and instrumentation through the Serverless framework, or manual metric creation and implementation.

With Lambda Layers

Note - Lambda Layers are an optional feature. If you decide to use this capability, the list of Lambda layers available is available here.

With Serverless framework

Manually

To manually configure Lumigo in your Lambda functions:

$ npm i @lumigo/tracer
# or
$ yarn add @lumigo/tracer
// javascript
const lumigo = require('@lumigo/tracer')()

const myHandler = async (event, context, callback) => { ... }

exports.handler = lumigo.trace(myHandler)
// typescript
import lumigo from '@lumigo/tracer';

const tracer = lumigo();

export const handler = tracer.trace(async (event, context) => {
  ...
});

Note

For Typescript users, you must add the following to your tsconfig.json file:

{
  ...,
  "esModuleInterop": true,
}

You can read more about it here

Connect Your Lumigo Account

Set your Lumigo token as the LUMIGO_TRACER_TOKEN environment variable of your Lambda function; refer to the Using AWS Lambda environment variables documentation for more information. Your Lumigo token is available in Settings -> Tracing -> Lumigo Token for Tracing, see the Lumigo Tokens documentation.

We advise you to store secrets such as your LUMIGO_TRACER_TOKEN securely; refer to AWS Lambda's Securing environment variables documentation for guidance on keeping the values of your Lambda environment variables secure.

Configuration

@lumigo/tracer offers several different configuration options. Pass these to the Lambda function as environment variables:

Step Functions

If your function is part of a set of step functions, you can add the flag step_function: true to the Lumigo tracer import. Alternatively, you can configure the step function using an environment variable LUMIGO_STEP_FUNCTION=True. When this is active, Lumigo tracks all states in the step function in a single transaction, easing debugging and observability.

const lumigo = require('@lumigo/tracer')({ step_function: true })

Note: the tracer adds the key "_lumigo" to the return value of the function.

If you override the "Parameters" configuration, add "_lumigo.$": "$._lumigo" to ensure this value is still present.

Below is an example configuration for a Lambda function that is part of a step function that has overridden its parameters:

"States": {
    "state1": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:us-west-2:ACCOUNT:function:FUNCTION_NAME",
      "Parameters": {
          "Changed": "parameters",
          "_lumigo.$": "$._lumigo"
        },
      "Next": "state2"
    },
    "state2": {
      "Type": "pass",
      "End": true
    }
}

Logging Programmatic Errors

With the tracer configured, simply call

console.log("[LUMIGO_LOG] <YOUR_MESSAGE>");

to create custom errors that are visible throughout the platform. This can be used anywhere in your Lambda code, and is included with the @lumigo/tracer package.

Adding Execution Tags

You can add execution tags to a function with dynamic values using the parameter addExecutionTag.

These tags will be searchable from within the Lumigo platform.

Adding tags for Manual tracing

To add a tag to a manual trace statement:

Adding tags for Auto tracing

To add a tag to an automatically-traced function:

Execution Tag Limitations

Execution tags are subject to the following limitations:

Scrubbing Limitations

Secrets scrubbing are subject to the following limitations: