Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@opentelemetry/instrumentation-aws-lambda

Package Overview
Dependencies
Maintainers
4
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/instrumentation-aws-lambda

OpenTelemetry AWS Lambda automatic instrumentation package.

  • 0.20.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
736K
decreased by-22.05%
Maintainers
4
Weekly downloads
 
Created

What is @opentelemetry/instrumentation-aws-lambda?

@opentelemetry/instrumentation-aws-lambda is an npm package that provides automatic instrumentation for AWS Lambda functions using OpenTelemetry. It helps in collecting and exporting telemetry data such as traces and metrics, which can be used for monitoring and observability of serverless applications.

What are @opentelemetry/instrumentation-aws-lambda's main functionalities?

Automatic Tracing

This feature allows you to automatically trace AWS Lambda function invocations. The code sample demonstrates how to set up the NodeTracerProvider and register the AWS Lambda instrumentation.

const { NodeTracerProvider } = require('@opentelemetry/node');
const { AwsLambdaInstrumentation } = require('@opentelemetry/instrumentation-aws-lambda');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
  instrumentations: [
    new AwsLambdaInstrumentation(),
  ],
});

exports.handler = async (event) => {
  // Your Lambda function code
};

Custom Span Attributes

This feature allows you to add custom attributes to spans within your AWS Lambda function. The code sample shows how to retrieve the current span and set a custom attribute.

const { context, trace } = require('@opentelemetry/api');

exports.handler = async (event) => {
  const span = trace.getSpan(context.active());
  if (span) {
    span.setAttribute('custom.attribute', 'value');
  }
  // Your Lambda function code
};

Error Handling

This feature allows you to record exceptions and set the status of spans when errors occur in your AWS Lambda function. The code sample demonstrates how to catch errors, record them, and set the span status.

const { context, trace } = require('@opentelemetry/api');

exports.handler = async (event) => {
  const span = trace.getSpan(context.active());
  try {
    // Your Lambda function code
  } catch (error) {
    if (span) {
      span.recordException(error);
      span.setStatus({ code: 2, message: error.message });
    }
    throw error;
  }
};

Other packages similar to @opentelemetry/instrumentation-aws-lambda

Keywords

FAQs

Package last updated on 04 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc