GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — chore: refactor otel tracing of Storage to be a decorator rather than in method modification by BenWhitehead · Pull Request #2856 · googleapis/java-storage

This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Conversation

@BenWhitehead

@BenWhitehead BenWhitehead commented Jan 3, 2025

Copy link
Copy Markdown
Collaborator

Refactor com.google.cloud.storage.Storage otel tracing to be based on a decorating instance of Storage rather than modifying the implementations of StorageImpl and GrpcStorageImpl directly.

This simplifies things by ensuring any otel tracing for c.g.c.s.Storage is implemented for both http and grpc at the same time and with the same metadata.

As a side effect, the previous com.google.cloud.storage.otel package has been removed.

The number of lines appears daunting, however a high level overview of the actual modifications:

  1. Remove otel tracing from StorageImpl
  2. Remove otel tracing from GrpcStorageImpl
  3. Cleanup StorageOption
    1. classes to specify @BetaApi on all otel related methods
    2. Add {Http,Grpc}StorageDefaults.getDefaultOpenTelemetry default which points at OpenTelemetry.noop()
    3. Relax dependency on OpenTelemetrySdk to only OpenTelemetry
  4. Add OtelStorageDecorator (~1700 Lines of the PR) to decorate nearly all public api methods (excluding batch())
    • Each method is "logicless" for the most part, and was generated with the help of IntelliJ live templates
    • Each method is generally: Define span, and scope invoke delegate catch any exception and complete the span
    • There are sub decorators for ReadChannel, WriteChannel, BlobWriteSession and CopyWriter which carry the originating span along for their lifetimes
  5. Remote com.google.cloud.storage.otel package and helpers
  6. Update assertions in ITOpenTelemetryTest to be wrapped in an assertAll

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead added 2 commits January 3, 2025 21:19
@BenWhitehead
feat: introductory beta level support for OpenTelemetry tracing on c.…
65cc5f7
…g.c.storage.Storage methods

Add introductory support for OpenTelemetry tracing to com.google.cloud.storage.Storage method.

Actual RPC methods are not yet supported.
@BenWhitehead
chore: remote otel helpers package
2b1c574
@BenWhitehead
BenWhitehead requested review from a team January 3, 2025 21:36
@product-auto-label product-auto-label Bot added size: xl Pull request size is extra large. api: storage Issues related to the googleapis/java-storage API. labels Jan 3, 2025
BenWhitehead
BenWhitehead commented Jan 3, 2025
View reviewed changes
Comment thread google-cloud-storage/src/test/java/com/google/cloud/storage/ITOpenTelemetryTest.java
}

SpanData spanData = exporter.getExportedSpans().get(0);
assertAll(

@BenWhitehead BenWhitehead Jan 3, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure all are validated rather than an early failure preventing a later assertion

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead
BenWhitehead commented Jan 3, 2025
View reviewed changes
Comment thread google-cloud-storage/src/test/java/com/google/cloud/storage/ITOpenTelemetryTestbenchTest.java
@After
public void tearDown() throws Exception {
if (storage != null) {
storage.close();

@BenWhitehead BenWhitehead Jan 3, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure we close the constructed storage instance so we don't leak grpc clients

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead
BenWhitehead commented Jan 3, 2025
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/HttpStorageOptions.java
/** @since 2.47.0 This new api is in preview and is subject to breaking changes. */
@BetaApi
public OpenTelemetry getDefaultOpenTelemetry() {
return OpenTelemetry.noop();

@BenWhitehead BenWhitehead Jan 3, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure we default to a non-null value

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead
BenWhitehead commented Jan 3, 2025
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java
/** @since 2.47.0 This new api is in preview and is subject to breaking changes. */
@BetaApi
public OpenTelemetry getDefaultOpenTelemetry() {
return OpenTelemetry.noop();

@BenWhitehead BenWhitehead Jan 3, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure we default to a non-null value

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead
BenWhitehead commented Jan 3, 2025
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java
ResponseContentLifecycleManager.noop(),
grpcStorageOptions.blobWriteSessionConfig.createFactory(Clock.systemUTC()),
defaultOpts);
return OtelStorageDecorator.decorate(

@BenWhitehead BenWhitehead Jan 3, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weave in the decorator if necessary

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead
BenWhitehead commented Jan 3, 2025
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/HttpStorageOptions.java
new StorageImpl(
httpStorageOptions,
httpStorageOptions.blobWriteSessionConfig.createFactory(clock));
return OtelStorageDecorator.decorate(

@BenWhitehead BenWhitehead Jan 3, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weave in the decorator if necessary

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead
BenWhitehead commented Jan 3, 2025
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/OtelStorageDecorator.java
Comment on lines +76 to +89
Span span =
tracer
.spanBuilder("create")
.setAttribute("gsutil.uri", fmtBucket(bucketInfo.getName()))
.startSpan();
try (Scope ignore = span.makeCurrent()) {
return delegate.create(bucketInfo, options);
} catch (Throwable t) {
span.recordException(t);
span.setStatus(StatusCode.ERROR, t.getClass().getSimpleName());
throw t;
} finally {
span.end();
}

@BenWhitehead BenWhitehead Jan 3, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is the largest chunk of the PR, but consists of generally templated code.

  1. Define a span and scope
  2. Invoke the delegate
  3. catch any error
  4. end the span

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sydney-munro sydney-munro Jan 6, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead
BenWhitehead commented Jan 3, 2025
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/OtelStorageDecorator.java Outdated
}
}

private static class OtelDecoratedReadChannel implements ReadChannel {

@BenWhitehead BenWhitehead Jan 3, 2025

Copy link
Copy Markdown
Collaborator Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadChannel, WriteChannel, CopyWriter and BlobWriteSession have sub-decorators which carry their originating spans along for their lifetimes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
BenWhitehead added 3 commits January 3, 2025 21:45
@BenWhitehead
chore: fix validation
2ef4ab6
@BenWhitehead
chore: mark openTelemetry fields transient in {Grpc,Http}StorageOptions
e55c3a4
@BenWhitehead
chore: fixup CopyWriter otel span lifecycle
32d5850
sydney-munro
sydney-munro approved these changes Jan 6, 2025
View reviewed changes

@sydney-munro sydney-munro left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, we chatted offline about this at greater length than is reflected in this code review. No surprises here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sydney-munro sydney-munro added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 6, 2025
@BenWhitehead
BenWhitehead merged commit 6faf5ec into otel-v1-branch Jan 6, 2025
@BenWhitehead
BenWhitehead deleted the otel/decorator-refactor branch January 6, 2025 18:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer
@sydney-munro sydney-munro sydney-munro approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: storage Issues related to the googleapis/java-storage API. kokoro:force-run Add this label to force Kokoro to re-run the tests. size: xl Pull request size is extra large.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@BenWhitehead @sydney-munro
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.