OpenTelemetry AWS Lambda Resource Detector for Golang
This module detects resource attributes available in AWS Lambda.
Installation
go get -u go.opentelemetry.io/contrib/detectors/aws/lambda
Usage
Create a sample Lambda Go application such as below.
package main
import (
"github.com/aws/aws-lambda-go/lambda"
sdktrace "go.opencensus.io/otel/sdk/trace"
lambdadetector "go.opentelemetry.io/contrib/detectors/aws/lambda"
)
func main() {
detector := lambdadetector.NewResourceDetector()
res, err := detector.Detect(context.Background())
if err != nil {
fmt.Printf("failed to detect lambda resources: %v\n", err)
}
tp := sdktrace.NewTracerProvider(
sdktrace.WithResource(res),
)
lambda.Start(<some lambda handler>)
}
Now your TracerProvider
will have the following resource attributes and attach them to new spans:
Resource Attribute |
Example Value |
cloud.provider |
aws |
cloud.region |
us-east-1 |
faas.name |
MyLambdaFunction |
faas.version |
$LATEST |
Of note, faas.id
and cloud.account.id
are not set by the Lambda resource detector because they are not available outside a Lambda invocation. For this reason, when using the AWS Lambda Instrumentation these attributes are set as additional span attributes.
Useful links
License
Apache 2.0 - See LICENSE for more information.