oh-langfuse 0.1.30 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oh-langfuse",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Use npm scripts to configure Claude Code / OpenCode / Codex with Langfuse tracing.",
@@ -23,6 +23,7 @@
23
23
  "scripts/opencode-langfuse-setup.mjs",
24
24
  "scripts/resolve-opencode-cli.mjs",
25
25
  "scripts/real-self-verify.mjs",
26
+ "scripts/log-filter-utils.mjs",
26
27
  "scripts/metrics-utils.mjs",
27
28
  "scripts/update-langfuse-runtime.mjs",
28
29
  "scripts/update-utils.mjs",
@@ -0,0 +1,18 @@
1
+ function envShowsWarnings(env = process.env) {
2
+ return /^(1|true|yes|on)$/i.test(String(env.OH_LANGFUSE_SHOW_WARN || env.LANGFUSE_SHOW_WARN || ""));
3
+ }
4
+
5
+ export function shouldSuppressAgentLogLine(line, options = {}) {
6
+ const showWarnings = options.showWarnings ?? envShowsWarnings(options.env);
7
+ if (showWarnings) return false;
8
+ const text = String(line || "").trim();
9
+ return /(?:^|\s)(npm\s+warn|warn(?:ing)?\b|\[warn\])/i.test(text);
10
+ }
11
+
12
+ export function filterAgentLogText(text, options = {}) {
13
+ const source = String(text || "");
14
+ return source
15
+ .split(/\r?\n/)
16
+ .filter((line) => line !== "" && !shouldSuppressAgentLogLine(line, options))
17
+ .join("\n");
18
+ }
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
  import os from "node:os";
4
4
  import { spawn, spawnSync } from "node:child_process";
5
5
  import { parseJsonRelaxed, stripBom } from "./json-utils.mjs";
6
+ import { shouldSuppressAgentLogLine } from "./log-filter-utils.mjs";
6
7
 
7
8
  const USER_ID_PATTERN = /^[a-z](?:\d{8}|wx\d{7})$/;
8
9
  const USER_ID_PATTERN_TEXT = "^[a-z](?:\\d{8}|wx\\d{7})$";
@@ -114,7 +115,8 @@ function getPatchedLangfuseDistIndexJs() {
114
115
  // This replaces opencode-plugin-langfuse/dist/index.js to inject userId into spans.
115
116
  // It is intentionally self-contained (no extra build steps).
116
117
  return [
117
- 'import { LangfuseSpanProcessor } from "@langfuse/otel";',
118
+ 'import { LangfuseSpanProcessor } from "@langfuse/otel";',
119
+ 'import { configureGlobalLogger, LogLevel } from "@langfuse/core";',
118
120
  'import { promises as fs } from "node:fs";',
119
121
  'import os from "node:os";',
120
122
  'import path from "node:path";',
@@ -128,7 +130,7 @@ function getPatchedLangfuseDistIndexJs() {
128
130
  ' "config.json"',
129
131
  ");",
130
132
  "",
131
- "const readConfiguredUserId = async () => {",
133
+ "const readConfiguredUserId = async () => {",
132
134
  " try {",
133
135
  ' const content = await fs.readFile(USER_CONFIG_PATH, "utf8");',
134
136
  " // tolerate UTF-8 BOM",
@@ -144,8 +146,14 @@ function getPatchedLangfuseDistIndexJs() {
144
146
  " } catch {",
145
147
  " return undefined;",
146
148
  " }",
147
- "};",
148
- "",
149
+ "};",
150
+ "",
151
+ "const showWarnings = /^(1|true|yes|on)$/i.test(String(process.env.OH_LANGFUSE_SHOW_WARN || process.env.LANGFUSE_SHOW_WARN || ''));",
152
+ "if (!showWarnings) {",
153
+ " process.env.LANGFUSE_LOG_LEVEL = 'ERROR';",
154
+ " configureGlobalLogger({ level: LogLevel.ERROR });",
155
+ "}",
156
+ "",
149
157
  "const createUserIdSpanProcessor = (userId) => ({",
150
158
  " onStart: (span) => {",
151
159
  ' span.setAttribute("langfuse.user.id", userId);',
@@ -360,11 +368,12 @@ function getPatchedLangfuseDistIndexJs() {
360
368
  "",
361
369
  " const userIdFromConfig = await readConfiguredUserId();",
362
370
  " const userIdEnv = process.env.LANGFUSE_USER_ID?.trim();",
363
- " const userId = userIdFromConfig || userIdEnv;",
364
- "",
365
- " const log = (level, message) => {",
366
- ' client.app.log({ body: { service: "langfuse-otel", level, message } });',
367
- " };",
371
+ " const userId = userIdFromConfig || userIdEnv;",
372
+ "",
373
+ " const log = (level, message) => {",
374
+ " if (level === 'warn' && !showWarnings) return;",
375
+ ' client.app.log({ body: { service: "langfuse-otel", level, message } });',
376
+ " };",
368
377
  "",
369
378
  " if (!publicKey || !secretKey) {",
370
379
  ' log("warn", "Missing LANGFUSE_PUBLIC_KEY or LANGFUSE_SECRET_KEY - tracing disabled");',
@@ -676,7 +685,11 @@ function runNpmInstallCapture(npmArgs) {
676
685
  child.stderr?.on("data", (chunk) => {
677
686
  const text = String(chunk);
678
687
  stderr += text;
679
- process.stderr.write(text);
688
+ const filtered = text
689
+ .split(/(\r?\n)/)
690
+ .filter((part) => part === "\n" || part === "\r\n" || !shouldSuppressAgentLogLine(part))
691
+ .join("");
692
+ if (filtered) process.stderr.write(filtered);
680
693
  });
681
694
  child.on("error", (error) => {
682
695
  clearInterval(timer);