Skip to content

Commit 5fb62e8

Browse files
committed
wip: exposing the create functions and correcting the code example in DelegatingMetricData class comment.
1 parent b992e17 commit 5fb62e8

17 files changed

+339
-22
lines changed

docs/apidiffs/current_vs_latest/opentelemetry-sdk-metrics.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,46 @@ Comparing source compatibility of opentelemetry-sdk-metrics-1.48.0-SNAPSHOT.jar
1313
+++ NEW METHOD: PUBLIC(+) java.lang.String getUnit()
1414
+++ NEW METHOD: PUBLIC(+) int hashCode()
1515
+++ NEW METHOD: PUBLIC(+) java.lang.String toString()
16+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.DoubleExemplarData (not serializable)
17+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
18+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.DoubleExemplarData create(io.opentelemetry.api.common.Attributes, long, io.opentelemetry.api.trace.SpanContext, double)
19+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.DoublePointData (not serializable)
20+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
21+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.DoublePointData create(long, long, io.opentelemetry.api.common.Attributes, double)
22+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets (not serializable)
23+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
24+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets create(int, int, java.util.List<java.lang.Long>)
25+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.ExponentialHistogramData (not serializable)
26+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
27+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramData create(io.opentelemetry.sdk.metrics.data.AggregationTemporality, java.util.Collection<io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData>)
28+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData (not serializable)
29+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
30+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.ExponentialHistogramPointData create(int, double, long, boolean, double, boolean, double, io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets, io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets, long, long, io.opentelemetry.api.common.Attributes, java.util.List<io.opentelemetry.sdk.metrics.data.DoubleExemplarData>)
31+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.GaugeData (not serializable)
32+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
33+
GENERIC TEMPLATES: === T:io.opentelemetry.sdk.metrics.data.PointData
34+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData<T> create(java.util.Collection<T>)
35+
GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.metrics.data.PointData
36+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.HistogramData (not serializable)
37+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
38+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.HistogramData create(io.opentelemetry.sdk.metrics.data.AggregationTemporality, java.util.Collection<io.opentelemetry.sdk.metrics.data.HistogramPointData>)
39+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.LongExemplarData (not serializable)
40+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
41+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.LongExemplarData create(io.opentelemetry.api.common.Attributes, long, io.opentelemetry.api.trace.SpanContext, long)
42+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.LongPointData (not serializable)
43+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
44+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.LongPointData create(long, long, io.opentelemetry.api.common.Attributes, long)
45+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.SumData (not serializable)
46+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
47+
GENERIC TEMPLATES: === T:io.opentelemetry.sdk.metrics.data.PointData
48+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.internal.data.ImmutableSumData<T> create(boolean, io.opentelemetry.sdk.metrics.data.AggregationTemporality, java.util.Collection<T>)
49+
GENERIC TEMPLATES: +++ T:io.opentelemetry.sdk.metrics.data.PointData
50+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.SummaryData (not serializable)
51+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
52+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.SummaryData create(java.util.Collection<io.opentelemetry.sdk.metrics.data.SummaryPointData>)
53+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.SummaryPointData (not serializable)
54+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
55+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryPointData create(long, long, io.opentelemetry.api.common.Attributes, long, double, java.util.List<io.opentelemetry.sdk.metrics.data.ValueAtQuantile>)
56+
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.metrics.data.ValueAtQuantile (not serializable)
57+
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
58+
+++ NEW METHOD: PUBLIC(+) STATIC(+) io.opentelemetry.sdk.metrics.data.ValueAtQuantile create(double, double)

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DelegatingMetricData.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@
1717
* custom implementation.
1818
*
1919
* <pre>{@code
20-
* // class MetricDataWithCustomAttributes extends DelegatingMetricData {
20+
* // class MetricDataWithCustomDescription extends DelegatingMetricData {
2121
* //
22-
* // private final Attributes attributes;
22+
* // private final String description;
2323
* //
24-
* // MetricDataWithCustomAttributes(MetricData delegate) {
24+
* // MetricDataWithCustomDescription(MetricData delegate) {
2525
* // super(delegate);
26-
* // Attributes.Builder newAttributes = Attributes.builder(delegate.getAttributes());
27-
* // newAttributes.put("custom_key", "custom_value");
28-
* // attributes = newAttributes.build();
26+
* // this.description = delegate.getDescription() + " (custom)";
2927
* // }
3028
* //
3129
* // @Override
32-
* // public Attributes getAttributes() {
33-
* // return attributes;
30+
* // public String getDescription() {
31+
* // return description;
3432
* // }
3533
* // }
3634
* }</pre>

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoubleExemplarData.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.trace.SpanContext;
10+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoubleExemplarData;
811
import javax.annotation.concurrent.Immutable;
912

