Skip to content
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 meter provider configurer to change observable up down counter to… #89

Merged
merged 4 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import io.opentelemetry.sdk.resources.Resource;
import java.util.UUID;

/**
* Note this class is wired into SPI via {@code
* resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider}
*/
public class Customizer implements AutoConfigurationCustomizerProvider {

/**
* Add additional resource attributes programmatically. NOTE: This class is referenced in {@code
* /resources/META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider}.
*/
@Override
public void customize(AutoConfigurationCustomizer autoConfiguration) {
// Add additional resource attributes programmatically
autoConfiguration.addResourceCustomizer(
(resource, configProperties) ->
resource.merge(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.newrelic.otel.initializer;

import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.metrics.SdkMeterProviderConfigurer;
import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder;
import io.opentelemetry.sdk.metrics.common.InstrumentType;
import io.opentelemetry.sdk.metrics.view.Aggregation;
import io.opentelemetry.sdk.metrics.view.InstrumentSelector;
import io.opentelemetry.sdk.metrics.view.View;

/**
* Note this class is wired into SPI via {@code
* resources/META-INF/services/com.newrelic.otel.initializer.SdkMeterProviderConfigurer}
*/
public class MeterProviderCustomizer implements SdkMeterProviderConfigurer {

@Override
public void configure(SdkMeterProviderBuilder meterProviderBuilder, ConfigProperties config) {
// Aggregate OBSERVABLE_UP_DOWN_SUM as gauge instead of sum. This allows OBSERVABLE_UP_DOWN_SUM
// data to still be useful when aggregation temporality is set to DELTA.
meterProviderBuilder.registerView(
InstrumentSelector.builder()
.setInstrumentType(InstrumentType.OBSERVABLE_UP_DOWN_SUM)
.build(),
View.builder().setAggregation(Aggregation.lastValue()).build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.newrelic.otel.initializer.MeterProviderCustomizer
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
import io.opentelemetry.sdk.logs.SdkLogEmitterProvider;
import io.opentelemetry.sdk.logs.export.BatchLogProcessor;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.common.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import io.opentelemetry.sdk.metrics.view.Aggregation;
import io.opentelemetry.sdk.metrics.view.InstrumentSelector;
import io.opentelemetry.sdk.metrics.view.View;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
Expand Down Expand Up @@ -70,7 +74,16 @@ public static OpenTelemetrySdk configureGlobal(String defaultServiceName) {
}

// Configure metrics
var meterProviderBuilder = SdkMeterProvider.builder().setResource(resource);
var meterProviderBuilder =
SdkMeterProvider.builder()
.setResource(resource)
// Aggregate OBSERVABLE_UP_DOWN_SUM as gauge instead of sum. This allows OBSERVABLE_UP_DOWN_SUM
// data to still be useful when aggregation temporality is set to DELTA.
.registerView(
InstrumentSelector.builder()
.setInstrumentType(InstrumentType.OBSERVABLE_UP_DOWN_SUM)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to demonstrate changing the aggregation to last value for InstrumentType.UP_DOWN_COUNTER since those will be equally unusable as deltas.

... Also is it OBSERVABLE_UP_DOWN_SUM or OBSERVABLE_UP_DOWN_COUNTER?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last value doesn't help for sync up down counter because we would just get the last incremental recording. I.e. +1 or -1 or something liek that.

... Also is it OBSERVABLE_UP_DOWN_SUM or OBSERVABLE_UP_DOWN_COUNTER?

Its both. We recently deprecated OBSERVABLE_UP_DOWN_SUM in favor of OBSERVABLE_UP_DOWN_COUNTER

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last value doesn't help for sync up down counter because we would just get the last incremental recording. I.e. +1 or -1 or something liek that.

I promise, you'll only have to say this 16 more times.

.build(),
View.builder().setAggregation(Aggregation.lastValue()).build());

var metricExporterBuilder =
OtlpGrpcMetricExporter.builder()
Expand Down