Documentation ¶
Overview ¶
Package instalambda provides Instana tracing instrumentation for AWS Lambda functions
Example ¶
This example demonstrates how to instrument a handler function with Instana
package main import ( "context" "github.com/aws/aws-lambda-go/lambda" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/instalambda" ) func main() { // Initialize a new sensor sensor := instana.NewSensor("my-go-lambda") // Create a new instrumented lambda.Handler from your handle function h := instalambda.NewHandler(func(ctx context.Context) (string, error) { // If your handler function takes context.Context as a first argument, // instrumentation will inject the parent span into it, so you can continue // the trace beyond your Lambda handler, e.g. when making external HTTP calls, // database queries, etc. if parent, ok := instana.SpanFromContext(ctx); ok { sp := parent.Tracer().StartSpan("internal") defer sp.Finish() } return "Hello, ƛ!", nil }, sensor) // Pass the instrumented handler to lambda.StartHandler() lambda.StartHandler(h) }
Output:
Example (ApiGateway) ¶
This example demonstrates how to instrument a handler function invoked with an API Gateway event
package main import ( "net/http" "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/instalambda" ) func main() { // Initialize a new sensor sensor := instana.NewSensor("my-go-lambda") // Create a new instrumented lambda.Handler from your handle function h := instalambda.NewHandler(func(event *events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) { return events.APIGatewayV2HTTPResponse{ StatusCode: http.StatusOK, Body: "Hello, ƛ!", }, nil }, sensor) // Pass the instrumented handler to lambda.StartHandler() lambda.StartHandler(h) }
Output:
Index ¶
Examples ¶
Constants ¶
const Version = "1.27.0"
Version is the instrumentation module semantic version
Variables ¶
This section is empty.
Functions ¶
func NewHandler ¶
func NewHandler(handlerFunc interface{}, sensor instana.TracerLogger) *wrappedHandler
NewHandler creates a new instrumented handler that can be used with `lambda.StartHandler()` from a handler function
Example ¶
To instrument a handler function, create a new lambda.Handler using instalambda.NewHandler() and pass it to lambda.StartHandler()
package main import ( "github.com/aws/aws-lambda-go/lambda" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/instalambda" ) func main() { // Initialize a new sensor sensor := instana.NewSensor("my-go-lambda") // Create a new instrumented lambda.Handler from your handle function h := instalambda.NewHandler(func() (string, error) { return "Hello, ƛ!", nil }, sensor) // Pass the instrumented handler to lambda.StartHandler() lambda.StartHandler(h) }
Output:
func WrapHandler ¶
func WrapHandler(h lambda.Handler, sensor instana.TracerLogger) *wrappedHandler
WrapHandler instruments a lambda.Handler to trace the invokations with Instana
Example ¶
To instrument a lambda.Handler, instrument it using instalambda.WrapHandler before passing to lambda.StartHandler()
package main import ( "context" "github.com/aws/aws-lambda-go/lambda" instana "github.com/instana/go-sensor" "github.com/instana/go-sensor/instrumentation/instalambda" ) func main() { // Initialize a new sensor sensor := instana.NewSensor("my-go-lambda") h := Handler{ // ... } // Instrument your handler before passing it to lambda.StartHandler() lambda.StartHandler(instalambda.WrapHandler(h, sensor)) } // Handler is an example AWS Lambda handler type Handler struct{} // Invoke handles AWS Lambda events func (Handler) Invoke(ctx context.Context, payload []byte) ([]byte, error) { return []byte("Hello, ƛ!"), nil }
Output:
Types ¶
This section is empty.