ashb commented on code in PR #66036:
URL: https://github.com/apache/airflow/pull/66036#discussion_r3156339439
##########
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:
Logs can have extra context that only applies to some lines, not everything.
These are the only keys we're "know" will exist everywhere
--
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]