fix(o11y): do not record error.type in successful runs by diegomarquezp · Pull Request #12620 · googleapis/google-cloud-java · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -205,9 +205,6 @@ private void recordErrorAndEndAttempt(Throwable error) {
return;
}

attemptSpan.setAttribute(
ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, ObservabilityUtils.extractErrorType(error));

Map<String, Object> statusAttributes = new HashMap<>();
ObservabilityUtils.populateStatusAttributes(
statusAttributes, error, this.apiTracerContext.transport());
Expand All @@ -220,6 +217,9 @@ private void recordErrorAndEndAttempt(Throwable error) {
return;
}

attemptSpan.setAttribute(
ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, ObservabilityUtils.extractErrorType(error));

attemptSpan.setAttribute(
ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE, error.getClass().getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class ErrorTypeUtilTest {

@Test
void testExtractErrorType_null() {
assertThat(ErrorTypeUtil.extractErrorType(null))
.isEqualTo(ErrorTypeUtil.ErrorType.INTERNAL.toString());
assertThat(ErrorTypeUtil.extractErrorType(null)).isNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,8 @@ void testAttemptFailed_internalFallback_nullError() {
// For an anonymous inner class Throwable, getSimpleName() is empty string,
// which triggers the
// fallback
verify(span)
.setAttribute(
ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE,
ErrorTypeUtil.ErrorType.INTERNAL.toString());
verify(span, never())
.setAttribute(eq(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), anyString());
verify(span).end();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import com.google.api.gax.tracing.CompositeTracerFactory;
import com.google.api.gax.tracing.GoldenSignalsMetricsTracerFactory;
import com.google.api.gax.tracing.LoggingTracerFactory;
import com.google.api.gax.tracing.ObservabilityAttributes;
import com.google.api.gax.tracing.SpanTracerFactory;
import com.google.showcase.v1beta1.EchoClient;
Expand All @@ -43,13 +42,13 @@
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -94,15 +93,16 @@ void tearDown() {

private CompositeTracerFactory createCompositeTracerFactory() {
SpanTracerFactory spanTracerFactory = new SpanTracerFactory(openTelemetrySdk);
GoldenSignalsMetricsTracerFactory metricsTracerFactory = new GoldenSignalsMetricsTracerFactory(openTelemetrySdk);
GoldenSignalsMetricsTracerFactory metricsTracerFactory =
new GoldenSignalsMetricsTracerFactory(openTelemetrySdk);

return new CompositeTracerFactory(Arrays.asList(spanTracerFactory, metricsTracerFactory));
}

@Test
void testCompositeTracer() throws Exception {
try (EchoClient client =
TestClientInitializer.createGrpcEchoClientOpentelemetry(createCompositeTracerFactory())) {
TestClientInitializer.createGrpcEchoClientOpentelemetry(createCompositeTracerFactory())) {

client.echo(EchoRequest.newBuilder().setContent("composite-tracing-test").build());

Expand All @@ -111,31 +111,37 @@ void testCompositeTracer() throws Exception {
assertThat(actualSpans).isNotEmpty();

SpanData attemptSpan =
actualSpans.stream()
.filter(span -> span.getName().equals("google.showcase.v1beta1.Echo/Echo"))
.findFirst()
.orElseThrow(() -> new AssertionError("Incorrect span name"));
actualSpans.stream()
.filter(span -> span.getName().equals("google.showcase.v1beta1.Echo/Echo"))
.findFirst()
.orElseThrow(() -> new AssertionError("Incorrect span name"));
assertThat(attemptSpan.getInstrumentationScopeInfo().getName()).isEqualTo(SHOWCASE_ARTIFACT);
assertThat(
attemptSpan
.getAttributes()
.get(AttributeKey.stringKey(ObservabilityAttributes.SERVER_ADDRESS_ATTRIBUTE)))
.isEqualTo(SHOWCASE_SERVER_ADDRESS);
.getAttributes()
.get(AttributeKey.stringKey(ObservabilityAttributes.SERVER_ADDRESS_ATTRIBUTE)))
.isEqualTo(SHOWCASE_SERVER_ADDRESS);

// Verify metric name and one basic attribute server.address
Collection<MetricData> actualMetrics = metricReader.collectAllMetrics();

assertThat(actualMetrics).isNotEmpty();
MetricData metricData = actualMetrics.stream()
MetricData metricData =
actualMetrics.stream()
.filter(metricData1 -> metricData1.getName().equals("gcp.client.request.duration"))
.findFirst()
.orElseThrow(() -> new AssertionError("Incorrect metric name"));
assertThat(metricData.getInstrumentationScopeInfo().getName()).isEqualTo(SHOWCASE_ARTIFACT);

assertThat(metricData.getHistogramData().getPoints().iterator().next()
.getAttributes()
.get(AttributeKey.stringKey(ObservabilityAttributes.SERVER_ADDRESS_ATTRIBUTE)))
.isEqualTo(SHOWCASE_SERVER_ADDRESS);
assertThat(
metricData
.getHistogramData()
.getPoints()
.iterator()
.next()
.getAttributes()
.get(AttributeKey.stringKey(ObservabilityAttributes.SERVER_ADDRESS_ATTRIBUTE)))
.isEqualTo(SHOWCASE_SERVER_ADDRESS);
}
}
}
Loading