slslambda

package module
v0.0.0-...-435fcaa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 21 Imported by: 0

README

Go SDK

Go SDK reports Traces, Captured Errors and Captured Warnings to Serverless Console from the AWS lambda Go runtime environment. The SDK library must be added and instrumented in your AWS Lambda function handler.

Key terms

  • A Captured Error is one instance of an error that is sent to Serverless Console. It can be viewed in the Trace Explorer Details.
  • A Captured Warning is one instance of a string that is sent to Serverless Console, much like a Captured Error.

Compatibility

While Serverless Console is developed by the makers of the Serverless Framework, the entire Serverless Console product and this SDK are 100% agnostic of the deployment tool you use. Serverless Console and this SDK work just as well with Terraform, CDK, SAM, Pulumi, etc, as they do with Serverless Framework.

Installation

Install the package

To instrument your Lambda function code you just need to replace "github.com/aws/aws-lambda-go/lambda" import with "github.com/serverless/console/go/packages/slslambda".

Before:

package main

import (
	"github.com/aws/aws-lambda-go/lambda"
)

func main() {
	lambda.Start(handle)
}

func handle() {}

After:

package main

import (
	"github.com/serverless/console/go/packages/slslambda"
)

func main() {
	slslambda.Start(handle)
}

func handle() {}
Enable Logging

Logging must be enabled on your org in Serverless Console in order for the data to be ingested.

Enable Tracing, Logging, and Dev Mode

Set environment variable

The package does require SLS_ORG_ID environment variable to be set in your Lambda function. You must do that manually using AWS API or AWS Console.

Capturing Errors

slslambda.CaptureError(ctx, err)

Capturing Warnings

slslambda.CaptureWarning(ctx, "something bad will happen soon")

Example

You can find a working example in the example directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTag

func AddTag(ctx context.Context, key, value string)

func AddTags

func AddTags(ctx context.Context, tags map[string]string)

func CaptureError

func CaptureError(ctx context.Context, err error)

func CaptureErrorWithOptions

func CaptureErrorWithOptions(ctx context.Context, err error, options EventOptions)

func CaptureWarning

func CaptureWarning(ctx context.Context, msg string)

func CaptureWarningWithOptions

func CaptureWarningWithOptions(ctx context.Context, msg string, options EventOptions)

func Close

func Close(ctx context.Context)

func Start

func Start(handlerFunc any, options ...Option)

Start starts handler function with Serverless instrumentation.

func WithSpan

func WithSpan(ctx context.Context, name string) context.Context

Types

type EventOptions

type EventOptions struct {
	CustomFingerprint *string
	CustomTags        map[string]string
}

type Option

type Option = func(c *wrapper)

Option is used to customize the instrumentation.

func WithEnvironment

func WithEnvironment(env string) Option

WithEnvironment allows for associating custom environment with telemetry data sent.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL