-
Notifications
You must be signed in to change notification settings - Fork 862
Include resource attributes as tags for Prometheus exporters #5489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,5 +38,14 @@ public int ScrapeResponseCacheDurationMilliseconds | |
| set => this.ExporterOptions.ScrapeResponseCacheDurationMilliseconds = value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the allowed resource attributes filter. Default value: null (no attributes allowed). | ||
| /// </summary> | ||
| public Predicate<string> AllowedResourceAttributesFilter | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand this implementation was inspired from Java's. It appears both Java and Go have implemented this as a predicate. That said, the spec is not opinionated in how this is implemented:
I think I'd prefer a simple include list. Something like: /// <summary>
/// Gets or sets the resource attributes to include on each metric point. By default no resource attributes are included.
/// </summary>
public string[] IncludedResourceAttributes |
||
| { | ||
| get => this.ExporterOptions.AllowedResourceAttributesFilter; | ||
| set => this.ExporterOptions.AllowedResourceAttributesFilter = value; | ||
| } | ||
|
|
||
| internal PrometheusExporterOptions ExporterOptions { get; } = new(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using OpenTelemetry.Resources; | ||
|
|
||
| namespace OpenTelemetry.Exporter.Prometheus; | ||
|
|
||
| internal readonly struct PrometheusResourceTagCollection | ||
| { | ||
| private readonly Resource resource; | ||
| private readonly Predicate<string> resourceAttributeFilter; | ||
|
|
||
| public PrometheusResourceTagCollection(Resource resource, Predicate<string> resourceAttributeFilter = null) | ||
| { | ||
| this.resource = resource; | ||
| this.resourceAttributeFilter = resourceAttributeFilter; | ||
| } | ||
|
|
||
| public IEnumerable<KeyValuePair<string, object>> Attributes | ||
| { | ||
| get | ||
| { | ||
| if (this.resource == null || this.resourceAttributeFilter == null) | ||
| { | ||
| return Enumerable.Empty<KeyValuePair<string, object>>(); | ||
| } | ||
|
|
||
| var attributeFilter = this.resourceAttributeFilter; | ||
|
|
||
| return this.resource?.Attributes | ||
| .Where(attribute => attributeFilter(attribute.Key)); | ||
|
Comment on lines
+30
to
+31
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we did keep this as a predicate, we could avoid evaluating the predicate on every single export. The configured resource is immutable. It does not change once the exporter is instantiated. |
||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.