zuozhiw commented on code in PR #5376:
URL: https://github.com/apache/texera/pull/5376#discussion_r3680503999


##########
common/config/src/main/scala/org/apache/texera/observability/SpanAttrs.scala:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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 io.opentelemetry.api.common.AttributeKey
+import io.opentelemetry.api.trace.{Span, SpanBuilder}
+
+/**
+  * Thin helper for setting span attributes safely.
+  *
+  * Three rules:
+  *  1. Typed setters only — no public escape hatch for arbitrary
+  *     untyped strings to land on a span as untrusted free text.
+  *  2. Free-text values are CRLF-stripped + capped at
+  *     [[FreeTextMaxLen]] to prevent log/span forging via embedded
+  *     newlines.
+  *  3. Operator IDs and workflow/execution IDs must match a strict
+  *     character set — otherwise dropped silently (the operator
+  *     identifier should be a stable internal value, not user free
+  *     text).
+  */
+object SpanAttrs {
+
+  /** Maximum length for free-text span attribute values. */
+  val FreeTextMaxLen: Int = 256
+
+  /** Validates the shape we accept for operator IDs: alnum + `_.-`,
+    *  1–64 chars. Anything else is dropped (not coerced — we'd rather
+    *  miss a label than leak an unbounded string into a span).
+    */
+  private val OperatorIdPattern = "^[A-Za-z0-9_.\\-]{1,64}$".r.pattern
+
+  // ---- 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")
+
+  // ---- Typed setters for SpanBuilder (used at span-start time) ---------
+
+  def withWorkflowId(b: SpanBuilder, id: Long): SpanBuilder =

Review Comment:
   thanks, looks good



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to