cwopencensusexporter implements the opencensus Exporter API and allows you to send open census metrics to cloudwatch.
awsClient := cloudwatch.New(session.Must(session.NewSession()))
exporter, sender := cwopencensusexporter.DefaultExporter(awsClient)
go sender.Run()
defer sender.Shutdown(context.Background())
ir, err := metricexport.NewIntervalReader(&metricexport.Reader{}, exporter)
if err != nil {
panic(err)
}
if err := ir.Start(); err != nil {
panic(err)
}
defer ir.Stop()
The open census API does not fully allow first class CloudWatch support. There are a few limitations causing this.
- CloudWatch expects to send aggregations of Max or Min across a time window. For example, the PutMetricData API
for CloudWatch, when working on aggregations, wants you to specify the maximum and minimum value seen in a 60 second
time window. This is not possible with the input data of
metricdata.Distribution
. While I can try to estimate a minimum or maximum value given the buckets, this isn't the true min or max that could otherwise be aggregated easily as points are ingested. - CloudWatch wants values aggregated inside a time window. For example with 60 second aggregations, a point seen at 59.9 seconds should be in an
aggregation for time window 0, while a point seen at 60.1 seconds should be in an aggregation for time window 1. The
API for
metricexport.Exporter
does not split aggregations across time windows. The best I can do is try to align calls toExporter.ExportMetrics
to a time boundary (call at exactly 60 seconds then exactly at 120 seconds, etc). This is unlikely to handle corner cases. The best way to get data with the most fidelity would be to aggregate calls into buckets when they are added tostats.Record
. - Some types, like
metricdata.Summary
, do not translate to CloudWatch metrics and I am unable to provide a good user experience for data submitted tocwopencensusexporter.Exporter.ExportMetrics
that are of typemetricdata.Summary
. An ideal experience for CloudWatch users would be to never let data get put into ametricdata.Summary
and instead bucket them at the level ofstats.Record
. - The layers of abstraction inside opencensus create unnecessary memory allocation that could be avoided with a system designed for CloudWatch's aggregation API.
- Open census buckets include the concept of [...inf] as the last range in their buckets. There's no way to represent this range for CloudWatch. Ideally open census would be able to track maximum (and minimum) values inside a time window so that I could use the min (or max) in the range of my buckets, rather than just assume infinity.
Make sure your tests pass CI/CD pipeline which includes running make fix lint test
locally.