Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Add @Override as EnabledTraceUtil.java

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