Skip to content
Open
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 @@ -17,6 +17,9 @@
*/
package org.apache.beam.sdk.io.gcp.spanner.changestreams.dofn;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
import java.io.Serializable;
import java.math.BigDecimal;
import org.apache.beam.sdk.io.gcp.spanner.changestreams.ChangeStreamMetrics;
Expand Down Expand Up @@ -49,6 +52,8 @@
import org.apache.beam.sdk.transforms.splittabledofn.ManualWatermarkEstimator;
import org.apache.beam.sdk.transforms.splittabledofn.RestrictionTracker;
import org.apache.beam.sdk.transforms.splittabledofn.WatermarkEstimators.Manual;
import org.apache.beam.sdk.util.Preconditions;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.joda.time.Duration;
import org.joda.time.Instant;
import org.slf4j.Logger;
Expand Down Expand Up @@ -77,6 +82,7 @@ public class ReadChangeStreamPartitionDoFn extends DoFn<PartitionMetadata, DataC
private final ChangeStreamMetrics metrics;
private final boolean isMutableChangeStream;
private final boolean cancelQueryOnHeartbeat;
private transient @MonotonicNonNull Tracer tracer = null;
/**
* Needs to be set through the {@link
* ReadChangeStreamPartitionDoFn#setThroughputEstimator(BytesThroughputEstimator)} call.
Expand Down Expand Up @@ -235,6 +241,8 @@ public void setup(PipelineOptions options) {
metrics,
isMutableChangeStream,
realTimeCheckpointInterval);
this.tracer =
options.as(SdkHarnessOptions.class).getOpenTelemetry().getTracer("SpannerIO.changestreams");
}

/**
Expand Down Expand Up @@ -264,8 +272,16 @@ public ProcessContinuation processElement(

LOG.debug("[{}] Processing element with restriction {}", token, tracker.currentRestriction());

return queryChangeStreamAction.run(
partition, tracker, receiver, watermarkEstimator, bundleFinalizer);
Span span =
Preconditions.checkStateNotNull(tracer)
.spanBuilder("DataChangeRecordAction.run")
.startSpan();
try (Scope ignored = span.makeCurrent()) {
return queryChangeStreamAction.run(
partition, tracker, receiver, watermarkEstimator, bundleFinalizer);
} finally {
span.end();
}
}

/**
Expand Down
Loading