Transforming Metrics through Code Rules
OTLP Metric Code Rule Examples
1. Add Custom Attribute to All Gauge Metrics
const u = ascent.decode.unflatten(Event);
u.resourceMetrics.forEach((rm) => {
rm.scopeMetrics.forEach((sm) => {
sm.metrics.forEach((m) => {
if (m.gauge) {
m.gauge.dataPoints.forEach((dp) => {
dp.attributes ||= [];
dp.attributes.push({
key: "env",
value: { stringValue: "prod" }
});
});
}
});
});
});
Event = ascent.encode.flatten(u);🧹2. Drop Metric by Name
3. Rename Metric
4. Convert Gauge to Sum
5. Filter Out Data Points by Value
Tips
Last updated
Was this helpful?