1013
/**
@@ -14,6 +17,22 @@
1417
*/
1518
@Immutable
1619
public interface DoubleExemplarData extends ExemplarData {
20+
21+
/**
22+
* Construct a new exemplar.
23+
*
24+
* @param filteredAttributes The set of {@link Attributes} not already associated with the {@link
25+
* PointData}.
26+
* @param recordTimeNanos The time when the sample qas recorded in nanoseconds.
27+
* @param spanContext The associated span context.
28+
* @param value The value recorded.
29+
*/
30+
static DoubleExemplarData create(
31+
Attributes filteredAttributes, long recordTimeNanos, SpanContext spanContext, double value) {
32+
return ImmutableDoubleExemplarData.create(
33+
filteredAttributes, recordTimeNanos, spanContext, value);
34+
}
35+
1736
/** Numerical value of the measurement that was recorded. */
1837
double getValue();
1938
}

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/DoublePointData.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableDoublePointData;
10+
import java.util.Collections;
811
import java.util.List;
912

1013
/**
@@ -13,6 +16,23 @@
1316
* @since 1.14.0
1417
*/
1518
public interface DoublePointData extends PointData {
19+
20+
/**
21+
* Creates a {@link DoublePointData}.
22+
*
23+
* @param startEpochNanos The starting time for the period where this point was sampled. Note:
24+
* While start time is optional in OTLP, all SDKs should produce it for all their metrics, so
25+
* it is required here.
26+
* @param epochNanos The ending time for the period when this value was sampled.
27+
* @param attributes The set of attributes associated with this point.
28+
* @param value The value that was sampled.
29+
*/
30+
static DoublePointData create(
31+
long startEpochNanos, long epochNanos, Attributes attributes, double value) {
32+
return ImmutableDoublePointData.create(
33+
startEpochNanos, epochNanos, attributes, value, Collections.emptyList());
34+
}
35+
1636
/** Returns the value of the data point. */
1737
double getValue();
1838

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramBuckets.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramBuckets;
89
import java.util.List;
910
import javax.annotation.concurrent.Immutable;
1011

@@ -25,6 +26,16 @@
2526
@Immutable
2627
public interface ExponentialHistogramBuckets {
2728

29+
/**
30+
* Create a ExponentialHistogramBuckets.
31+
*
32+
* @return a ExponentialHistogramBuckets.
33+
*/
34+
@SuppressWarnings("TooManyParameters")
35+
static ExponentialHistogramBuckets create(int scale, int offset, List<Long> bucketCounts) {
36+
return ImmutableExponentialHistogramBuckets.create(scale, offset, bucketCounts);
37+
}
38+
2839
/** The scale of the buckets. Must align with {@link ExponentialHistogramPointData#getScale()}. */
2940
int getScale();
3041

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramData.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramData;
89
import java.util.Collection;
910
import javax.annotation.concurrent.Immutable;
1011

@@ -15,15 +16,21 @@
1516
* <p><i>Note: This is called "ExponentialHistogramData" to reflect which primitives are used to
1617
* record it, however "ExponentialHistogram" is the equivalent OTLP type.</i>
1718
*
18-
* @see <a
19-
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#exponentialhistogram">Exponential
19+
* @see <a href=
20+
* "https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#exponentialhistogram">Exponential
2021
* Histogram Data Model</a>
2122
* @see ExponentialHistogramPointData
2223
* @since 1.23.0
2324
*/
2425
@Immutable
2526
public interface ExponentialHistogramData extends Data<ExponentialHistogramPointData> {
2627

28+
/** Returns a new {@link ExponentialHistogramData}. */
29+
static ExponentialHistogramData create(
30+
AggregationTemporality temporality, Collection<ExponentialHistogramPointData> points) {
31+
return ImmutableExponentialHistogramData.create(temporality, points);
32+
}
33+
2734
/**
2835
* Returns the {@code AggregationTemporality} of this metric.
2936
*

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/ExponentialHistogramPointData.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableExponentialHistogramPointData;
810
import java.util.List;
911
import javax.annotation.concurrent.Immutable;
1012

@@ -24,6 +26,43 @@
2426
@Immutable
2527
public interface ExponentialHistogramPointData extends PointData {
2628

29+
/**
30+
* Create a DoubleExponentialHistogramPointData.
31+
*
32+
* @return a DoubleExponentialHistogramPointData.
33+
*/
34+
@SuppressWarnings("TooManyParameters")
35+
static ExponentialHistogramPointData create(
36+
int scale,
37+
double sum,
38+
long zeroCount,
39+
boolean hasMin,
40+
double min,
41+
boolean hasMax,
42+
double max,
43+
ExponentialHistogramBuckets positiveBuckets,
44+
ExponentialHistogramBuckets negativeBuckets,
45+
long startEpochNanos,
46+
long epochNanos,
47+
Attributes attributes,
48+
List<DoubleExemplarData> exemplars) {
49+
50+
return ImmutableExponentialHistogramPointData.create(
51+
scale,
52+
sum,
53+
zeroCount,
54+
hasMin,
55+
min,
56+
hasMax,
57+
max,
58+
positiveBuckets,
59+
negativeBuckets,
60+
startEpochNanos,
61+
epochNanos,
62+
attributes,
63+
exemplars);
64+
}
65+
2766
/**
2867
* Scale characterises the resolution of the histogram, with larger values of scale offering
2968
* greater precision. Bucket boundaries of the histogram are located at integer powers of the

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/GaugeData.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableGaugeData;
9+
import java.util.Collection;
810
import javax.annotation.concurrent.Immutable;
911

1012
/**
@@ -13,4 +15,16 @@
1315
* @since 1.14.0
1416
*/
1517
@Immutable
16-
public interface GaugeData<T extends PointData> extends Data<T> {}
18+
public interface GaugeData<T extends PointData> extends Data<T> {
19+
20+
/**
21+
* Creates an instance of {@link ImmutableGaugeData} with the given collection of points.
22+
*
23+
* @param <T> the type of the point data
24+
* @param points the collection of points to be included in the gauge data
25+
* @return an instance of {@link ImmutableGaugeData} containing the provided points
26+
*/
27+
static <T extends PointData> ImmutableGaugeData<T> create(Collection<T> points) {
28+
return ImmutableGaugeData.create(points);
29+
}
30+
}

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/HistogramData.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramData;
89
import java.util.Collection;
910
import javax.annotation.concurrent.Immutable;
1011

@@ -15,6 +16,19 @@
1516
*/
1617
@Immutable
1718
public interface HistogramData extends Data<HistogramPointData> {
19+
20+
/**
21+
* Creates a new instance of {@link HistogramData}.
22+
*
23+
* @param temporality the aggregation temporality of the histogram data
24+
* @param points the collection of histogram point data
25+
* @return a new instance of {@link HistogramData}
26+
*/
27+
static HistogramData create(
28+
AggregationTemporality temporality, Collection<HistogramPointData> points) {
29+
return ImmutableHistogramData.create(temporality, points);
30+
}
31+
1832
/** Returns the histogram {@link AggregationTemporality}. */
1933
AggregationTemporality getAggregationTemporality();
2034

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/HistogramPointData.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,54 @@
55

66
package io.opentelemetry.sdk.metrics.data;
77

8+
import java.util.Collections;
89
import java.util.List;
910
import javax.annotation.concurrent.Immutable;
1011

12+
import io.opentelemetry.api.common.Attributes;
13+
import io.opentelemetry.sdk.metrics.internal.data.ImmutableHistogramPointData;
14+
1115
/**
1216
* Point data for {@link HistogramData}.
1317
*
1418
* @since 1.14.0
1519
*/
1620
@Immutable
1721
public interface HistogramPointData extends PointData {
22+
23+
/**
24+
* Creates a HistogramPointData. For a Histogram with N defined boundaries, there should be N+1
25+
* counts.
26+
*
27+
* @return a HistogramPointData.
28+
* @throws IllegalArgumentException if the given boundaries/counts were invalid
29+
*/
30+
@SuppressWarnings("TooManyParameters")
31+
static HistogramPointData create(
32+
long startEpochNanos,
33+
long epochNanos,
34+
Attributes attributes,
35+
double sum,
36+
boolean hasMin,
37+
double min,
38+
boolean hasMax,
39+
double max,
40+
List<Double> boundaries,
41+
List<Long> counts) {
42+
return ImmutableHistogramPointData.create(
43+
startEpochNanos,
44+
epochNanos,
45+
attributes,
46+
sum,
47+
hasMin,
48+
min,
49+
hasMax,
50+
max,
51+
boundaries,
52+
counts,
53+
Collections.emptyList());
54+
}
55+
1856
/**
1957
* The sum of all measurements recorded.
2058
*

0 commit comments

Comments
 (0)