diff --git a/build.gradle b/build.gradle index 049b4bf6..dec09006 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ subprojects { apply plugin: 'signing' group = "com.google.cloud.opentelemetry" - version = "0.12.0-SNAPSHOT" // CURRENT_VERSION + version = "0.13.1-SNAPSHOT" // CURRENT_VERSION sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 @@ -23,8 +23,8 @@ subprojects { slf4jVersion = '1.7.30' googleCloudVersion = '1.0.2' cloudMonitoringVersion = '2.0.1' - openTelemetryVersion = '0.11.0' - openTelemetryInstrumentationVersion = '0.11.0' + openTelemetryVersion = '0.13.1' + openTelemetryInstrumentationVersion = '0.13.1' junitVersion = '4.13' mockitoVersion = '3.5.10' diff --git a/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/MetricExporter.java b/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/MetricExporter.java index a533a126..f451527d 100644 --- a/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/MetricExporter.java +++ b/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/MetricExporter.java @@ -173,8 +173,10 @@ public CompletableResultCode flush() { } @Override - public void shutdown() { + public CompletableResultCode shutdown() { metricServiceClient.shutdown(); + + return CompletableResultCode.ofSuccess(); } static class MetricWithLabels { diff --git a/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/MetricTranslator.java b/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/MetricTranslator.java index 80c29819..d8be3aa3 100644 --- a/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/MetricTranslator.java +++ b/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/MetricTranslator.java @@ -1,9 +1,9 @@ package com.google.cloud.opentelemetry.metric; -import static io.opentelemetry.sdk.metrics.data.MetricData.Type.MONOTONIC_DOUBLE; -import static io.opentelemetry.sdk.metrics.data.MetricData.Type.MONOTONIC_LONG; -import static io.opentelemetry.sdk.metrics.data.MetricData.Type.NON_MONOTONIC_DOUBLE; -import static io.opentelemetry.sdk.metrics.data.MetricData.Type.NON_MONOTONIC_LONG; +import static io.opentelemetry.sdk.metrics.data.MetricData.Type.DOUBLE_GAUGE; +import static io.opentelemetry.sdk.metrics.data.MetricData.Type.DOUBLE_SUM; +import static io.opentelemetry.sdk.metrics.data.MetricData.Type.LONG_GAUGE; +import static io.opentelemetry.sdk.metrics.data.MetricData.Type.LONG_SUM; import com.google.api.LabelDescriptor; import com.google.api.Metric; @@ -37,10 +37,10 @@ public class MetricTranslator { static final long NANO_PER_SECOND = (long) 1e9; static final String METRIC_DESCRIPTOR_TIME_UNIT = "ns"; - static final Set GAUGE_TYPES = ImmutableSet.of(NON_MONOTONIC_LONG, NON_MONOTONIC_DOUBLE); - static final Set CUMULATIVE_TYPES = ImmutableSet.of(MONOTONIC_LONG, MONOTONIC_DOUBLE); - static final Set LONG_TYPES = ImmutableSet.of(NON_MONOTONIC_LONG, MONOTONIC_LONG); - static final Set DOUBLE_TYPES = ImmutableSet.of(NON_MONOTONIC_DOUBLE, MONOTONIC_DOUBLE); + static final Set GAUGE_TYPES = ImmutableSet.of(LONG_GAUGE, DOUBLE_GAUGE); + static final Set CUMULATIVE_TYPES = ImmutableSet.of(LONG_SUM, DOUBLE_SUM); + static final Set LONG_TYPES = ImmutableSet.of(LONG_GAUGE, LONG_SUM); + static final Set DOUBLE_TYPES = ImmutableSet.of(DOUBLE_GAUGE, DOUBLE_SUM); private static final int MIN_TIMESTAMP_INTERVAL_NANOS = 1000000; static Metric mapMetric(MetricData.Point metricPoint, String type) { diff --git a/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/FakeData.java b/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/FakeData.java index 5b94a7fe..3974efbf 100644 --- a/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/FakeData.java +++ b/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/FakeData.java @@ -48,17 +48,26 @@ public class FakeData { Labels.of("label1", "value1", "label2", "False"), 32L); + static final Point aDoublePoint = + MetricData.DoublePoint.create( + 1599030114 * NANO_PER_SECOND, + 1599031814 * NANO_PER_SECOND, + Labels.of("label1", "value1", "label2", "False"), + 32d); + // The name does not have to start with "opentelemetry/", it is set this way because of a bug in // the mock server, // and should be changed when the following issue is resolved: // https://github.com/googleinterns/cloud-operations-api-mock/issues/56 static final MetricData aMetricData = - MetricData.create( + MetricData.createLongSum( aGceResource, anInstrumentationLibraryInfo, "opentelemetry/name", "description", "ns", - Type.MONOTONIC_LONG, - ImmutableList.of(aLongPoint)); + MetricData.LongSumData.create( + true, + MetricData.AggregationTemporality.CUMULATIVE, + ImmutableList.of(aLongPoint))); } diff --git a/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/MetricExporterTest.java b/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/MetricExporterTest.java index beb2f8b9..9f57908d 100644 --- a/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/MetricExporterTest.java +++ b/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/MetricExporterTest.java @@ -3,6 +3,7 @@ import static com.google.cloud.opentelemetry.metric.FakeData.aFakeCredential; import static com.google.cloud.opentelemetry.metric.FakeData.aGceResource; import static com.google.cloud.opentelemetry.metric.FakeData.aLongPoint; +import static com.google.cloud.opentelemetry.metric.FakeData.aDoublePoint; import static com.google.cloud.opentelemetry.metric.FakeData.aMetricData; import static com.google.cloud.opentelemetry.metric.FakeData.aProjectId; import static com.google.cloud.opentelemetry.metric.FakeData.anInstrumentationLibraryInfo; @@ -153,14 +154,13 @@ public void testExportWithNonSupportedMetricTypeReturnsFailure() { MetricExporter exporter = MetricExporter.createWithClient(aProjectId, mockClient); MetricData metricData = - MetricData.create( + MetricData.createDoubleSummary( aGceResource, anInstrumentationLibraryInfo, "Metric Name", "description", "ns", - Type.SUMMARY, - ImmutableList.of(aLongPoint)); + MetricData.DoubleSummaryData.create(ImmutableList.of(aDoublePoint))); CompletableResultCode result = exporter.export(ImmutableList.of(metricData)); verify(mockClient, times(0)).createMetricDescriptor(any()); diff --git a/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/MetricTranslatorTest.java b/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/MetricTranslatorTest.java index 2933f322..7a9de924 100644 --- a/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/MetricTranslatorTest.java +++ b/exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/MetricTranslatorTest.java @@ -1,6 +1,7 @@ package com.google.cloud.opentelemetry.metric; import static com.google.cloud.opentelemetry.metric.FakeData.aGceResource; +import static com.google.cloud.opentelemetry.metric.FakeData.aDoublePoint; import static com.google.cloud.opentelemetry.metric.FakeData.aLongPoint; import static com.google.cloud.opentelemetry.metric.FakeData.aMetricData; import static com.google.cloud.opentelemetry.metric.FakeData.anInstrumentationLibraryInfo; @@ -69,14 +70,13 @@ public void testMapMetricDescriptorWithInvalidMetricKindReturnsNull() { String description = "Metric Description"; String unit = "ns"; MetricData metricData = - MetricData.create( + MetricData.createDoubleSummary( aGceResource, anInstrumentationLibraryInfo, name, description, unit, - Type.SUMMARY, - ImmutableList.of(aLongPoint)); + MetricData.DoubleSummaryData.create(ImmutableList.of(aDoublePoint))); MetricDescriptor actualDescriptor = MetricTranslator.mapMetricDescriptor(metricData, aLongPoint); diff --git a/exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/TraceTranslator.java b/exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/TraceTranslator.java index d153fad7..d68c3d7e 100644 --- a/exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/TraceTranslator.java +++ b/exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/TraceTranslator.java @@ -13,10 +13,9 @@ import com.google.devtools.cloudtrace.v2.TruncatableString; import com.google.protobuf.BoolValue; import com.google.rpc.Status; -import io.opentelemetry.api.common.AttributeConsumer; import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.ReadableAttributes; import io.opentelemetry.api.trace.Span.Kind; +import io.opentelemetry.api.trace.StatusCode; import io.opentelemetry.sdk.trace.data.SpanData; import io.opentelemetry.sdk.trace.data.SpanData.Event; import java.util.Collections; @@ -24,6 +23,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; class TraceTranslator { @@ -116,7 +116,7 @@ static com.google.protobuf.Timestamp toTimestampProto(long epochNanos) { // attributes like the agent. @VisibleForTesting static Attributes toAttributesProto( - ReadableAttributes attributes, Map fixedAttributes) { + io.opentelemetry.api.common.Attributes attributes, Map fixedAttributes) { Attributes.Builder attributesBuilder = toAttributesBuilderProto(attributes); attributesBuilder.putAttributeMap(AGENT_LABEL_KEY, AGENT_LABEL_VALUE); for (Map.Entry entry : fixedAttributes.entrySet()) { @@ -129,14 +129,14 @@ private static Attributes toAttributesProto(io.opentelemetry.api.common.Attribut return toAttributesProto(attributes, ImmutableMap.of()); } - private static Attributes.Builder toAttributesBuilderProto(ReadableAttributes attributes) { + private static Attributes.Builder toAttributesBuilderProto(io.opentelemetry.api.common.Attributes attributes) { Attributes.Builder attributesBuilder = // TODO (nilebox): Does OpenTelemetry support droppedAttributesCount? Attributes.newBuilder().setDroppedAttributesCount(0); attributes.forEach( - new AttributeConsumer() { + new BiConsumer, Object>() { @Override - public void accept(AttributeKey key, T value) { + public void accept(AttributeKey key, Object value) { attributesBuilder.putAttributeMap(mapKey(key), toAttributeValueProto(key, value)); } }); @@ -189,7 +189,23 @@ static Span.TimeEvents toTimeEventsProto(List events) { @VisibleForTesting static Status toStatusProto(SpanData.Status status) { - Status.Builder statusBuilder = Status.newBuilder().setCode(status.getStatusCode().value()); + + final Status.Builder statusBuilder = Status.newBuilder(); + + final StatusCode statusCode = status.getStatusCode(); + switch (statusCode) { + case OK: + statusBuilder.setCode(0); + break; + case UNSET: + statusBuilder.setCode(1); + break; + case ERROR: + statusBuilder.setCode(2); + break; + + } + if (status.getDescription() != null) { statusBuilder.setMessage(status.getDescription()); } diff --git a/exporters/trace/src/test/java/com/google/cloud/opentelemetry/trace/TestSpanData.java b/exporters/trace/src/test/java/com/google/cloud/opentelemetry/trace/TestSpanData.java index 7ef1f668..c772f49c 100644 --- a/exporters/trace/src/test/java/com/google/cloud/opentelemetry/trace/TestSpanData.java +++ b/exporters/trace/src/test/java/com/google/cloud/opentelemetry/trace/TestSpanData.java @@ -26,17 +26,18 @@ import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.ReadableAttributes; import io.opentelemetry.api.trace.Span.Kind; +import io.opentelemetry.api.trace.SpanContext; import io.opentelemetry.api.trace.SpanId; import io.opentelemetry.api.trace.TraceState; import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.data.SpanData; + +import javax.annotation.concurrent.Immutable; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import javax.annotation.concurrent.Immutable; /** * Immutable representation of all data collected by the {@link io.opentelemetry.api.trace.Span} @@ -57,6 +58,7 @@ public abstract class TestSpanData implements SpanData { public static Builder newBuilder() { return new AutoValue_TestSpanData.Builder() .setParentSpanId(SpanId.getInvalid()) + .setParentSpanContext(SpanContext.getInvalid()) .setInstrumentationLibraryInfo(InstrumentationLibraryInfo.getEmpty()) .setLinks(Collections.emptyList()) .setTotalRecordedLinks(0) @@ -74,6 +76,9 @@ public static Builder newBuilder() { abstract boolean getInternalHasRemoteParent(); + @Override + public abstract String getParentSpanId(); + @Override public final boolean hasEnded() { return getInternalHasEnded(); @@ -145,6 +150,14 @@ public TestSpanData build() { */ public abstract Builder setParentSpanId(String parentSpanId); + /** + * The parent SpanContext associated for this span, which may be null. + * + * @param parentSpanContext the SpanContext of the parent + * @return this. + */ + public abstract Builder setParentSpanContext(SpanContext parentSpanContext); + /** * Set the {@link Resource} associated with this span. Must not be null. * @@ -200,7 +213,7 @@ public abstract Builder setInstrumentationLibraryInfo( * @return this * @since 0.1.0 */ - public abstract Builder setAttributes(ReadableAttributes attributes); + public abstract Builder setAttributes(Attributes attributes); /** * Set timed events that are associated with this span. Must not be null, may be empty.