From ead92e33a69d2f521b8cb84ae18077f86c3d390e Mon Sep 17 00:00:00 2001 From: Matthew Ball Date: Sat, 14 Nov 2026 03:50:44 -0800 Subject: [PATCH 1/3] feat(amber): trace the sync workflow execution entrypoint SyncExecutionResource.executeWorkflowSync, the POST /execution/{wid}/{cuid}/run entrypoint, ran with no span of its own, so a synchronous run produced no end-to-end trace; only the nested WorkflowService.initExecutionService span existed. executeWorkflowSync now opens a span named after the method with texera.workflow.id, texera.computing_unit.id, and texera.operator.count attributes, makes it current so initExecutionService nests beneath it, records a thrown exception on the span, and ends it in a finally so every early return and the catch path are covered. A synchronous run now yields a single trace showing total execution time with the init step as a child, using the same TexeraTracer and SpanAttrs pattern already in WorkflowService. reference/perf-candidates.md records this under P6 as the first slice, including the note that the amber module cannot be compiled locally without JOOQ code generation against the database (an existing build requirement unrelated to this change), so the change is verified by matching the established span pattern and relies on CI to compile. --- .../texera/web/resource/SyncExecutionResource.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala b/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala index 400d7bbc877..3029ff7eb4a 100644 --- a/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala +++ b/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala @@ -67,6 +67,7 @@ import javax.ws.rs.core.MediaType import scala.collection.mutable import scala.jdk.CollectionConverters._ import com.fasterxml.jackson.databind.ObjectMapper +import org.apache.texera.observability.{SpanAttrs, TexeraTracer} case class SyncExecutionRequest( executionName: String, @@ -153,6 +154,13 @@ class SyncExecutionResource extends LazyLogging { s"maxOperatorResultCellCharLimit=${request.maxOperatorResultCellCharLimit} (capped to $maxOperatorResultCellCharLimit)" ) + val span = TexeraTracer.tracer + .spanBuilder("SyncExecutionResource.executeWorkflowSync") + .setAttribute(SpanAttrs.WorkflowId, Long.box(workflowId)) + .setAttribute("texera.computing_unit.id", computingUnitId.toLong) + .setAttribute("texera.operator.count", request.logicalPlan.operators.size.toLong) + .startSpan() + val scope = span.makeCurrent() try { val workflowService = WorkflowService.getOrCreate( WorkflowIdentity(workflowId), @@ -357,7 +365,11 @@ class SyncExecutionResource extends LazyLogging { } catch { case e: Exception => logger.error(s"Sync execution error: ${e.getMessage}", e) + span.recordException(e) handleExecutionError(e) + } finally { + scope.close() + span.end() } } From a48464e5764654b1e0d676bf64e63b3307dea207 Mon Sep 17 00:00:00 2001 From: Matthew Ball Date: Fri, 20 Nov 2026 21:58:06 -0800 Subject: [PATCH 2/3] fix(amber): set the sync-execution span to ERROR on failure The executeWorkflowSync span recorded an exception but never set a status, so a failed run exported as UNSET and Jaeger's error filter skipped it, while the early timeout, wait-error, and null-service returns did not touch the span at all. The body is now a nested runExecution whose single result, or the failure handed back by the catch, sets the span to ERROR once when it is not successful, covering every failure path. SpanAttrs gains ComputingUnitId and OperatorCount so the span tags those with shared keys instead of inline strings. SyncExecutionResourceSpec drives a failing run and asserts, via an in-memory SpanExporter installed into GlobalOpenTelemetry, that the span is named, tagged, and marked ERROR. --- .../web/resource/SyncExecutionResource.scala | 26 ++++--- .../resource/SyncExecutionResourceSpec.scala | 72 ++++++++++++++++++- .../texera/observability/SpanAttrs.scala | 3 + 3 files changed, 92 insertions(+), 9 deletions(-) diff --git a/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala b/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala index 3029ff7eb4a..752d79eb7ad 100644 --- a/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala +++ b/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala @@ -68,6 +68,7 @@ import scala.collection.mutable import scala.jdk.CollectionConverters._ import com.fasterxml.jackson.databind.ObjectMapper import org.apache.texera.observability.{SpanAttrs, TexeraTracer} +import io.opentelemetry.api.trace.StatusCode case class SyncExecutionRequest( executionName: String, @@ -157,11 +158,11 @@ class SyncExecutionResource extends LazyLogging { val span = TexeraTracer.tracer .spanBuilder("SyncExecutionResource.executeWorkflowSync") .setAttribute(SpanAttrs.WorkflowId, Long.box(workflowId)) - .setAttribute("texera.computing_unit.id", computingUnitId.toLong) - .setAttribute("texera.operator.count", request.logicalPlan.operators.size.toLong) + .setAttribute(SpanAttrs.ComputingUnitId, Long.box(computingUnitId.toLong)) + .setAttribute(SpanAttrs.OperatorCount, Long.box(request.logicalPlan.operators.size.toLong)) .startSpan() val scope = span.makeCurrent() - try { + def runExecution(): SyncExecutionResult = { val workflowService = WorkflowService.getOrCreate( WorkflowIdentity(workflowId), computingUnitId @@ -361,12 +362,21 @@ class SyncExecutionResource extends LazyLogging { compilationErrors = None, errors = if (fatalErrors.nonEmpty) Some(fatalErrors) else None ) + } - } catch { - case e: Exception => - logger.error(s"Sync execution error: ${e.getMessage}", e) - span.recordException(e) - handleExecutionError(e) + try { + // A failed run (an early return or a caught exception) must mark the span ERROR, or + // Jaeger's error filter skips it; set it once from the single result. + val result = + try runExecution() + catch { + case e: Exception => + logger.error(s"Sync execution error: ${e.getMessage}", e) + span.recordException(e) + handleExecutionError(e) + } + if (!result.success) span.setStatus(StatusCode.ERROR) + result } finally { scope.close() span.end() diff --git a/amber/src/test/scala/org/apache/texera/web/resource/SyncExecutionResourceSpec.scala b/amber/src/test/scala/org/apache/texera/web/resource/SyncExecutionResourceSpec.scala index 7c505881e5b..da8d735dd0d 100644 --- a/amber/src/test/scala/org/apache/texera/web/resource/SyncExecutionResourceSpec.scala +++ b/amber/src/test/scala/org/apache/texera/web/resource/SyncExecutionResourceSpec.scala @@ -88,6 +88,14 @@ import java.net.URI import java.sql.Timestamp import java.util.concurrent.{FutureTask, TimeUnit} import scala.jdk.CollectionConverters._ +import io.opentelemetry.api.GlobalOpenTelemetry +import io.opentelemetry.api.trace.StatusCode +import io.opentelemetry.sdk.OpenTelemetrySdk +import io.opentelemetry.sdk.common.CompletableResultCode +import io.opentelemetry.sdk.trace.SdkTracerProvider +import io.opentelemetry.sdk.trace.`export`.{SimpleSpanProcessor, SpanExporter} +import io.opentelemetry.sdk.trace.data.SpanData +import org.apache.texera.observability.SpanAttrs /** * Unit tests for the synchronous "run this workflow and hand me the results" endpoint used by @@ -152,6 +160,18 @@ class SyncExecutionResourceSpec private val resource = new SyncExecutionResource() + // Captures the spans the resource emits so a case can assert their status and attributes. + private val exportedSpans = + java.util.Collections.synchronizedList(new java.util.ArrayList[SpanData]()) + private object CollectingSpanExporter extends SpanExporter { + override def `export`(spans: java.util.Collection[SpanData]): CompletableResultCode = { + exportedSpans.addAll(spans) + CompletableResultCode.ofSuccess() + } + override def flush(): CompletableResultCode = CompletableResultCode.ofSuccess() + override def shutdown(): CompletableResultCode = CompletableResultCode.ofSuccess() + } + private val stateToString = PrivateMethod[String](Symbol("stateToString")) private val isTerminalState = PrivateMethod[Boolean](Symbol("isTerminalState")) private val isCausedByTimeout = PrivateMethod[Boolean](Symbol("isCausedByTimeout")) @@ -184,6 +204,20 @@ class SyncExecutionResourceSpec private var resultEid: Int = 0 override protected def beforeAll(): Unit = { + // Install an in-memory span exporter before anything emits a span; TexeraTracer reads the + // tracer from GlobalOpenTelemetry, so the resource's spans land in exportedSpans. + GlobalOpenTelemetry.resetForTest() + GlobalOpenTelemetry.set( + OpenTelemetrySdk + .builder() + .setTracerProvider( + SdkTracerProvider + .builder() + .addSpanProcessor(SimpleSpanProcessor.create(CollectingSpanExporter)) + .build() + ) + .build() + ) initializeDBAndReplaceDSLContext() val cfg = getDSLContext.configuration() @@ -226,7 +260,10 @@ class SyncExecutionResourceSpec resultEid = insertExecution("result-fixture") } - override protected def afterAll(): Unit = closeConnectionPool() + override protected def afterAll(): Unit = { + try closeConnectionPool() + finally GlobalOpenTelemetry.resetForTest() + } private def insertExecution(name: String): Int = { import org.apache.texera.dao.jooq.generated.Tables.{WORKFLOW_EXECUTIONS, WORKFLOW_VERSION} @@ -1217,4 +1254,37 @@ class SyncExecutionResourceSpec result.operators("scan-op").state shouldBe "Unknown" result.operators("scan-op").error shouldBe None } + + it should "mark the execution span ERROR with correlation labels on a failed run" in { + exportedSpans.clear() + val scan = new CSVScanSourceOpDesc() + scan.setOperatorId("scan-op") + val user = new User + user.setUid(testUid) + user.setEmail("sync-exec@example.com") + + val result = resource.executeWorkflowSync( + testWid.toLong, + testCuid, + SyncExecutionRequest( + executionName = "sync-spec-span", + logicalPlan = LogicalPlanPojo(List(scan), List.empty, List.empty, List.empty), + workflowSettings = None, + targetOperatorIds = List("scan-op"), + timeoutSeconds = 5, + maxOperatorResultCharLimit = 100000, + maxOperatorResultCellCharLimit = 20000 + ), + new SessionUser(user) + ) + result.success shouldBe false + + val span = exportedSpans.asScala + .find(_.getName == "SyncExecutionResource.executeWorkflowSync") + .getOrElse(fail("expected the executeWorkflowSync span to be exported")) + span.getStatus.getStatusCode shouldBe StatusCode.ERROR + span.getAttributes.get(SpanAttrs.WorkflowId) shouldBe testWid.toLong + span.getAttributes.get(SpanAttrs.ComputingUnitId) shouldBe testCuid.toLong + span.getAttributes.get(SpanAttrs.OperatorCount) shouldBe 1L + } } diff --git a/common/observability/src/main/scala/org/apache/texera/observability/SpanAttrs.scala b/common/observability/src/main/scala/org/apache/texera/observability/SpanAttrs.scala index 56e0d192571..197b461c439 100644 --- a/common/observability/src/main/scala/org/apache/texera/observability/SpanAttrs.scala +++ b/common/observability/src/main/scala/org/apache/texera/observability/SpanAttrs.scala @@ -35,4 +35,7 @@ object SpanAttrs { val WorkflowId: AttributeKey[java.lang.Long] = AttributeKey.longKey("texera.workflow.id") val ExecutionId: AttributeKey[java.lang.Long] = AttributeKey.longKey("texera.execution.id") + val ComputingUnitId: AttributeKey[java.lang.Long] = + AttributeKey.longKey("texera.computing_unit.id") + val OperatorCount: AttributeKey[java.lang.Long] = AttributeKey.longKey("texera.operator.count") } From 3fb963ebf86379942a00e14e3c4752a4a3a12480 Mon Sep 17 00:00:00 2001 From: Matthew Ball Date: Mon, 23 Nov 2026 16:40:04 -0800 Subject: [PATCH 3/3] fix(amber): mark the sync-execution span ERROR on any Throwable SyncExecutionResource.executeWorkflowSync wraps its body in an outer try whose catch now matches Throwable rather than Exception: the throwable is recorded as an "exception" event on the execution span, the span status is set to StatusCode.ERROR, and the throwable is rethrown, while the finally still closes the current-context scope and ends the span. The inner `case e: Exception` arm is unchanged and keeps turning expected engine failures into a success=false result, so the new outer arm only covers non-Exception Errors (for example OutOfMemoryError) that previously left the span UNSET. SpanAttrsSpec: the "expose stable key names" case now also asserts SpanAttrs.ComputingUnitId.getKey is "texera.computing_unit.id" and SpanAttrs.OperatorCount.getKey is "texera.operator.count", so renaming either wire key fails a test. SyncExecutionResourceSpec: the failed-run case now asserts the exported WorkflowService.initExecutionService span's parent span id equals the executeWorkflowSync span id, pinning that init nests under the sync span. A new case drives the throwing path by passing warehouseId = Some(1), which is refused before any engine run, and asserts the exported executeWorkflowSync span carries an "exception" event and ERROR status. The class Scaladoc now says the span behaviour is driven by two end-to-end cases. --- .../web/resource/SyncExecutionResource.scala | 5 +++ .../resource/SyncExecutionResourceSpec.scala | 41 ++++++++++++++++++- .../texera/observability/SpanAttrsSpec.scala | 2 + 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala b/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala index 752d79eb7ad..622cc1610b2 100644 --- a/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala +++ b/amber/src/main/scala/org/apache/texera/web/resource/SyncExecutionResource.scala @@ -377,6 +377,11 @@ class SyncExecutionResource extends LazyLogging { } if (!result.success) span.setStatus(StatusCode.ERROR) result + } catch { + case t: Throwable => + span.recordException(t) + span.setStatus(StatusCode.ERROR) + throw t } finally { scope.close() span.end() diff --git a/amber/src/test/scala/org/apache/texera/web/resource/SyncExecutionResourceSpec.scala b/amber/src/test/scala/org/apache/texera/web/resource/SyncExecutionResourceSpec.scala index da8d735dd0d..3a6b5e5bd5d 100644 --- a/amber/src/test/scala/org/apache/texera/web/resource/SyncExecutionResourceSpec.scala +++ b/amber/src/test/scala/org/apache/texera/web/resource/SyncExecutionResourceSpec.scala @@ -102,8 +102,8 @@ import org.apache.texera.observability.SpanAttrs * agent-service. * * Two of the resource's methods are public (`executeWorkflowSync`, `healthCheck`); the other - * sixteen are `private def`. `executeWorkflowSync` is driven for real here — one end-to-end case - * that gets as far as a running engine can be taken without one — but the result-shaping helpers + * sixteen are `private def`. `executeWorkflowSync` is driven for real here — two end-to-end cases + * that get as far as a running engine can be taken without one — but the result-shaping helpers * it calls cannot be reached that way: every one of them only produces an observable difference * once the engine has populated the stats/console stores or written Iceberg results. They are * therefore driven through `PrivateMethodTester` over fixtures that stand in for that state, and @@ -1286,5 +1286,42 @@ class SyncExecutionResourceSpec span.getAttributes.get(SpanAttrs.WorkflowId) shouldBe testWid.toLong span.getAttributes.get(SpanAttrs.ComputingUnitId) shouldBe testCuid.toLong span.getAttributes.get(SpanAttrs.OperatorCount) shouldBe 1L + + val initSpan = exportedSpans.asScala + .find(_.getName == "WorkflowService.initExecutionService") + .getOrElse(fail("expected the initExecutionService span to be exported")) + initSpan.getParentSpanId shouldBe span.getSpanContext.getSpanId + } + + it should "record the exception and mark the span ERROR when the run throws" in { + exportedSpans.clear() + val scan = new CSVScanSourceOpDesc() + scan.setOperatorId("scan-op") + val user = new User + user.setUid(testUid) + user.setEmail("sync-exec@example.com") + + val result = resource.executeWorkflowSync( + testWid.toLong, + testCuid, + SyncExecutionRequest( + executionName = "sync-spec-span-throw", + logicalPlan = LogicalPlanPojo(List(scan), List.empty, List.empty, List.empty), + workflowSettings = None, + targetOperatorIds = List("scan-op"), + timeoutSeconds = 5, + maxOperatorResultCharLimit = 100000, + maxOperatorResultCellCharLimit = 20000, + warehouseId = Some(1) + ), + new SessionUser(user) + ) + result.success shouldBe false + + val span = exportedSpans.asScala + .find(_.getName == "SyncExecutionResource.executeWorkflowSync") + .getOrElse(fail("expected the executeWorkflowSync span to be exported")) + span.getStatus.getStatusCode shouldBe StatusCode.ERROR + span.getEvents.asScala.exists(_.getName == "exception") shouldBe true } } diff --git a/common/observability/src/test/scala/org/apache/texera/observability/SpanAttrsSpec.scala b/common/observability/src/test/scala/org/apache/texera/observability/SpanAttrsSpec.scala index 8143832c4c6..65ab2eb641d 100644 --- a/common/observability/src/test/scala/org/apache/texera/observability/SpanAttrsSpec.scala +++ b/common/observability/src/test/scala/org/apache/texera/observability/SpanAttrsSpec.scala @@ -47,6 +47,8 @@ class SpanAttrsSpec extends AnyFlatSpec with Matchers { it should "expose stable key names so callsites share one label vocabulary" in { SpanAttrs.WorkflowId.getKey shouldBe "texera.workflow.id" SpanAttrs.ExecutionId.getKey shouldBe "texera.execution.id" + SpanAttrs.ComputingUnitId.getKey shouldBe "texera.computing_unit.id" + SpanAttrs.OperatorCount.getKey shouldBe "texera.operator.count" } // ----- attribute-count cap is the OTel SDK default (128) -------------