Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🪵 fix: Keep the Winston Level Symbol in `jsonTruncateFormat` for OpenTelemetry Logs (#17307)

Pierre Erraud3d813cab11bb
diff --git a/packages/data-schemas/src/config/parsers.spec.ts b/packages/data-schemas/src/config/parsers.spec.ts
index d2d472296f..66c8dbd438 100644
--- a/packages/data-schemas/src/config/parsers.spec.ts
+++ b/packages/data-schemas/src/config/parsers.spec.ts
@@ -1166,4 +1166,87 @@ describe('jsonTruncateFormat structured events', () => {
response_status: 401,
});
});
+
+ it('preserves transport symbols in a single enumeration of the log record', () => {
+ const LEVEL = Symbol.for('level');
+ const format = jsonTruncateFormat();
+ const message = 'x'.repeat(300);
+ const splat = [{ requestId: 'request-123' }];
+ const ownKeys = jest.fn(Reflect.ownKeys);
+ const info = new Proxy<winston.Logform.TransformableInfo>(
+ {
+ level: 'error',
+ message,
+ [LEVEL]: 'error',
+ [MESSAGE_SYMBOL]: message,
+ [SPLAT_SYMBOL]: splat,
+ },
+ { ownKeys },
+ );
+
+ const output = format.transform(info, format.options);
+ if (typeof output !== 'object') {
+ throw new Error('Expected jsonTruncateFormat to preserve the log record');
+ }
+
+ expect(ownKeys).toHaveBeenCalledTimes(1);
+ expect(output[LEVEL]).toBe('error');
+ expect(output[MESSAGE_SYMBOL]).toBe(message);
+ expect(output[SPLAT_SYMBOL]).toBe(splat);
+ expect(output.level).toBe('error');
+ expect(output.message).toBe(`${message.slice(0, 255)}...`);
+ expect(info.message).toBe(message);
+ });
+
+ it('preserves non-enumerable symbols without reading non-enumerable string fields', () => {
+ const LEVEL = Symbol.for('level');
+ const format = jsonTruncateFormat();
+ const info = { level: 'error', message: 'request failed' };
+ const readHidden = jest.fn(() => {
+ throw new Error('Hidden string fields must not be read');
+ });
+ Object.defineProperties(info, {
+ [LEVEL]: { value: 'error', enumerable: false },
+ hidden: { get: readHidden, enumerable: false },
+ });
+
+ const output = format.transform(info, format.options);
+ if (typeof output !== 'object') {
+ throw new Error('Expected jsonTruncateFormat to preserve the log record');
+ }
+
+ expect(output[LEVEL]).toBe('error');
+ expect(output).not.toHaveProperty('hidden');
+ expect(readHidden).not.toHaveBeenCalled();
+ });
+
+ it('keeps nested values JSON-shaped while truncating strings and handling cycles', () => {
+ const format = jsonTruncateFormat();
+ const message = 'x'.repeat(300);
+ const nested: Record<string | symbol, unknown> = {
+ detail: message,
+ items: [{ detail: message }],
+ [SPLAT_SYMBOL]: [{ detail: message }],
+ };
+ nested.self = nested;
+ const readHidden = jest.fn(() => {
+ throw new Error('Hidden string fields must not be read');
+ });
+ Object.defineProperty(nested, 'hidden', { get: readHidden, enumerable: false });
+ const info = { level: 'info', message: 'event', metadata: nested };
+
+ const output = format.transform(info, format.options);
+ if (typeof output !== 'object') {
+ throw new Error('Expected jsonTruncateFormat to preserve the log record');
+ }
+
+ expect(output.metadata).toEqual({
+ detail: `${message.slice(0, 255)}...`,
+ items: [{ detail: `${message.slice(0, 255)}...` }],
+ self: '[Circular]',
+ });
+ expect(nested.detail).toBe(message);
+ expect(nested.self).toBe(nested);
+ expect(readHidden).not.toHaveBeenCalled();
+ });
});
diff --git a/packages/data-schemas/src/config/parsers.ts b/packages/data-schemas/src/config/parsers.ts
index 3af5fca305..79c0db762f 100644
--- a/packages/data-schemas/src/config/parsers.ts
+++ b/packages/data-schemas/src/config/parsers.ts
@@ -1044,16 +1044,25 @@ const jsonTruncateFormat: winston.Logform.FormatWrap = winston.format(
return obj.map((item) => truncateObject(item));
}
- // We know this is an object at this point
- const objectRecord = obj as Record<string, unknown>;
- const newObj: Record<string, unknown> = {};
- Object.entries(objectRecord).forEach(([key, value]) => {
+ const objectRecord = obj as Record<string | symbol, unknown>;
+ const newObj: Record<string | symbol, unknown> = {};
+ // Only the log record carries transport symbols; nested values stay JSON-shaped.
+ const keys = obj === info ? Reflect.ownKeys(objectRecord) : Object.keys(objectRecord);
+ for (const key of keys) {
+ if (typeof key === 'symbol') {
+ newObj[key] = objectRecord[key];
+ continue;
+ }
+ if (!Object.prototype.propertyIsEnumerable.call(objectRecord, key)) {
+ continue;
+ }
+ const value = objectRecord[key];
if (typeof value === 'string') {
newObj[key] = truncateLongStrings(value, CONSOLE_JSON_STRING_LENGTH);
} else {
newObj[key] = truncateObject(value);
}
- });
+ }
return newObj;
};