Based on the example in https://github.com/aws-samples/aws-lambda-extensions/tree/main/go-example-telemetry-api-extension.
This proof-of-concept code is not production ready. Use it with your own discretion after testing thoroughly.
This sample extension:
- Registers the extension with Lambda Extensions API (see
extensionApi/client.go
) - Starts a local HTTP server to receive incoming telemetry events from the Telemetry API (see
telemetryApi/listener.go
) - Subscribes to the Telemetry API to start receiving incoming telemetry events (see
telemetryApi/client.go
) - Receives telemetry events, batches them, and dispatches only the log events to a grafana loki(see
telemetryApi/dispatcher.go
)
Adapt loki/promtail.go
for your need.
To build and deploy this layer, run:
task publish
Note the ARN and use it as the Lambda Layer.
Configure the extension by setting below environment variables
LOKI_URL
- the URL of the loki server. This poc runs without authentocation.DISPATCH_MIN_BATCH_SIZE
- optimize dispatching telemetry by telling the dispatcher how many log events you want it to batch. On function invoke the telemetry will be dispatched only if number of log events collected so far is greater thanDISPATCH_MIN_BATCH_SIZE
. On function shutdown the telemetry will be dispatched regardless of how many log events were collected so far.