-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package storage | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"cloud.google.com/go/storage/internal" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
otelcodes "go.opentelemetry.io/otel/codes" | ||
"go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
const ( | ||
OpenTelemetryTracingExpVar = "GO_STORAGE_EXPERIMENTAL_OTEL_TRACING" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
defaultTracerName = "cloud.google.com/go/storage" | ||
gcpClientRepo = "googleapis/google-cloud-go" | ||
gcpClientArtifact = "storage" | ||
) | ||
|
||
// isOTelTracingDevEnabled checks the development flag until experimental feature is launched. | ||
func isOTelTracingDevEnabled() bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return os.Getenv(OpenTelemetryTracingExpVar) == "true" | ||
} | ||
|
||
func tracer() trace.Tracer { | ||
return otel.Tracer(defaultTracerName, trace.WithInstrumentationVersion(internal.Version)) | ||
} | ||
|
||
// startSpan accepts SpanStartOption and is used to replace internal/trace/StartSpan. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not seeing any changes here yet |
||
func startSpan(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) { | ||
opts = append(opts, getCommonTraceOptions()...) | ||
return tracer().Start(ctx, name, opts...) | ||
} | ||
|
||
// endSpan is used to replace internal/trace/EndSpan. | ||
func endSpan(ctx context.Context, err error) { | ||
span := trace.SpanFromContext(ctx) | ||
if err != nil { | ||
span.SetStatus(otelcodes.Error, err.Error()) | ||
span.RecordError(err) | ||
} | ||
span.End() | ||
} | ||
|
||
// getCommonTraceOptions includes the common attributes used for Cloud Trace adoption tracking. | ||
func getCommonTraceOptions() []trace.SpanStartOption { | ||
opts := []trace.SpanStartOption{ | ||
trace.WithAttributes( | ||
attribute.String("gcp.client.version", internal.Version), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we missing |
||
attribute.String("gcp.client.repo", gcpClientRepo), | ||
attribute.String("gcp.client.artifact", gcpClientArtifact), | ||
), | ||
} | ||
return opts | ||
} |
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.
Since
startSpan
is completely internal to Storage now, can we factor outcloud.google.com/go/storage
?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.
Absolutely, I've changed these to
storage.Bucket.Create
so we're still following the semantic conventions of $package.$service.$methodThere 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.
Oh I meant, just to move
cloud.google.com/go/
to thestartSpan
method so that we don't have to repeat it in the name of each span (and to help with consistency).