-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add OTEL_EXCLUDE_METRICS (#11317)
Adds an env var to allow excluding certain metrics from being exported to reduce noisiness and cost. Metrics are defined by prefix and comma-separated.
- Loading branch information
1 parent
e385ea9
commit 37d4fa8
Showing
13 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
yarn-project/telemetry-client/src/otel_filter_metric_exporter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { type ExportResult } from '@opentelemetry/core'; | ||
import { type MetricData, type PushMetricExporter, type ResourceMetrics } from '@opentelemetry/sdk-metrics'; | ||
|
||
export class OtelFilterMetricExporter implements PushMetricExporter { | ||
constructor(private readonly exporter: PushMetricExporter, private readonly excludeMetricPrefixes: string[]) { | ||
if (exporter.selectAggregation) { | ||
(this as PushMetricExporter).selectAggregation = exporter.selectAggregation.bind(exporter); | ||
} | ||
if (exporter.selectAggregationTemporality) { | ||
(this as PushMetricExporter).selectAggregationTemporality = exporter.selectAggregationTemporality.bind(exporter); | ||
} | ||
} | ||
|
||
public export(metrics: ResourceMetrics, resultCallback: (result: ExportResult) => void): void { | ||
const filteredMetrics: ResourceMetrics = { | ||
resource: metrics.resource, | ||
scopeMetrics: metrics.scopeMetrics | ||
.map(({ scope, metrics }) => ({ scope, metrics: this.filterMetrics(metrics) })) | ||
.filter(({ metrics }) => metrics.length > 0), | ||
}; | ||
|
||
this.exporter.export(filteredMetrics, resultCallback); | ||
} | ||
|
||
private filterMetrics(metrics: MetricData[]): MetricData[] { | ||
return metrics.filter( | ||
metric => !this.excludeMetricPrefixes.some(prefix => metric.descriptor.name.startsWith(prefix)), | ||
); | ||
} | ||
|
||
public forceFlush(): Promise<void> { | ||
return this.exporter.forceFlush(); | ||
} | ||
|
||
public shutdown(): Promise<void> { | ||
return this.exporter.shutdown(); | ||
} | ||
} |