Yicong-Huang commented on code in PR #5375:
URL: https://github.com/apache/texera/pull/5375#discussion_r3509227937


##########
common/config/src/main/scala/org/apache/texera/observability/TexeraOtelLogAppender.scala:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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

Review Comment:
   Should this (not just this file, I mean the entire package) be under common 
so that other services can later use as well? 



##########
common/config/src/main/scala/org/apache/texera/observability/LogSanitizer.scala:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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 scala.jdk.CollectionConverters._
+
+/**
+  * Pure functions that sanitize log bodies and MDC before export:
+  * strip control characters, redact secrets, cap body size, and
+  * filter MDC to an allowlist.
+  */
+object LogSanitizer {
+
+  /** Per-record body byte cap. */
+  val MaxBodyBytes: Int = 16 * 1024
+
+  /** Suffix appended to truncated bodies. */
+  val TruncatedMarker: String = "...[truncated]"
+
+  /** C0 control characters except TAB (0x09), plus DEL (0x7F). */
+  private val C0ControlRegex = "[\\x00-\\x08\\x0A-\\x1F\\x7F]".r
+
+  /** Secret patterns, redacted from bodies. Most specific first. */
+  private val SecretPatterns: Seq[scala.util.matching.Regex] = Seq(
+    // Bearer token
+    """(?i)Bearer\s+[A-Za-z0-9._\-/+=]{8,}""".r,
+    // password=... or password: ...
+    """(?i)password\s*[=:]\s*[^\s,;"']+""".r,
+    // AWS access key ID
+    """AKIA[0-9A-Z]{16}""".r,
+    // labelled AWS secret access key
+    """(?i)aws_secret_access_key\s*[=:]\s*[A-Za-z0-9/+=]{20,}""".r
+  )
+
+  /** MDC keys forwarded to OTel log attributes; others are dropped. */
+  val AllowedMdcKeys: Set[String] = Set(
+    "trace_id",
+    "span_id",
+    "texera.user.id",
+    "texera.workflow.id",
+    "texera.execution.id",
+    "texera.computing_unit.id",
+    "texera.project.id",
+    "texera.operator.id"
+  )

Review Comment:
   I wonder how do we decide what ids to forward to OTel, also, can we list 
other dropped ones (if any)?



##########
common/config/build.sbt:
##########
@@ -48,8 +48,28 @@ Compile / scalacOptions ++= Seq(
 // Dependencies
 /////////////////////////////////////////////////////////////////////////////
 
+// OpenTelemetry version is pinned here as the single source of truth; all
+// services pick it up transitively via dependsOn(Config). Bump deliberately.
+val openTelemetryVersion = "1.50.0"
+
 // Core Dependencies
 libraryDependencies ++= Seq(
-  "com.typesafe" % "config" % "1.4.6", // For configuration management
-  "org.scalatest" %% "scalatest" % "3.2.15" % Test // ScalaTest (for unit 
tests)
+  "com.typesafe" % "config" % "1.4.6",                                  // For 
configuration management
+  "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5",            // for 
LazyLogging in OtelInit
+  // OpenTelemetry SDK bootstrap (Apache-2.0). We deliberately do NOT use
+  // sdk-extension-autoconfigure: the security model requires that endpoint
+  // + resource-attribute filtering run before any exporter is configured.
+  "io.opentelemetry" % "opentelemetry-api" % openTelemetryVersion,
+  "io.opentelemetry" % "opentelemetry-sdk" % openTelemetryVersion,
+  "io.opentelemetry" % "opentelemetry-exporter-otlp" % openTelemetryVersion,
+  // Logback Classic — needed at compile time to write the OTel log
+  // appender. Marked `provided` because every service already brings
+  // Logback in transitively (via Dropwizard / SLF4J), so we don't
+  // bundle a second copy.
+  "ch.qos.logback" % "logback-classic" % "1.2.13" % "provided",
+  // Test-only: in-memory exporter for OtelInitSpec; avoids hitting a real
+  // collector during unit tests.
+  "io.opentelemetry" % "opentelemetry-sdk-testing" % openTelemetryVersion % 
Test,
+  "ch.qos.logback" % "logback-classic" % "1.2.13" % Test,
+  "org.scalatest" %% "scalatest" % "3.2.17" % Test

Review Comment:
   shall we avoid bumping scalatest version in this PR?



##########
common/config/build.sbt:
##########
@@ -48,8 +48,28 @@ Compile / scalacOptions ++= Seq(
 // Dependencies
 /////////////////////////////////////////////////////////////////////////////
 
+// OpenTelemetry version is pinned here as the single source of truth; all
+// services pick it up transitively via dependsOn(Config). Bump deliberately.
+val openTelemetryVersion = "1.50.0"
+
 // Core Dependencies
 libraryDependencies ++= Seq(
-  "com.typesafe" % "config" % "1.4.6", // For configuration management
-  "org.scalatest" %% "scalatest" % "3.2.15" % Test // ScalaTest (for unit 
tests)
+  "com.typesafe" % "config" % "1.4.6",                                  // For 
configuration management
+  "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5",            // for 
LazyLogging in OtelInit
+  // OpenTelemetry SDK bootstrap (Apache-2.0). We deliberately do NOT use
+  // sdk-extension-autoconfigure: the security model requires that endpoint
+  // + resource-attribute filtering run before any exporter is configured.
+  "io.opentelemetry" % "opentelemetry-api" % openTelemetryVersion,
+  "io.opentelemetry" % "opentelemetry-sdk" % openTelemetryVersion,
+  "io.opentelemetry" % "opentelemetry-exporter-otlp" % openTelemetryVersion,
+  // Logback Classic — needed at compile time to write the OTel log
+  // appender. Marked `provided` because every service already brings
+  // Logback in transitively (via Dropwizard / SLF4J), so we don't
+  // bundle a second copy.
+  "ch.qos.logback" % "logback-classic" % "1.2.13" % "provided",
+  // Test-only: in-memory exporter for OtelInitSpec; avoids hitting a real
+  // collector during unit tests.
+  "io.opentelemetry" % "opentelemetry-sdk-testing" % openTelemetryVersion % 
Test,
+  "ch.qos.logback" % "logback-classic" % "1.2.13" % Test,

Review Comment:
   I see you are introducing same dependencies to each of the service. can we 
group them into one package and let services depend on it? that's easier to 
manage



-- 
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