A Go library for emitting AWS CloudWatch Embedded Metrics Format (EMF) logs 馃搱
go aws lambda cloudwatch emf
0

Configure Feed

Select the types of activity you want to include in your feed.

Go 100.0%
5 1 0

Clone this repository

https://tangled.org/followtheprocess.codes/emf https://tangled.org/did:plc:wkrlmaetvm6rgl63bdp4c4bz
git@tangled.org:followtheprocess.codes/emf git@tangled.org:did:plc:wkrlmaetvm6rgl63bdp4c4bz

For self-hosted knots, clone URLs may differ based on your setup.



README.md

emf#

License Go Reference Go Report Card GitHub CI codecov

A Go library for emitting AWS CloudWatch Embedded Metrics Format (EMF) logs 馃搱

Project Description#

AWS CloudWatch allows publishing of metrics using a special format known as Embedded Metrics Format (EMF), which involves printing specially formatted JSON messages to stdout from inside a Lambda function. CloudWatch then scans for these messages in the logs, parses them and publishes the metrics behind the scenes.

The primary advantage being this can be done without having to make a HTTP call to the CloudWatch API through AWS client libraries, which means it's much faster and your metrics can be gathered up asynchronously by CloudWatch in the background, not to mention cheaper! 馃

EMF JSON#

An EMF JSON blob looks like this:

{
  "_aws": {
    "Timestamp": 1574109732004,
    "CloudWatchMetrics": [
      {
        "Namespace": "lambda-function-metrics",
        "Dimensions": [["functionVersion"]],
        "Metrics": [
          {
            "Name": "time",
            "Unit": "Milliseconds",
            "StorageResolution": 60
          }
        ]
      }
    ]
  },
  "functionVersion": "$LATEST",
  "time": 100,
  "requestId": "989ffbf8-9ace-4817-a57c-e4dd734019ee"
}

Installation#

WARNING

This module requires the Go 1.25+ JSONv2 experiment: GOEXPERIMENT=jsonv2 set at build time e.g. GOEXPERIMENT=jsonv2 sam build if using AWS SAM CLI See https://go.dev/blog/jsonv2-exp#experimenting-with-jsonv2

go get go.followtheprocess.codes/emf@latest

Quickstart#

Credits#

This package was created with copier and the FollowTheProcess/go-template project template.