Skip to content

Commit

Permalink
feat: Take in a module name when creating a span (#2811)
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-munro authored Nov 8, 2024
1 parent 4538213 commit dc5a734
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BucketTargetOpt> opts = Opts.unwrap(options).resolveFrom(bucketInfo).prepend(defaultOpts);
GrpcCallContext grpcCallContext =
opts.grpcMetadataMapper().apply(GrpcCallContext.createDefault());
Expand Down Expand Up @@ -248,7 +249,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", this.getClass().getName());
try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) {
return internalDirectUpload(
blobInfo,
Expand All @@ -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));
Expand Down Expand Up @@ -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<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 @@ -360,7 +360,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", this.getClass().getName());
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 +389,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", this.getClass().getName());
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 +850,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", this.getClass().getName());
Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_READ);
Scope scope = tracer.withSpan(span);
try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) {
Expand Down Expand Up @@ -886,7 +889,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", this.getClass().getName());
Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_READ);
Scope scope = tracer.withSpan(span);
try (OpenTelemetryTraceUtil.Scope unused = otelSpan.makeCurrent()) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand All @@ -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) {
Expand Down

0 comments on commit dc5a734

Please sign in to comment.