Skip to content

Commit

Permalink
test: Additional Transaction tests and AggregationQuery test (#1518)
Browse files Browse the repository at this point in the history
* test: ReadWrite Transaction test

* test: Added test for Transactional RunQuery and Transaction Rollback

* test: runInTransaction API tracing test
- Fixed setting of common span attributes to spans in runInTransaction
- Removed some gRPC related channel attributes that are not present in this Datastore version, yet.
  • Loading branch information
jimit-j-shah committed Sep 16, 2024
1 parent db41656 commit 9672e7b
Show file tree
Hide file tree
Showing 5 changed files with 303 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private io.opentelemetry.api.trace.Span startSpanWithParentContext(
.with(
io.opentelemetry.api.trace.Span.wrap(
parentSpanContext.getSpanContext())));
return spanBuilder.startSpan();
return otelTraceUtil.addSettingsAttributesToCurrentSpan(spanBuilder).startSpan();
}

@Override
Expand Down Expand Up @@ -540,7 +540,10 @@ com.google.datastore.v1.LookupResponse lookup(
.put("Received", response.getFoundCount())
.put("Missing", response.getMissingCount())
.put("Deferred", response.getDeferredCount())
.put("isTransactional", isTransactional)
.put("transactional", isTransactional)
.put(
"transaction_id",
isTransactional ? readOptions.getTransaction().toStringUtf8() : "")
.build());
return response;
},
Expand Down Expand Up @@ -772,6 +775,11 @@ public Void call() throws DatastoreException {
retrySettings,
EXCEPTION_HANDLER,
getOptions().getClock());
span.addEvent(
com.google.cloud.datastore.telemetry.TraceUtil.SPAN_NAME_ROLLBACK,
new ImmutableMap.Builder<String, Object>()
.put("transaction_id", requestPb.getTransaction().toStringUtf8())
.build());
} catch (RetryHelperException e) {
span.end(e);
throw DatastoreException.translateAndThrow(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.cloud.datastore.telemetry.TraceUtil.SpanContext;
import io.grpc.ManagedChannelBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerProvider;
import java.util.Map;
Expand Down Expand Up @@ -115,6 +116,10 @@ public TraceUtil.Span startSpan(String spanName, TraceUtil.SpanContext parentSpa
return new Span();
}

public SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder) {
return getTracer().spanBuilder("TRACING_DISABLED_NO_OP");
}

@Nonnull
@Override
public TraceUtil.Span getCurrentSpan() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ public Scope makeCurrent() {
}

/** Applies the current Datastore instance settings as attributes to the current Span */
private SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder) {
@Override
public SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder) {
spanBuilder =
spanBuilder.setAllAttributes(
Attributes.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.cloud.datastore.DatastoreOptions;
import io.grpc.ManagedChannelBuilder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.api.trace.Tracer;
import java.util.Map;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -144,6 +145,12 @@ interface Scope extends AutoCloseable {
*/
Span startSpan(String spanName, SpanContext parentSpanContext);

/**
* Adds common SpanAttributes to the current span, useful when hand-creating a new Span without
* using the TraceUtil.Span interface.
*/
SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder);

/** Returns the current span. */
@Nonnull
Span getCurrentSpan();
Expand Down
Loading

0 comments on commit 9672e7b

Please sign in to comment.