From 98d3a24e32ce285a09c18198f2e7cdf1a6b15e20 Mon Sep 17 00:00:00 2001 From: Sydney Munro Date: Wed, 30 Oct 2024 11:16:25 -0700 Subject: [PATCH 1/6] feat: Instrument HTTP Reads and Writes --- .../com/google/cloud/storage/spi/v1/HttpStorageRpc.java | 8 ++++++++ .../com/google/cloud/storage/ITHttpOpenTelemetryTest.java | 3 +++ 2 files changed, 11 insertions(+) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java index bb69d83000..2ef146334c 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java @@ -1856,4 +1856,12 @@ private static StorageException buildStorageException(int statusCode, String sta error.setMessage(statusMessage); return translate(error); } + private static StorageException buildStorageException(int statusCode, String statusMessage, OpenTelemetryTraceUtil.Span otelSpan) { + GoogleJsonError error = new GoogleJsonError(); + error.setCode(statusCode); + error.setMessage(statusMessage); + StorageException ex = translate(error); + otelSpan.recordException(ex); + return ex; + } } diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java index afe7884445..e231ad971d 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java @@ -16,7 +16,9 @@ package com.google.cloud.storage; +import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.Assert.fail; import com.google.cloud.NoCredentials; import com.google.cloud.storage.Storage.BlobSourceOption; @@ -57,6 +59,7 @@ public class ITHttpOpenTelemetryTest { @Inject public Generator generator; @Inject public BucketInfo testBucket; + @Before public void setUp() { exporter = new TestExporter(); From b391316401783373a90f7bb46e0a0cc7fbbd386f Mon Sep 17 00:00:00 2001 From: Sydney Munro Date: Mon, 4 Nov 2024 15:51:53 -0800 Subject: [PATCH 2/6] Add tests --- .../com/google/cloud/storage/spi/v1/HttpStorageRpc.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java index 2ef146334c..bb69d83000 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java @@ -1856,12 +1856,4 @@ private static StorageException buildStorageException(int statusCode, String sta error.setMessage(statusMessage); return translate(error); } - private static StorageException buildStorageException(int statusCode, String statusMessage, OpenTelemetryTraceUtil.Span otelSpan) { - GoogleJsonError error = new GoogleJsonError(); - error.setCode(statusCode); - error.setMessage(statusMessage); - StorageException ex = translate(error); - otelSpan.recordException(ex); - return ex; - } } From e6d814af3c44c22294cf069da1f9f51b1b49dd7c Mon Sep 17 00:00:00 2001 From: Sydney Munro Date: Tue, 5 Nov 2024 08:13:42 -0800 Subject: [PATCH 3/6] lint --- .../com/google/cloud/storage/ITHttpOpenTelemetryTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java index e231ad971d..37b755ae9e 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java @@ -16,9 +16,7 @@ package com.google.cloud.storage; -import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.fail; import com.google.cloud.NoCredentials; import com.google.cloud.storage.Storage.BlobSourceOption; @@ -59,7 +57,6 @@ public class ITHttpOpenTelemetryTest { @Inject public Generator generator; @Inject public BucketInfo testBucket; - @Before public void setUp() { exporter = new TestExporter(); @@ -152,6 +149,8 @@ private void checkCommonAttributes(List spanData) { "com.google.cloud.google-cloud-storage", getAttributeValue(span, "gcp.client.artifact")); Assert.assertEquals("http", getAttributeValue(span, "rpc.system")); } + Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("openRewrite"))); + Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("rewrite"))); } private String getAttributeValue(SpanData spanData, String key) { From d5c11756ebfa188e6d283ae84682b657b58f1a79 Mon Sep 17 00:00:00 2001 From: Sydney Munro Date: Thu, 7 Nov 2024 10:50:21 -0800 Subject: [PATCH 4/6] refactor test logic --- .../java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java index 37b755ae9e..afe7884445 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/ITHttpOpenTelemetryTest.java @@ -149,8 +149,6 @@ private void checkCommonAttributes(List spanData) { "com.google.cloud.google-cloud-storage", getAttributeValue(span, "gcp.client.artifact")); Assert.assertEquals("http", getAttributeValue(span, "rpc.system")); } - Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("openRewrite"))); - Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("rewrite"))); } private String getAttributeValue(SpanData spanData, String key) { From ceb116f9bdd63858e3e717cd959bbf08e094cdd6 Mon Sep 17 00:00:00 2001 From: Sydney Munro Date: Fri, 8 Nov 2024 09:12:38 -0800 Subject: [PATCH 5/6] feat: Take in a module name when creating a span --- .../google/cloud/storage/GrpcStorageImpl.java | 12 ++++++---- .../otel/NoOpOpenTelemetryInstance.java | 4 ++-- .../storage/otel/OpenTelemetryInstance.java | 8 +++---- .../storage/otel/OpenTelemetryTraceUtil.java | 4 ++-- .../cloud/storage/spi/v1/HttpStorageRpc.java | 22 +++++++++++++------ 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java index 5a16b6c299..e0bfa27a5a 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java @@ -148,6 +148,7 @@ final class GrpcStorageImpl extends BaseService StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); private static final BucketSourceOption[] EMPTY_BUCKET_SOURCE_OPTIONS = new BucketSourceOption[0]; + private static final String OTEL_MODULE_NAME = "storage.client"; private static final Opts ALL_BLOB_FIELDS = Opts.from(UnifiedOpts.fields(ImmutableSet.copyOf(BlobField.values()))); @@ -201,7 +202,8 @@ public void close() throws Exception { @Override public Bucket create(BucketInfo bucketInfo, BucketTargetOption... options) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("create"); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); Opts opts = Opts.unwrap(options).resolveFrom(bucketInfo).prepend(defaultOpts); GrpcCallContext grpcCallContext = opts.grpcMetadataMapper().apply(GrpcCallContext.createDefault()); @@ -248,7 +250,8 @@ public Blob create( BlobInfo blobInfo, byte[] content, int offset, int length, BlobTargetOption... options) { Opts opts = Opts.unwrap(options).resolveFrom(blobInfo); // Start the otel span to retain information of the origin of the request - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("create"); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { return internalDirectUpload( blobInfo, @@ -267,7 +270,8 @@ public Blob create( @Override public Blob create(BlobInfo blobInfo, InputStream content, BlobWriteOption... options) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("create"); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); try (OpenTelemetryTraceUtil.Scope ununsed = otelSpan.makeCurrent()) { requireNonNull(blobInfo, "blobInfo must be non null"); InputStream inputStreamParam = firstNonNull(content, new ByteArrayInputStream(ZERO_BYTES)); @@ -830,7 +834,7 @@ public BlobInfo internalDirectUpload( requireNonNull(blobInfo, "blobInfo must be non null"); requireNonNull(buf, "content must be non null"); OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("internalDirectUpload(BlobInfo)", ctx); + openTelemetryTraceUtil.startSpan("internalDirectUpload(BlobInfo)", OTEL_MODULE_NAME, ctx); Opts optsWithDefaults = opts.prepend(defaultOpts); GrpcCallContext grpcCallContext = optsWithDefaults.grpcMetadataMapper().apply(GrpcCallContext.createDefault()); diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/NoOpOpenTelemetryInstance.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/NoOpOpenTelemetryInstance.java index 814dbafdc4..0106f18f86 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/NoOpOpenTelemetryInstance.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/NoOpOpenTelemetryInstance.java @@ -24,13 +24,13 @@ class NoOpOpenTelemetryInstance implements OpenTelemetryTraceUtil { @Override - public OpenTelemetryTraceUtil.Span startSpan(String spanName) { + public OpenTelemetryTraceUtil.Span startSpan(String spanName, String module) { return new Span(); } @Override public OpenTelemetryTraceUtil.Span startSpan( - String spanName, OpenTelemetryTraceUtil.Context parent) { + String spanName, String module, OpenTelemetryTraceUtil.Context parent) { return new Span(); } diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/OpenTelemetryInstance.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/OpenTelemetryInstance.java index d7ce734c07..1c0718fce4 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/OpenTelemetryInstance.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/OpenTelemetryInstance.java @@ -153,8 +153,8 @@ public Scope makeCurrent() { } @Override - public OpenTelemetryTraceUtil.Span startSpan(String methodName) { - String formatSpanName = String.format("%s.%s/%s", "storage", "client", methodName); + public OpenTelemetryTraceUtil.Span startSpan(String methodName, String module) { + String formatSpanName = String.format("%s/%s", module, methodName); SpanBuilder spanBuilder = tracer.spanBuilder(formatSpanName).setSpanKind(SpanKind.CLIENT); io.opentelemetry.api.trace.Span span = addSettingsAttributesToCurrentSpan(spanBuilder).startSpan(); @@ -163,9 +163,9 @@ public OpenTelemetryTraceUtil.Span startSpan(String methodName) { @Override public OpenTelemetryTraceUtil.Span startSpan( - String methodName, OpenTelemetryTraceUtil.Context parent) { + String methodName, String module, OpenTelemetryTraceUtil.Context parent) { assert (parent instanceof OpenTelemetryInstance.Context); - String formatSpanName = String.format("%s.%s/%s", "storage", "client", methodName); + String formatSpanName = String.format("%s/%s", module, methodName); SpanBuilder spanBuilder = tracer .spanBuilder(formatSpanName) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/OpenTelemetryTraceUtil.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/OpenTelemetryTraceUtil.java index 932457d05e..a99b1da954 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/OpenTelemetryTraceUtil.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/otel/OpenTelemetryTraceUtil.java @@ -76,13 +76,13 @@ interface Scope extends AutoCloseable { } /** Starts a new span with the given name, sets it as the current span, and returns it. */ - Span startSpan(String spanName); + Span startSpan(String spanName, String module); /** * Starts a new span with the given name and the given context as its parent, sets it as the * current span, and returns it. */ - Span startSpan(String spanName, Context parent); + Span startSpan(String spanName, String module, Context parent); /** Returns the current span. */ @Nonnull diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java index bb69d83000..c990877cc0 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java @@ -106,6 +106,7 @@ public class HttpStorageRpc implements StorageRpc { public static final String NO_ACL_PROJECTION = "noAcl"; private static final String ENCRYPTION_KEY_PREFIX = "x-goog-encryption-"; private static final String SOURCE_ENCRYPTION_KEY_PREFIX = "x-goog-copy-source-encryption-"; + private static final String OTEL_MODULE_NAME = "storage.spi.v1"; // declare this HttpStatus code here as it's not included in java.net.HttpURLConnection private static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416; @@ -360,7 +361,8 @@ private Span startSpan(String spanName) { @Override public Bucket create(Bucket bucket, Map options) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("create"); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_BUCKET); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -388,7 +390,8 @@ public Bucket create(Bucket bucket, Map options) { @Override public StorageObject create( StorageObject storageObject, final InputStream content, Map options) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("create"); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_OBJECT); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -848,7 +851,8 @@ private Get createReadRequest(StorageObject from, Map options) throws @Override public long read( StorageObject from, Map options, long position, OutputStream outputStream) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("read"); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("read", OTEL_MODULE_NAME); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_READ); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -886,7 +890,8 @@ public long read( @Override public Tuple read( StorageObject from, Map options, long position, int bytes) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("read"); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("read", OTEL_MODULE_NAME); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_READ); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -1166,7 +1171,8 @@ public String open(String signedURL) { @Override public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("openRewrite"); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("openRewrite", OTEL_MODULE_NAME); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_OPEN_REWRITE); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -1180,7 +1186,8 @@ public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { @Override public RewriteResponse continueRewrite(RewriteResponse previousResponse) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("continueRewrite"); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("continueRewrite", OTEL_MODULE_NAME); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CONTINUE_REWRITE); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -1197,7 +1204,8 @@ public RewriteResponse continueRewrite(RewriteResponse previousResponse) { private RewriteResponse rewrite( RewriteRequest req, String token, OpenTelemetryTraceUtil.Context ctx) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("rewrite", ctx); + OpenTelemetryTraceUtil.Span otelSpan = + openTelemetryTraceUtil.startSpan("rewrite", OTEL_MODULE_NAME, ctx); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { String userProject = Option.USER_PROJECT.getString(req.sourceOptions); if (userProject == null) { From 6605f94d2600437ca94492011d992f7586053281 Mon Sep 17 00:00:00 2001 From: Sydney Munro Date: Fri, 8 Nov 2024 13:10:07 -0800 Subject: [PATCH 6/6] pr comments --- .../com/google/cloud/storage/GrpcStorageImpl.java | 9 ++++----- .../cloud/storage/spi/v1/HttpStorageRpc.java | 15 +++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java index e0bfa27a5a..cf58235678 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java @@ -148,7 +148,6 @@ final class GrpcStorageImpl extends BaseService StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); private static final BucketSourceOption[] EMPTY_BUCKET_SOURCE_OPTIONS = new BucketSourceOption[0]; - private static final String OTEL_MODULE_NAME = "storage.client"; private static final Opts ALL_BLOB_FIELDS = Opts.from(UnifiedOpts.fields(ImmutableSet.copyOf(BlobField.values()))); @@ -203,7 +202,7 @@ public void close() throws Exception { @Override public Bucket create(BucketInfo bucketInfo, BucketTargetOption... options) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); + openTelemetryTraceUtil.startSpan("create", this.getClass().getName()); Opts opts = Opts.unwrap(options).resolveFrom(bucketInfo).prepend(defaultOpts); GrpcCallContext grpcCallContext = opts.grpcMetadataMapper().apply(GrpcCallContext.createDefault()); @@ -251,7 +250,7 @@ public Blob create( Opts opts = Opts.unwrap(options).resolveFrom(blobInfo); // Start the otel span to retain information of the origin of the request OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); + openTelemetryTraceUtil.startSpan("create", this.getClass().getName()); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { return internalDirectUpload( blobInfo, @@ -271,7 +270,7 @@ public Blob create( @Override public Blob create(BlobInfo blobInfo, InputStream content, BlobWriteOption... options) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); + openTelemetryTraceUtil.startSpan("create", this.getClass().getName()); try (OpenTelemetryTraceUtil.Scope ununsed = otelSpan.makeCurrent()) { requireNonNull(blobInfo, "blobInfo must be non null"); InputStream inputStreamParam = firstNonNull(content, new ByteArrayInputStream(ZERO_BYTES)); @@ -834,7 +833,7 @@ public BlobInfo internalDirectUpload( requireNonNull(blobInfo, "blobInfo must be non null"); requireNonNull(buf, "content must be non null"); OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("internalDirectUpload(BlobInfo)", OTEL_MODULE_NAME, ctx); + openTelemetryTraceUtil.startSpan("internalDirectUpload", this.getClass().getName(), ctx); Opts optsWithDefaults = opts.prepend(defaultOpts); GrpcCallContext grpcCallContext = optsWithDefaults.grpcMetadataMapper().apply(GrpcCallContext.createDefault()); diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java index c990877cc0..45366e5e1c 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java @@ -106,7 +106,6 @@ public class HttpStorageRpc implements StorageRpc { public static final String NO_ACL_PROJECTION = "noAcl"; private static final String ENCRYPTION_KEY_PREFIX = "x-goog-encryption-"; private static final String SOURCE_ENCRYPTION_KEY_PREFIX = "x-goog-copy-source-encryption-"; - private static final String OTEL_MODULE_NAME = "storage.spi.v1"; // declare this HttpStatus code here as it's not included in java.net.HttpURLConnection private static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416; @@ -362,7 +361,7 @@ private Span startSpan(String spanName) { @Override public Bucket create(Bucket bucket, Map options) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); + openTelemetryTraceUtil.startSpan("create", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_BUCKET); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -391,7 +390,7 @@ public Bucket create(Bucket bucket, Map options) { public StorageObject create( StorageObject storageObject, final InputStream content, Map options) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("create", OTEL_MODULE_NAME); + openTelemetryTraceUtil.startSpan("create", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_OBJECT); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -852,7 +851,7 @@ private Get createReadRequest(StorageObject from, Map options) throws public long read( StorageObject from, Map options, long position, OutputStream outputStream) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("read", OTEL_MODULE_NAME); + openTelemetryTraceUtil.startSpan("read", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_READ); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -891,7 +890,7 @@ public long read( public Tuple read( StorageObject from, Map options, long position, int bytes) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("read", OTEL_MODULE_NAME); + openTelemetryTraceUtil.startSpan("read", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_READ); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -1172,7 +1171,7 @@ public String open(String signedURL) { @Override public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("openRewrite", OTEL_MODULE_NAME); + openTelemetryTraceUtil.startSpan("openRewrite", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_OPEN_REWRITE); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -1187,7 +1186,7 @@ public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { @Override public RewriteResponse continueRewrite(RewriteResponse previousResponse) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("continueRewrite", OTEL_MODULE_NAME); + openTelemetryTraceUtil.startSpan("continueRewrite", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CONTINUE_REWRITE); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -1205,7 +1204,7 @@ public RewriteResponse continueRewrite(RewriteResponse previousResponse) { private RewriteResponse rewrite( RewriteRequest req, String token, OpenTelemetryTraceUtil.Context ctx) { OpenTelemetryTraceUtil.Span otelSpan = - openTelemetryTraceUtil.startSpan("rewrite", OTEL_MODULE_NAME, ctx); + openTelemetryTraceUtil.startSpan("rewrite", this.getClass().getName(), ctx); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { String userProject = Option.USER_PROJECT.getString(req.sourceOptions); if (userProject == null) {