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

feat: Take in a module name when creating a span #2811

Merged
merged 6 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ final class GrpcStorageImpl extends BaseService<StorageOptions>
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";
sydney-munro marked this conversation as resolved.
Show resolved Hide resolved

private static final Opts<Fields> ALL_BLOB_FIELDS =
Opts.from(UnifiedOpts.fields(ImmutableSet.copyOf(BlobField.values())));
Expand Down Expand Up @@ -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<BucketTargetOpt> opts = Opts.unwrap(options).resolveFrom(bucketInfo).prepend(defaultOpts);
GrpcCallContext grpcCallContext =
opts.grpcMetadataMapper().apply(GrpcCallContext.createDefault());
Expand Down Expand Up @@ -248,7 +250,8 @@ public Blob create(
BlobInfo blobInfo, byte[] content, int offset, int length, BlobTargetOption... options) {
Opts<ObjectTargetOpt> 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,
Expand All @@ -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));
Expand Down Expand Up @@ -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);
sydney-munro marked this conversation as resolved.
Show resolved Hide resolved
Opts<ObjectTargetOpt> optsWithDefaults = opts.prepend(defaultOpts);
GrpcCallContext grpcCallContext =
optsWithDefaults.grpcMetadataMapper().apply(GrpcCallContext.createDefault());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -360,7 +361,8 @@ private Span startSpan(String spanName) {

@Override
public Bucket create(Bucket bucket, Map<Option, ?> 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()) {
Expand Down Expand Up @@ -388,7 +390,8 @@ public Bucket create(Bucket bucket, Map<Option, ?> options) {
@Override
public StorageObject create(
StorageObject storageObject, final InputStream content, Map<Option, ?> 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()) {
Expand Down Expand Up @@ -848,7 +851,8 @@ private Get createReadRequest(StorageObject from, Map<Option, ?> options) throws
@Override
public long read(
StorageObject from, Map<Option, ?> 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()) {
Expand Down Expand Up @@ -886,7 +890,8 @@ public long read(
@Override
public Tuple<String, byte[]> read(
StorageObject from, Map<Option, ?> 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()) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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) {
Expand Down
Loading