phanikumv commented on code in PR #69079: URL: https://github.com/apache/airflow/pull/69079#discussion_r3511189546
########## ts-sdk/src/coordinator/log-channel.ts: ########## @@ -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. + */ + +// Log channel — newline-delimited JSON log records over TCP. +// +// The Airflow coordinator's `_bridge` reads lines from this socket, +// parses each as JSON, and re-emits through structlog using the same +// handler used for ordinary Python task logs +// (`process_log_messages_from_subprocess`). Required fields are +// `event`, `level`, `logger`, `timestamp`. Extra fields pass through +// as structured log keys. +// +// The `logger` field becomes the bracketed name column in structlog's +// ConsoleRenderer output (e.g. `[ts-sdk.runtime] Coordinator runtime +// started`). Use hierarchical names — `ts-sdk.runtime`, `ts-sdk.comm`, +// `ts-sdk.client` — so SDK-emitted lines are visibly distinct from +// user task logs (which typically use the task's module name). + +import type { Socket } from "node:net"; +import { connectTcp } from "./tcp-connect.js"; + +export type LogLevel = "debug" | "info" | "warning" | "error"; + +export interface LogRecord { + event: string; + level: LogLevel; + logger: string; + timestamp: string; + [key: string]: unknown; +} + +const DEFAULT_LOGGER_NAME = "ts-sdk"; + +export class LogChannel { + private readonly sock: Socket; + private readonly name: string; + private readonly isRoot: boolean; + + private constructor(sock: Socket, name: string, isRoot: boolean) { + this.sock = sock; + this.name = name; + this.isRoot = isRoot; + } Review Comment: Nice catch by jason inline on the test file — CommChannel wires sock.on("close"/"error") in its constructor, LogChannel doesn't. Right now the only thing catching errors is a one-shot listener left over from connectTcp()'s promise — so the first post-connect error slips by silently, and the second one has nothing left to catch it. Could mean quietly losing task logs, or a hard crash Should be a quick fix, just mirror the comm channel's handler here. -- 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]
