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..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 @@ -201,7 +201,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", this.getClass().getName()); Opts opts = Opts.unwrap(options).resolveFrom(bucketInfo).prepend(defaultOpts); GrpcCallContext grpcCallContext = opts.grpcMetadataMapper().apply(GrpcCallContext.createDefault()); @@ -248,7 +249,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", this.getClass().getName()); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { return internalDirectUpload( blobInfo, @@ -267,7 +269,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", this.getClass().getName()); try (OpenTelemetryTraceUtil.Scope ununsed = otelSpan.makeCurrent()) { requireNonNull(blobInfo, "blobInfo must be non null"); InputStream inputStreamParam = firstNonNull(content, new ByteArrayInputStream(ZERO_BYTES)); @@ -830,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)", 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/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..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 @@ -360,7 +360,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", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_BUCKET); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -388,7 +389,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", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_OBJECT); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -848,7 +850,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", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_READ); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -886,7 +889,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", this.getClass().getName()); Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_READ); Scope scope = tracer.withSpan(span); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { @@ -1166,7 +1170,8 @@ public String open(String signedURL) { @Override public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("openRewrite"); + OpenTelemetryTraceUtil.Span otelSpan = + 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()) { @@ -1180,7 +1185,8 @@ public RewriteResponse openRewrite(RewriteRequest rewriteRequest) { @Override public RewriteResponse continueRewrite(RewriteResponse previousResponse) { - OpenTelemetryTraceUtil.Span otelSpan = openTelemetryTraceUtil.startSpan("continueRewrite"); + OpenTelemetryTraceUtil.Span otelSpan = + 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()) { @@ -1197,7 +1203,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", this.getClass().getName(), ctx); try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) { String userProject = Option.USER_PROJECT.getString(req.sourceOptions); if (userProject == null) {