bbovenzi commented on code in PR #66036:
URL: https://github.com/apache/airflow/pull/66036#discussion_r3156279567


##########
airflow-core/src/airflow/ui/src/components/renderStructuredLog.tsx:
##########
@@ -109,6 +109,65 @@ const addAnsiWithLinks = (line: string) => {
 
 const sourceFields = ["logger", "chan", "lineno", "filename", "loc"];
 
+// Fields bound once per task-instance process via bind_contextvars — 
identical on every log line,
+// so we strip them from per-line rendering and show them once as a preamble 
instead.
+export const tiContextFields = ["ti_id", "dag_id", "task_id", "run_id", 
"try_number", "map_index"];
+
+export const renderTIContextPreamble = (
+  context: Record<string, unknown>,
+  renderingMode: "jsx" | "text" = "jsx",
+  label?: string,
+): JSX.Element | string => {
+  const fields = tiContextFields.filter((field) => field in context);
+
+  if (renderingMode === "text") {
+    const prefix = label === undefined ? "" : `${label} `;
+
+    return prefix + fields.map((field) => 
`${field}=${String(context[field])}`).join(" ");
+  }
+
+  return (
+    <chakra.span lineHeight={1.5} opacity={0.7}>
+      {label === undefined ? undefined : <chakra.span 
fontWeight="medium">{label}</chakra.span>}
+      {fields.map((field) => (
+        <React.Fragment key={field}>
+          {" "}
+          <span>
+            <chakra.span 
color="fg.info">{field}</chakra.span>={String(context[field])}
+          </span>
+        </React.Fragment>
+      ))}
+    </chakra.span>
+  );
+};
+
+const extractFromStructuredDatum = (datum: StructuredLogMessage): 
Record<string, unknown> => {
+  const ctx: Record<string, unknown> = {};
+
+  for (const field of tiContextFields) {
+    if (Object.hasOwn(datum, field) && datum[field] !== undefined) {
+      ctx[field] = datum[field];
+    }
+  }
+
+  return ctx;
+};
+
+export const extractTIContext = (data: TaskInstancesLogResponse["content"]): 
Record<string, unknown> => {

Review Comment:
   Are there other times when a structured log message would have `task_id: ""` 
in a json format? If so do we always want to format it this way?
   
   Now I am also wondering if we just always want to fallback to this key/value 
rendering for structured logs if there is not a more custom way we want to 
render it.



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