ddlambda

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2020 License: Apache-2.0 Imports: 11 Imported by: 30

README

datadog-lambda-go

CircleCI Code Coverage Slack Godoc License

Datadog Lambda Library for Go enables enhanced Lambda metrics, distributed tracing, and custom metric submission from AWS Lambda functions.

Installation

Follow the installation instructions, and view your function's enhanced metrics, traces and logs in Datadog.

Enhanced Metrics

Once installed, you should be able to view enhanced metrics for your Lambda function in Datadog.

Check out the official documentation on Datadog Lambda enhanced metrics.

Custom Metrics

Once installed, you should be able to submit custom metrics from your Lambda function.

Check out the instructions for submitting custom metrics from AWS Lambda functions.

Tracing

Use ddlambda.AddTraceHeaders(ctx, req) to inject the Datadog tracing headers to the outbound requests.

  req, err := http.NewRequest("GET", "http://example.com/status", nil)
  // Use the same Context object given to your lambda handler.
  // If you don't want to pass the context through your call hierarchy, you can use ddlambda.GetContext()
  ddlambda.AddTraceHeaders(ctx, req)

  client := http.Client{}
  client.Do(req)
}

Environment Variables

DD_FLUSH_TO_LOG

Set to true (recommended) to send custom metrics asynchronously (with no added latency to your Lambda function executions) through CloudWatch Logs with the help of Datadog Forwarder. Defaults to false. If set to false, you also need to set DD_API_KEY and DD_SITE.

DD_API_KEY

If DD_FLUSH_TO_LOG is set to false (not recommended), the Datadog API Key must be defined.

DD_SITE

If DD_FLUSH_TO_LOG is set to false (not recommended), and your data need to be sent to the Datadog EU site, you must set DD_SITE to datadoghq.eu. Defaults to datadoghq.com.

DD_LOG_LEVEL

Set to debug enable debug logs from the Datadog Lambda Library. Defaults to info.

DD_ENHANCED_METRICS

Generate enhanced Datadog Lambda integration metrics, such as, aws.lambda.enhanced.invocations and aws.lambda.enhanced.errors. Defaults to true.

Opening Issues

If you encounter a bug with this package, we want to hear about it. Before opening a new issue, search the existing issues to avoid duplicates.

When opening an issue, include the datadog-lambda-go version, go version, and stack trace if available. In addition, include the steps to reproduce when appropriate.

You can also open an issue for a feature request.

Contributing

If you find an issue with this package and have a fix, please feel free to open a pull request following the procedures.

License

Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.

This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2020 Datadog, Inc.

Documentation

Index

Constants

View Source
const (
	// DatadogAPIKeyEnvVar is the environment variable that will be used as an API key by default
	DatadogAPIKeyEnvVar = "DD_API_KEY"
	// DatadogKMSAPIKeyEnvVar is the environment variable that will be sent to KMS for decryption, then used as an API key.
	DatadogKMSAPIKeyEnvVar = "DD_KMS_API_KEY"
	// DatadogSiteEnvVar is the environment variable that will be used as the API host.
	DatadogSiteEnvVar = "DD_SITE"
	// DatadogLogLevelEnvVar is the environment variable that will be used to check the log level.
	// if it equals "debug" everything will be logged.
	DatadogLogLevelEnvVar = "DD_LOG_LEVEL"
	// DatadogShouldUseLogForwarderEnvVar is the environment variable that is used to enable log forwarding of metrics.
	DatadogShouldUseLogForwarderEnvVar = "DD_FLUSH_TO_LOG"
	// DefaultSite to send API messages to.
	DefaultSite = "datadoghq.com"
	// DefaultEnhancedMetrics enables enhanced metrics by default.
	DefaultEnhancedMetrics = true
)

Variables

This section is empty.

Functions

func AddTraceHeaders

func AddTraceHeaders(ctx context.Context, req *http.Request)

AddTraceHeaders adds DataDog trace headers to a HTTP Request

func Distribution

func Distribution(metric string, value float64, tags ...string)

Distribution sends a distribution metric to DataDog Deprecated: Use Metric method instead

func GetContext

func GetContext() context.Context

GetContext retrieves the last created lambda context. Only use this if you aren't manually passing context through your call hierarchy.

func GetTraceHeaders

func GetTraceHeaders(ctx context.Context) map[string]string

GetTraceHeaders reads a map containing the DataDog trace headers from a context object.

func InvokeDryRun added in v0.5.0

func InvokeDryRun(callback func(ctx context.Context), cfg *Config) (interface{}, error)

InvokeDryRun is a utility to easily run your lambda for testing

func Metric added in v0.5.0

func Metric(metric string, value float64, tags ...string)

Metric sends a distribution metric to DataDog

func MetricWithTimestamp added in v0.5.0

func MetricWithTimestamp(metric string, value float64, timestamp time.Time, tags ...string)

MetricWithTimestamp sends a distribution metric to DataDog with a custom timestamp

func WrapHandler

func WrapHandler(handler interface{}, cfg *Config) interface{}

WrapHandler is used to instrument your lambda functions, reading in context from API Gateway. It returns a modified handler that can be passed directly to the lambda.Start function.

Types

type Config

type Config struct {
	// APIKey is your Datadog API key. This is used for sending metrics.
	APIKey string
	// KMSAPIKey is your Datadog API key, encrypted using the AWS KMS service. This is used for sending metrics.
	KMSAPIKey string
	// ShouldRetryOnFailure is used to turn on retry logic when sending metrics via the API. This can negatively effect the performance of your lambda,
	// and should only be turned on if you can't afford to lose metrics data under poor network conditions.
	ShouldRetryOnFailure bool
	// ShouldUseLogForwarder enabled the log forwarding method for sending metrics to Datadog. This approach requires the user to set up a custom lambda
	// function that forwards metrics from cloudwatch to the Datadog api. This approach doesn't have any impact on the performance of your lambda function.
	ShouldUseLogForwarder bool
	// BatchInterval is the period of time which metrics are grouped together for processing to be sent to the API or written to logs.
	// Any pending metrics are flushed at the end of the lambda.
	BatchInterval time.Duration
	// Site is the host to send metrics to. If empty, this value is read from the 'DD_SITE' environment variable, or if that is empty
	// will default to 'datadoghq.com'.
	Site string

	// DebugLogging will turn on extended debug logging.
	DebugLogging bool
	// EnhancedMetrics enables the reporting of enhanced metrics under `aws.lambda.enhanced*` and adds enhanced metric tags
	EnhancedMetrics bool
}

Config gives options for how ddlambda should behave

Directories

Path Synopsis
internal
metrics
* Unless explicitly stated otherwise all files in this repository are licensed * under the Apache License Version 2.0.
* Unless explicitly stated otherwise all files in this repository are licensed * under the Apache License Version 2.0.

Jump to

Keyboard shortcuts

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