-
Notifications
You must be signed in to change notification settings - Fork 871
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
add additional attributes to metric #5453
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
.../io/opentelemetry/sdk/autoconfigure/spi/metrics/ConfigurableMetricAttributesProvider.java
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,19 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.autoconfigure.spi.metrics; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
|
||
/** | ||
* A service provider interface (SPI) for providing additional attributes that can be used with the | ||
* View AttributeProcessor. | ||
*/ | ||
public interface ConfigurableMetricAttributesProvider { | ||
|
||
/** Returns a {@link Attributes} that can be added to OpenTelemetry view AttributeProcessor */ | ||
Attributes addCustomAttributes(ConfigProperties config); | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...metry/sdk/extension/incubator/metric/viewconfig/CustomConfigurableAttributesProvider.java
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,14 @@ | ||
package io.opentelemetry.sdk.extension.incubator.metric.viewconfig; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricAttributesProvider; | ||
|
||
|
||
public class CustomConfigurableAttributesProvider implements ConfigurableMetricAttributesProvider { | ||
@Override | ||
public Attributes addCustomAttributes(ConfigProperties config) { | ||
return Attributes.of(AttributeKey.stringKey("foo"),"val"); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
.../io/opentelemetry/sdk/extension/incubator/metric/viewconfig/ViewConfigAdditionalTest.java
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,59 @@ | ||
package io.opentelemetry.sdk.extension.incubator.metric.viewconfig; | ||
|
||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; | ||
import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions; | ||
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ViewConfigAdditionalTest { | ||
|
||
@Test | ||
public void testViewConfigAdditionAttrs() { | ||
InMemoryMetricReader reader = InMemoryMetricReader.create(); | ||
AutoConfiguredOpenTelemetrySdk.builder() | ||
.setResultAsGlobal(false) | ||
.addPropertiesSupplier( | ||
() -> | ||
ImmutableMap.of( | ||
"otel.traces.exporter", | ||
"none", | ||
"otel.metrics.exporter", | ||
"none", | ||
"otel.experimental.metrics.view.config", | ||
"classpath:/view-config-customizer-test.yaml")) | ||
.addMeterProviderCustomizer( | ||
(meterProviderBuilder, configProperties) -> | ||
meterProviderBuilder.registerMetricReader(reader)) | ||
.build() | ||
.getOpenTelemetrySdk() | ||
.getSdkMeterProvider() | ||
.get("test-meter") | ||
.counterBuilder("counter") | ||
.buildWithCallback( | ||
callback -> { | ||
// Attributes with keys baz and qux should be filtered out | ||
callback.record( | ||
1, | ||
Attributes.builder() | ||
.build()); | ||
}); | ||
|
||
assertThat(reader.collectAllMetrics()) | ||
.satisfiesExactly( | ||
metricData -> | ||
OpenTelemetryAssertions.assertThat(metricData) | ||
.hasLongSumSatisfying( | ||
sum -> | ||
sum.hasPointsSatisfying( | ||
point -> | ||
point | ||
.hasValue(1) | ||
.hasAttributes( | ||
attributeEntry("foo", "val"))))); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...vices/io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricAttributesProvider
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 @@ | ||
io.opentelemetry.sdk.extension.incubator.metric.viewconfig.CustomConfigurableAttributesProvider |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is an extension to the YAML file configuration for views, I think it would make more sense to implement this as an additional section of key value pairs within the YAML, rather than an SPI that surprisingly interacts with all registered views.
With that said, I'm reluctant to add configurable surface area for adding these attributes since using views to add additional attributes is experimental and not an official part of the spec. That means that when we replace this file based YAML config with the full file configuration solution (currently being worked on), we'd have to drop the ability to append attributes via views.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, My earliest consideration was the implementation you mentioned. Perhaps a specific metric needs to extend attributes,that's very suitable,Considering the common attributes of metrics, such as clusters, planes, etc., If each metric needs to be configured separately, it would be a lot of work,So I adopted the SPI. Do you have any good suggestions for the common attributes of all metrics, There maybe be better way. @jack-berg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned this in slack, but the most correct solution is probably to create a delegating MetricExporter which enriches MetricData with the additional attributes before calling a subsequent MetricExporter. While probably the most correct solution, this is awkward because it requires you to provide your own implementations of the MetricData interfaces. There's an issue tracking this here.