metric-stream-lambda

command module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

metric-stream-lambda

Lambda function that receives OTLP (0.7.0) data from AWS metric stream and exports the data to logz.io using prometheus remote write

How to create function.zip
make function
How it Works
  • The function begins by importing a number of packages, including those for handling AWS events, encoding/decoding JSON, working with OpenTelemetry data, and logging.
  • The firehoseResponse struct is used to hold information about the response to the Lambda function's API Gateway trigger, including the request ID, a timestamp, and an error message. The generateValidFirehoseResponse function takes in a status code, request ID, error message, and error, and returns an events.APIGatewayProxyResponse with the given information and some default headers and other values.
  • The initLogger function initializes a logger using Uber's zap package, taking in a context and an events.APIGatewayProxyRequest as arguments. It extracts the AWS request ID and account ID from the context and request, respectively, and uses them to configure the logger.
  • The HandleRequest function is the main entry point for the Lambda function. It receives an events.APIGatewayProxyRequest and a context, and returns an events.APIGatewayProxyResponse. It first initializes the logger using the initLogger function. It then decodes the base64-encoded request body and unmarshals it into a pb.ExportMetricsServiceRequest protobuf message.
  • Next, the function creates a pdata.Metrics value from the protobuf message and a componenttest.NewNopExporter component to hold the metrics data. It then creates a prometheusremotewriteexporter.Exporter using the getListenerUrl function to get the logz.io listener url and the LogzioToken variable extracted from the events.APIGatewayProxyRequest headers.
  • The function then iterates through the metrics in the pdata.Metrics value, extracting their names and data points. It converts the data points into Prometheus Remote Write format and sends them to the exporter. If any errors are encountered during this process, they are collected in an ErrorCollector.
  • Finally, the function checks the length of the ErrorCollector and returns an appropriate response based on whether any errors were encountered. If there were no errors, a response with a status code of 200 and an empty error message is returned. If there were errors, a response with a status code of 400 and the concatenated error messages is returned.
Limitations

This function has the following limitations:

  • It can only process metrics data in OTLP 0.7 format.
  • It can only forward the data to a Prometheus Remote Write endpoint.
Changelog
  • v1.0.3
    • Decode every ExportMetricsServiceRequest in a Firehose record. A record can hold several length-prefixed messages, and only the first one was processed, so the rest of the metrics were dropped while Firehose still received 200
    • Log a warning when a record ends with a malformed message, and still ship the messages decoded before it
    • Retry transient remote write failures (5xx, timeouts, connection errors) with exponential backoff for up to 15 seconds per bulk, with a 5 second request timeout, and stop exporting after 25 seconds so Firehose gets the error before the 30 second API Gateway timeout
    • Stop sending the remaining bulks after a failed one, since Firehose retries the whole batch
    • Log only the namespaces of the current invocation
    • Build a bootstrap binary for the provided.al2023 runtime
  • v1.0.2
    • Stop trying to send bulks if encountered 401 status code
    • Add logzio identifier to each log (5 last chars of the shipping token)
    • Add zip workflow and artifact
  • v1.0.1
    • Improved logging (Add zap logger)
    • Add metadata (AWS account, firehose request id, lambda invocation id) to each log for context
    • Flush buffered logs if exists, before the function run ends
  • v1.0.0
    • Initial release: Lambda function that receives OTLP (0.7.0) data from AWS metric stream and exports the data to logz.io using Prometheus remote write

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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