Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(storage): introduce storage trace package #11051

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cojenco
Copy link
Contributor

@cojenco cojenco commented Oct 29, 2024

Introduce storage trace package, starting with the bucket module

  • Added a flag for development GO_STORAGE_DEV_OTEL_TRACING
  • Test the new storage trace startSpan accepts StartSpanOption and can setAttributes
  • Test Cloud Trace adoption attributes are appended with the new storage trace package

Copy link
Contributor

@BrennaEpp BrennaEpp left a comment

Choose a reason for hiding this comment

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

Quick review, looking good!

storage/trace.go Outdated
)

const (
OpenTelemetryTracingExpVar = "GO_STORAGE_EXPERIMENTAL_OTEL_TRACING"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to export this since we'd ideally remove it after the migration is done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks! If fuse needs it anytime sooner, we can change it to an experimental env var.

return otel.Tracer(defaultTracerName, trace.WithInstrumentationVersion(internal.Version))
}

// startSpan accepts SpanStartOption and is used to replace internal/trace/StartSpan.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is fine for drafting, but we should change it to something else before merging

Copy link
Contributor

Choose a reason for hiding this comment

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

Not seeing any changes here yet

ctx = trace.StartSpan(ctx, "cloud.google.com/go/storage.Bucket.Create")
defer func() { trace.EndSpan(ctx, err) }()
if isOTelTracingDevEnabled() {
ctx, _ = startSpan(ctx, "cloud.google.com/go/storage.Bucket.Create")
Copy link
Contributor

Choose a reason for hiding this comment

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

Since startSpan is completely internal to Storage now, can we factor out cloud.google.com/go/storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely, I've changed these to storage.Bucket.Create so we're still following the semantic conventions of $package.$service.$method

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I meant, just to move cloud.google.com/go/ to the startSpan method so that we don't have to repeat it in the name of each span (and to help with consistency).

@cojenco cojenco marked this pull request as ready for review November 1, 2024 18:39
@cojenco cojenco requested review from a team as code owners November 1, 2024 18:39
@tritone tritone changed the title chore: introduce storage trace package chore(storage): introduce storage trace package Nov 5, 2024
)

// isOTelTracingDevEnabled checks the development flag until experimental feature is launched.
func isOTelTracingDevEnabled() bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

This func seems unused? What is the actual purpose of the env var?

Copy link
Contributor

Choose a reason for hiding this comment

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

It will be used during development to enable the new stuff only if that var is set. It will be removed once launched

@tritone tritone added the api: storage Issues related to the Cloud Storage API. label Nov 7, 2024
storageOtelTracingDevVar = "GO_STORAGE_DEV_OTEL_TRACING"
defaultTracerName = "cloud.google.com/go/storage"
gcpClientRepo = "googleapis/google-cloud-go"
gcpClientArtifact = "storage"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be cloud.google.com/go/storage or something like com.google.cloud.google-cloud-storage?

func getCommonTraceOptions() []trace.SpanStartOption {
opts := []trace.SpanStartOption{
trace.WithAttributes(
attribute.String("gcp.client.version", internal.Version),
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we missing gcp.client.service?

Comment on lines +34 to +37
originalOtelTracingBool := os.Getenv("GO_STORAGE_DEV_OTEL_TRACING")
defer os.Setenv("GO_STORAGE_DEV_OTEL_TRACING", originalOtelTracingBool)

os.Setenv("GO_STORAGE_DEV_OTEL_TRACING", "true")
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this, try https://pkg.go.dev/testing#T.Setenv

Suggested change
originalOtelTracingBool := os.Getenv("GO_STORAGE_DEV_OTEL_TRACING")
defer os.Setenv("GO_STORAGE_DEV_OTEL_TRACING", originalOtelTracingBool)
os.Setenv("GO_STORAGE_DEV_OTEL_TRACING", "true")
t.Setenv("GO_STORAGE_DEV_OTEL_TRACING", "true")

otel.SetTracerProvider(tp)

spanName := "storage.TestTrace.TestStorageTraceStartEndSpan"
spanStartopts := []trace.SpanStartOption{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
spanStartopts := []trace.SpanStartOption{
spanStartOpts := []trace.SpanStartOption{


func spanAttributesComparer(a, b tracetest.SpanStub) bool {
if a.Name != b.Name {
fmt.Printf("name mismatch: a.Name: %v, b.Name: %v\n", a.Name, b.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be printed in the diff when comparing? What does the output on failure look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants