This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-9233-858eeec4939ea44c605ce8c9f1fef34cffe5410e
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 3f9bdd481a4015657e485e0e345942b72381c9e6
Author: Xinyuan Lin <[email protected]>
AuthorDate: Wed Nov 4 06:02:48 2026 +0000

    refactor(observability): drop TraceparentValidator, SpanAttrs (#9233)
    
    ### What changes were proposed in this PR?
    Removes unreferenced classes, methods, and attributes in the
    `common/observability` module:
    1.
    
`common/observability/src/main/scala/org/apache/texera/observability/TraceparentValidator.scala`:
    - Drops orphaned file (-98 lines) containing `TraceparentValidator`
    (`validateTraceparent`, `validateTracestate`, `MaxTracestateLength`)
    with zero production callers across the repository.
    2.
    
`common/observability/src/test/scala/org/apache/texera/observability/TraceparentValidatorSpec.scala`:
       - Drops companion spec file (-124 lines).
    3.
    
`common/observability/src/main/scala/org/apache/texera/observability/TexeraTracer.scala`:
    - Drops unreferenced `currentContext` snapshot helper and unused
    `io.opentelemetry.context.Context` import (-9 lines).
    4.
    
`common/observability/src/test/scala/org/apache/texera/observability/TexeraTracerSpec.scala`:
    - Drops unit tests for `currentContext` and companion unused import (-15
    lines).
    5.
    
`common/observability/src/main/scala/org/apache/texera/observability/SpanAttrs.scala`:
    - Drops unused standard correlation attribute keys `ProjectId`,
    `UserId`, `OperatorId`, `OperatorName`, and `Outcome`, plus the
    now-unused free-text helper `sanitizeFreeText` and `FreeTextMaxLen` (no
    production callers; no free-text key remains), keeping active keys
    `WorkflowId` and `ExecutionId`.
    6.
    
`common/observability/src/test/scala/org/apache/texera/observability/SpanAttrsSpec.scala`:
    - Drops test assertions for `OperatorName` and the five
    `sanitizeFreeText` tests.
    
    **+3/-301 lines.** Pure refactoring with no behavior change.
    
    ### Any related issues, documentation, discussions?
    Closes #9232.
    
    ### How was this PR tested?
    - Scalafmt check passed:
      ```bash
      sbt "project Observability" scalafmtCheck "Test / scalafmtCheck"
      ```
    - Unit tests passed (71 tests, 6 suites):
      ```bash
      sbt "project Observability" test
      ```
    - Verified 0 callers repo-wide on `origin/main` for
    `TraceparentValidator`, `TexeraTracer.currentContext`, and the dropped
    `SpanAttrs` keys (`ProjectId`, `UserId`, `OperatorId`, `OperatorName`,
    `Outcome`), `SpanAttrs.sanitizeFreeText`, and
    `SpanAttrs.FreeTextMaxLen`.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    Generated-by: Antigravity
---
 .../apache/texera/observability/SpanAttrs.scala    |  30 +----
 .../apache/texera/observability/TexeraTracer.scala |   9 --
 .../observability/TraceparentValidator.scala       |  98 ----------------
 .../texera/observability/SpanAttrsSpec.scala       |  28 -----
 .../texera/observability/TexeraTracerSpec.scala    |  15 ---
 .../observability/TraceparentValidatorSpec.scala   | 124 ---------------------
 6 files changed, 3 insertions(+), 301 deletions(-)

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 c818f69bc1..56e0d19257 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
@@ -22,41 +22,17 @@ package org.apache.texera.observability
 import io.opentelemetry.api.common.AttributeKey
 
 /**
-  * Standard Texera span-attribute keys plus a free-text sanitizer.
+  * Standard Texera span-attribute keys.
   *
   * These are the shared label keys so every callsite tags spans with the
   * same names. Set them with the standard OTel API at the callsite, e.g.
-  * ``spanBuilder.setAttribute(SpanAttrs.WorkflowId, id)`` or
-  * ``span.setAttribute(SpanAttrs.WorkflowId, id)``. Run any free-text value
-  * through [[sanitizeFreeText]] first to strip CRLF and cap its length.
+  * `spanBuilder.setAttribute(SpanAttrs.WorkflowId, id)` or
+  * `span.setAttribute(SpanAttrs.WorkflowId, id)`.
   */
 object SpanAttrs {
 
-  /** Maximum length for free-text span attribute values. */
-  val FreeTextMaxLen: Int = 256
-
   // ---- Standard Texera correlation labels ------------------------------
 
   val WorkflowId: AttributeKey[java.lang.Long] = 
AttributeKey.longKey("texera.workflow.id")
   val ExecutionId: AttributeKey[java.lang.Long] = 
AttributeKey.longKey("texera.execution.id")
-  val ProjectId: AttributeKey[java.lang.Long] = 
AttributeKey.longKey("texera.project.id")
-  val UserId: AttributeKey[java.lang.Long] = 
AttributeKey.longKey("texera.user.id")
-  val OperatorId: AttributeKey[String] = 
AttributeKey.stringKey("texera.operator.id")
-  val OperatorName: AttributeKey[String] = 
AttributeKey.stringKey("texera.operator.name")
-  val Outcome: AttributeKey[String] = AttributeKey.stringKey("texera.outcome")
-
-  // ---- Pure helpers (exposed for testing) ------------------------------
-
-  /**
-    * Strip CR/LF and other C0 control characters from a free-text
-    * value, then cap at [[FreeTextMaxLen]]. Returns null for
-    * null/empty input (caller skips the setAttribute call).
-    */
-  def sanitizeFreeText(value: String): String = {
-    if (value == null || value.isEmpty) return null
-    val stripped = value.filter(c => c >= 0x20 && c != 0x7f)
-    if (stripped.isEmpty) null
-    else if (stripped.length <= FreeTextMaxLen) stripped
-    else stripped.substring(0, FreeTextMaxLen)
-  }
 }
diff --git 
a/common/observability/src/main/scala/org/apache/texera/observability/TexeraTracer.scala
 
b/common/observability/src/main/scala/org/apache/texera/observability/TexeraTracer.scala
index 38e1c36b62..844850c93d 100644
--- 
a/common/observability/src/main/scala/org/apache/texera/observability/TexeraTracer.scala
+++ 
b/common/observability/src/main/scala/org/apache/texera/observability/TexeraTracer.scala
@@ -21,7 +21,6 @@ package org.apache.texera.observability
 
 import io.opentelemetry.api.GlobalOpenTelemetry
 import io.opentelemetry.api.trace.Tracer
-import io.opentelemetry.context.Context
 
 /**
   * Accessor for the Texera OTel tracer.
@@ -50,12 +49,4 @@ object TexeraTracer {
   private val InstrumentationScope = "org.apache.texera"
 
   def tracer: Tracer = GlobalOpenTelemetry.getTracer(InstrumentationScope)
-
-  /**
-    * Snapshot the current OTel ``Context`` so async callbacks can
-    * re-attach it via ``Context.makeCurrent`` later. Useful at the
-    * Scala to Python boundary where the calling thread is not the
-    * receiving thread.
-    */
-  def currentContext: Context = Context.current()
 }
diff --git 
a/common/observability/src/main/scala/org/apache/texera/observability/TraceparentValidator.scala
 
b/common/observability/src/main/scala/org/apache/texera/observability/TraceparentValidator.scala
deleted file mode 100644
index f5ea4d6cfa..0000000000
--- 
a/common/observability/src/main/scala/org/apache/texera/observability/TraceparentValidator.scala
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.texera.observability
-
-/**
-  * Pure validators for W3C Trace Context headers crossing the
-  * Scala↔Python boundary. The single rule: if the inbound bytes do
-  * not match the strict regex, we discard the value and start a fresh
-  * trace. We never echo a rejected value back into a span, log, or
-  * error message.
-  *
-  * Spec reference: https://www.w3.org/TR/trace-context/
-  *
-  * The regexes here intentionally do NOT use any context-sensitive
-  * grouping or backreferences, keeps the validators safe against
-  * pathological inputs (ReDoS) and trivially fast.
-  */
-object TraceparentValidator {
-
-  /** W3C traceparent format: `<version>-<trace-id>-<parent-id>-<flags>`.
-    *  We accept only version `00` (the only published version) with the
-    *  canonical 32-hex / 16-hex / 2-hex layout. All hex lowercase per
-    *  spec, uppercase is invalid.
-    */
-  private val TraceparentPattern =
-    "^00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$".r.pattern
-
-  /** Bounded tracestate length. Spec recommends ≤512 chars. We are
-    *  stricter to remove a small DoS surface, an attacker can't send
-    *  a 1 MiB tracestate to balloon downstream context allocations.
-    */
-  val MaxTracestateLength: Int = 512
-
-  /** Validate a traceparent header. Returns the input unchanged on
-    *  success, None on any failure (rejected, caller starts a fresh
-    *  trace). Null and empty are silent failures.
-    */
-  def validateTraceparent(header: String): Option[String] = {
-    if (header == null || header.isEmpty) return None
-    // Trace-id and parent-id must not be all-zero per spec, an
-    // all-zero ID is a sentinel for "no value" and MUST be rejected.
-    if (!TraceparentPattern.matcher(header).matches()) return None
-    val parts = header.split('-')
-    val traceId = parts(1)
-    val spanId = parts(2)
-    if (isAllZero(traceId) || isAllZero(spanId)) return None
-    Some(header)
-  }
-
-  /** Validate a tracestate header. Spec: comma-separated list of
-    *  key=value pairs, ASCII-printable only, total length capped.
-    *  Returns the input unchanged on success, None on rejection.
-    */
-  def validateTracestate(header: String): Option[String] = {
-    if (header == null || header.isEmpty) return None
-    if (header.length > MaxTracestateLength) return None
-    if (!isAsciiPrintable(header)) return None
-    Some(header)
-  }
-
-  private def isAllZero(s: String): Boolean = {
-    var i = 0
-    while (i < s.length) {
-      if (s.charAt(i) != '0') return false
-      i += 1
-    }
-    true
-  }
-
-  private def isAsciiPrintable(s: String): Boolean = {
-    var i = 0
-    while (i < s.length) {
-      val c = s.charAt(i)
-      // Allow printable ASCII range (0x20-0x7E). Tab and CR/LF are
-      // rejected, a tracestate must not span lines.
-      if (c < 0x20 || c > 0x7e) return false
-      i += 1
-    }
-    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 8fabc602a8..8143832c4c 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
@@ -30,32 +30,6 @@ import scala.jdk.CollectionConverters._
 
 class SpanAttrsSpec extends AnyFlatSpec with Matchers {
 
-  // ----- sanitizeFreeText: pure ----------------------------------------
-
-  "sanitizeFreeText" should "return null for null / empty input" in {
-    SpanAttrs.sanitizeFreeText(null) shouldBe null
-    SpanAttrs.sanitizeFreeText("") shouldBe null
-  }
-
-  it should "strip CR/LF and other control characters" in {
-    SpanAttrs.sanitizeFreeText("hello\r\nworld") shouldBe "helloworld"
-    SpanAttrs.sanitizeFreeText("a\u0000b\u0001c\u001fd\u007fe") shouldBe 
"abcde"
-  }
-
-  it should "preserve printable text including spaces" in {
-    SpanAttrs.sanitizeFreeText("my-op v1 (alpha)") shouldBe "my-op v1 (alpha)"
-  }
-
-  it should "cap at FreeTextMaxLen" in {
-    val long = "x" * (SpanAttrs.FreeTextMaxLen * 4)
-    val out = SpanAttrs.sanitizeFreeText(long)
-    out.length shouldBe SpanAttrs.FreeTextMaxLen
-  }
-
-  it should "return null when stripping reduces the input to empty" in {
-    SpanAttrs.sanitizeFreeText("\r\n\u0000\u0001") shouldBe null
-  }
-
   // ----- standard label keys land via the plain OTel API ---------------
 
   "the standard label keys" should "set correctly through the OTel builder 
API" in {
@@ -63,13 +37,11 @@ class SpanAttrsSpec extends AnyFlatSpec with Matchers {
     val sb = tracer.spanBuilder("workflow.execute")
     sb.setAttribute(SpanAttrs.WorkflowId, java.lang.Long.valueOf(42L))
     sb.setAttribute(SpanAttrs.ExecutionId, java.lang.Long.valueOf(7L))
-    sb.setAttribute(SpanAttrs.OperatorName, 
SpanAttrs.sanitizeFreeText("good\r\nFAKE LINE"))
     sb.startSpan().end()
 
     val attrs = exporter.getFinishedSpanItems.asScala.head.getAttributes
     attrs.get(SpanAttrs.WorkflowId) shouldBe 42L
     attrs.get(SpanAttrs.ExecutionId) shouldBe 7L
-    attrs.get(SpanAttrs.OperatorName) shouldBe "goodFAKE LINE"
   }
 
   it should "expose stable key names so callsites share one label vocabulary" 
in {
diff --git 
a/common/observability/src/test/scala/org/apache/texera/observability/TexeraTracerSpec.scala
 
b/common/observability/src/test/scala/org/apache/texera/observability/TexeraTracerSpec.scala
index 77d5b3ab0f..8eed5e8288 100644
--- 
a/common/observability/src/test/scala/org/apache/texera/observability/TexeraTracerSpec.scala
+++ 
b/common/observability/src/test/scala/org/apache/texera/observability/TexeraTracerSpec.scala
@@ -19,7 +19,6 @@
 
 package org.apache.texera.observability
 
-import io.opentelemetry.context.Context
 import org.scalatest.flatspec.AnyFlatSpec
 import org.scalatest.matchers.should.Matchers
 
@@ -39,18 +38,4 @@ class TexeraTracerSpec extends AnyFlatSpec with Matchers {
     TexeraTracer.tracer should not be null
     TexeraTracer.tracer should not be null
   }
-
-  "TexeraTracer.currentContext" should "return the active context" in {
-    TexeraTracer.currentContext shouldBe Context.current()
-  }
-
-  it should "observe a value made current via the OpenTelemetry context" in {
-    val key = 
io.opentelemetry.context.ContextKey.named[String]("texera.tracer.spec.key")
-    val scope = Context.current().`with`(key, "v").makeCurrent()
-    try {
-      TexeraTracer.currentContext.get(key) shouldBe "v"
-    } finally {
-      scope.close()
-    }
-  }
 }
diff --git 
a/common/observability/src/test/scala/org/apache/texera/observability/TraceparentValidatorSpec.scala
 
b/common/observability/src/test/scala/org/apache/texera/observability/TraceparentValidatorSpec.scala
deleted file mode 100644
index 6bf74d99b3..0000000000
--- 
a/common/observability/src/test/scala/org/apache/texera/observability/TraceparentValidatorSpec.scala
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.texera.observability
-
-import org.scalatest.flatspec.AnyFlatSpec
-import org.scalatest.matchers.should.Matchers
-
-class TraceparentValidatorSpec extends AnyFlatSpec with Matchers {
-
-  // ----- traceparent: positive paths -----------------------------------
-
-  "validateTraceparent" should "accept a canonical W3C traceparent" in {
-    val good = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"
-    TraceparentValidator.validateTraceparent(good) shouldBe Some(good)
-  }
-
-  it should "accept sampled=0 flag" in {
-    val good = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-00"
-    TraceparentValidator.validateTraceparent(good) shouldBe Some(good)
-  }
-
-  // ----- traceparent: negative paths -----------------------------------
-
-  it should "reject null and empty input" in {
-    TraceparentValidator.validateTraceparent(null) shouldBe None
-    TraceparentValidator.validateTraceparent("") shouldBe None
-  }
-
-  it should "reject path-traversal-style spoofing attempts" in {
-    TraceparentValidator.validateTraceparent("../../etc/passwd") shouldBe None
-    TraceparentValidator.validateTraceparent(
-      "00-../../../etc/passwd-b7ad6b7169203331-01"
-    ) shouldBe None
-  }
-
-  it should "reject the wrong version byte" in {
-    // Only version 00 is published. 01, ff, etc. are invalid.
-    val bad01 = "01-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"
-    val badff = "ff-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"
-    TraceparentValidator.validateTraceparent(bad01) shouldBe None
-    TraceparentValidator.validateTraceparent(badff) shouldBe None
-  }
-
-  it should "reject all-zero trace-id (sentinel for no-value)" in {
-    val zero = "00-00000000000000000000000000000000-b7ad6b7169203331-01"
-    TraceparentValidator.validateTraceparent(zero) shouldBe None
-  }
-
-  it should "reject all-zero span-id (sentinel for no-value)" in {
-    val zero = "00-0af7651916cd43dd8448eb211c80319c-0000000000000000-01"
-    TraceparentValidator.validateTraceparent(zero) shouldBe None
-  }
-
-  it should "reject UPPERCASE hex (spec requires lowercase)" in {
-    val upper = "00-0AF7651916CD43DD8448EB211C80319C-b7ad6b7169203331-01"
-    TraceparentValidator.validateTraceparent(upper) shouldBe None
-  }
-
-  it should "reject non-hex characters in trace-id" in {
-    val bad = "00-XYZ7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"
-    TraceparentValidator.validateTraceparent(bad) shouldBe None
-  }
-
-  it should "reject wrong-length segments" in {
-    // trace-id one char short
-    val short = "00-af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"
-    // span-id one char long
-    val long = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b71692033311-01"
-    TraceparentValidator.validateTraceparent(short) shouldBe None
-    TraceparentValidator.validateTraceparent(long) shouldBe None
-  }
-
-  it should "reject embedded CRLF (header injection)" in {
-    val crlf =
-      "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01\r\nX-Forge: yes"
-    TraceparentValidator.validateTraceparent(crlf) shouldBe None
-  }
-
-  // ----- tracestate ----------------------------------------------------
-
-  "validateTracestate" should "accept a canonical tracestate" in {
-    val ts = "vendor1=hello,vendor2=world"
-    TraceparentValidator.validateTracestate(ts) shouldBe Some(ts)
-  }
-
-  it should "reject null and empty" in {
-    TraceparentValidator.validateTracestate(null) shouldBe None
-    TraceparentValidator.validateTracestate("") shouldBe None
-  }
-
-  it should "reject tracestate longer than the cap" in {
-    val oversize = "a=" + ("b" * (TraceparentValidator.MaxTracestateLength + 
1))
-    TraceparentValidator.validateTracestate(oversize) shouldBe None
-  }
-
-  it should "reject non-ASCII / control characters" in {
-    TraceparentValidator.validateTracestate("vendor=hello\u00ffworld") 
shouldBe None
-    TraceparentValidator.validateTracestate("vendor=hello\r\nworld") shouldBe 
None
-    TraceparentValidator.validateTracestate("vendor=hello\u0000world") 
shouldBe None
-  }
-
-  it should "accept tracestate at exactly the cap" in {
-    val atCap = "k=" + ("v" * (TraceparentValidator.MaxTracestateLength - 2))
-    atCap.length shouldBe TraceparentValidator.MaxTracestateLength
-    TraceparentValidator.validateTracestate(atCap) shouldBe Some(atCap)
-  }
-}

Reply via email to