@shogo-ai/core 1.9.13 → 2.4.1
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/dist/chunk-H625AGFN.js +466 -0
- package/dist/chunk-MDRCI2CN.js +197 -0
- package/dist/chunk-NTAY4E43.js +72 -0
- package/dist/{chunk-24AL3V6R.js → chunk-VW6ZGCBI.js} +35 -1
- package/dist/{chunk-IDGVRGAL.js → chunk-WRHTXHTH.js} +81 -11
- package/dist/file-types.cjs +79 -5
- package/dist/file-types.d.cts +23 -4
- package/dist/file-types.d.ts +23 -4
- package/dist/file-types.js +7 -1
- package/dist/index.cjs +464 -17
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +35 -7
- package/dist/instrumentation.cjs +95 -10
- package/dist/instrumentation.js +2 -1
- package/dist/logger.cjs +39 -2
- package/dist/logger.d.cts +71 -1
- package/dist/logger.d.ts +71 -1
- package/dist/logger.js +9 -3
- package/dist/stream-buffer.cjs +242 -5
- package/dist/stream-buffer.d.cts +97 -1
- package/dist/stream-buffer.d.ts +97 -1
- package/dist/stream-buffer.js +13 -3
- package/dist/tech-stack-registry.cjs +36 -0
- package/dist/tech-stack-registry.d.cts +48 -1
- package/dist/tech-stack-registry.d.ts +48 -1
- package/dist/tech-stack-registry.js +7 -1
- package/package.json +16 -1
- package/dist/chunk-ELMG6OXT.js +0 -236
- package/dist/chunk-HKX3MEJN.js +0 -126
- package/dist/chunk-KTDDFWXM.js +0 -39
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { LogLevel, Logger, createLogger } from './logger.js';
|
|
1
|
+
export { LogEntry, LogLevel, LogSink, Logger, TraceContext, TraceContextProvider, createLogger, emitLogToSink, setOtelLogSink, setTraceContextProvider } from './logger.js';
|
|
2
2
|
export { InstrumentationConfig, initInstrumentation, shutdownInstrumentation, traceOperation } from './instrumentation.js';
|
|
3
|
-
export { ReplayOptions, StreamBufferStore, StreamBufferWriter, TurnSnapshot, TurnStatus, TurnTerminal, createBufferingTransform } from './stream-buffer.js';
|
|
3
|
+
export { ReplayOptions, StreamBufferStore, StreamBufferWriter, TURN_COMPLETE_EVENT_TYPE, TURN_SEQ_EVENT_TYPE, TurnCompleteFrameData, TurnReply, TurnSnapshot, TurnStatus, TurnTerminal, compactSseFrames, createBufferingTransform, encodeTurnCompleteFrame, encodeTurnSeqFrame } from './stream-buffer.js';
|
|
4
4
|
export { extractUserText, findLastUserMessage } from './chat-message.js';
|
|
5
5
|
export { isMacOSJunkName, isMacOSJunkPath } from './macos-junk.js';
|
|
6
|
-
export { StackRegistryEntry, StackTarget, TECH_STACK_REGISTRY, getStackEntry, isMobileTechStack, stackSeedsItself, usesMetroBundler } from './tech-stack-registry.js';
|
|
7
|
-
export { BINARY_FILE_EXTENSIONS, isBinaryFilePath } from './file-types.js';
|
|
6
|
+
export { StackRegistryEntry, StackTarget, TECH_STACK_REGISTRY, getDeclaredPorts, getMinimumInstanceSize, getStackEntry, isDockerTechStack, isMobileTechStack, stackSeedsItself, usesMetroBundler } from './tech-stack-registry.js';
|
|
7
|
+
export { BINARY_FILE_BASENAMES, BINARY_FILE_EXTENSIONS, BINARY_FILE_TRANSIENT_SUFFIXES, isBinaryBuffer, isBinaryFilePath } from './file-types.js';
|
|
8
8
|
import '@opentelemetry/api';
|
package/dist/index.js
CHANGED
|
@@ -3,46 +3,74 @@ import {
|
|
|
3
3
|
findLastUserMessage
|
|
4
4
|
} from "./chunk-4J7NH2WJ.js";
|
|
5
5
|
import {
|
|
6
|
+
BINARY_FILE_BASENAMES,
|
|
6
7
|
BINARY_FILE_EXTENSIONS,
|
|
8
|
+
BINARY_FILE_TRANSIENT_SUFFIXES,
|
|
9
|
+
isBinaryBuffer,
|
|
7
10
|
isBinaryFilePath
|
|
8
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-MDRCI2CN.js";
|
|
9
12
|
import {
|
|
10
13
|
initInstrumentation,
|
|
11
14
|
shutdownInstrumentation,
|
|
12
15
|
traceOperation
|
|
13
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-WRHTXHTH.js";
|
|
14
17
|
import {
|
|
15
|
-
createLogger
|
|
16
|
-
|
|
18
|
+
createLogger,
|
|
19
|
+
emitLogToSink,
|
|
20
|
+
setOtelLogSink,
|
|
21
|
+
setTraceContextProvider
|
|
22
|
+
} from "./chunk-VW6ZGCBI.js";
|
|
17
23
|
import {
|
|
18
24
|
isMacOSJunkName,
|
|
19
25
|
isMacOSJunkPath
|
|
20
26
|
} from "./chunk-VTD7O7YC.js";
|
|
21
27
|
import {
|
|
22
28
|
StreamBufferStore,
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
TURN_COMPLETE_EVENT_TYPE,
|
|
30
|
+
TURN_SEQ_EVENT_TYPE,
|
|
31
|
+
compactSseFrames,
|
|
32
|
+
createBufferingTransform,
|
|
33
|
+
encodeTurnCompleteFrame,
|
|
34
|
+
encodeTurnSeqFrame
|
|
35
|
+
} from "./chunk-H625AGFN.js";
|
|
25
36
|
import {
|
|
26
37
|
TECH_STACK_REGISTRY,
|
|
38
|
+
getDeclaredPorts,
|
|
39
|
+
getMinimumInstanceSize,
|
|
27
40
|
getStackEntry,
|
|
41
|
+
isDockerTechStack,
|
|
28
42
|
isMobileTechStack,
|
|
29
43
|
stackSeedsItself,
|
|
30
44
|
usesMetroBundler
|
|
31
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-NTAY4E43.js";
|
|
32
46
|
export {
|
|
47
|
+
BINARY_FILE_BASENAMES,
|
|
33
48
|
BINARY_FILE_EXTENSIONS,
|
|
49
|
+
BINARY_FILE_TRANSIENT_SUFFIXES,
|
|
34
50
|
StreamBufferStore,
|
|
35
51
|
TECH_STACK_REGISTRY,
|
|
52
|
+
TURN_COMPLETE_EVENT_TYPE,
|
|
53
|
+
TURN_SEQ_EVENT_TYPE,
|
|
54
|
+
compactSseFrames,
|
|
36
55
|
createBufferingTransform,
|
|
37
56
|
createLogger,
|
|
57
|
+
emitLogToSink,
|
|
58
|
+
encodeTurnCompleteFrame,
|
|
59
|
+
encodeTurnSeqFrame,
|
|
38
60
|
extractUserText,
|
|
39
61
|
findLastUserMessage,
|
|
62
|
+
getDeclaredPorts,
|
|
63
|
+
getMinimumInstanceSize,
|
|
40
64
|
getStackEntry,
|
|
41
65
|
initInstrumentation,
|
|
66
|
+
isBinaryBuffer,
|
|
42
67
|
isBinaryFilePath,
|
|
68
|
+
isDockerTechStack,
|
|
43
69
|
isMacOSJunkName,
|
|
44
70
|
isMacOSJunkPath,
|
|
45
71
|
isMobileTechStack,
|
|
72
|
+
setOtelLogSink,
|
|
73
|
+
setTraceContextProvider,
|
|
46
74
|
shutdownInstrumentation,
|
|
47
75
|
stackSeedsItself,
|
|
48
76
|
traceOperation,
|
package/dist/instrumentation.cjs
CHANGED
|
@@ -26,13 +26,43 @@ __export(instrumentation_exports, {
|
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(instrumentation_exports);
|
|
28
28
|
var import_api = require("@opentelemetry/api");
|
|
29
|
+
var import_api_logs = require("@opentelemetry/api-logs");
|
|
29
30
|
var import_sdk_node = require("@opentelemetry/sdk-node");
|
|
30
31
|
var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
|
|
32
|
+
var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-http");
|
|
31
33
|
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
34
|
+
var import_sdk_logs = require("@opentelemetry/sdk-logs");
|
|
32
35
|
var import_resources = require("@opentelemetry/resources");
|
|
33
36
|
var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
37
|
+
|
|
38
|
+
// src/logger.ts
|
|
39
|
+
var LOG_LEVELS = {
|
|
40
|
+
debug: 0,
|
|
41
|
+
info: 1,
|
|
42
|
+
warn: 2,
|
|
43
|
+
error: 3
|
|
44
|
+
};
|
|
45
|
+
var isProduction = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "staging";
|
|
46
|
+
var minLevel = LOG_LEVELS[process.env.LOG_LEVEL || "info"] ?? 1;
|
|
47
|
+
var logSink = null;
|
|
48
|
+
function setOtelLogSink(sink) {
|
|
49
|
+
logSink = sink;
|
|
50
|
+
}
|
|
51
|
+
var traceContextProvider = null;
|
|
52
|
+
function setTraceContextProvider(provider) {
|
|
53
|
+
traceContextProvider = provider;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/instrumentation.ts
|
|
57
|
+
var SEVERITY_BY_LEVEL = {
|
|
58
|
+
debug: { number: import_api_logs.SeverityNumber.DEBUG, text: "DEBUG" },
|
|
59
|
+
info: { number: import_api_logs.SeverityNumber.INFO, text: "INFO" },
|
|
60
|
+
warn: { number: import_api_logs.SeverityNumber.WARN, text: "WARN" },
|
|
61
|
+
error: { number: import_api_logs.SeverityNumber.ERROR, text: "ERROR" }
|
|
62
|
+
};
|
|
34
63
|
var sdk = null;
|
|
35
64
|
function initInstrumentation(config) {
|
|
65
|
+
if (sdk) return;
|
|
36
66
|
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
37
67
|
if (!endpoint) {
|
|
38
68
|
console.log(`[OTEL] Tracing disabled for ${config.serviceName} (OTEL_EXPORTER_OTLP_ENDPOINT not set)`);
|
|
@@ -46,18 +76,43 @@ function initInstrumentation(config) {
|
|
|
46
76
|
}
|
|
47
77
|
const serviceName = process.env.OTEL_SERVICE_NAME || config.serviceName;
|
|
48
78
|
console.log(`[OTEL] Configuring ${serviceName} \u2192 ${endpoint}/v1/traces`);
|
|
79
|
+
const exportTimeoutMs = Number(process.env.OTEL_EXPORTER_TIMEOUT_MS ?? 3e3);
|
|
49
80
|
let traceExporter;
|
|
50
81
|
try {
|
|
51
82
|
traceExporter = new import_exporter_trace_otlp_http.OTLPTraceExporter({
|
|
52
83
|
url: `${endpoint}/v1/traces`,
|
|
53
|
-
headers
|
|
84
|
+
headers,
|
|
85
|
+
timeoutMillis: exportTimeoutMs
|
|
54
86
|
});
|
|
55
87
|
} catch (err) {
|
|
56
88
|
console.error(`[OTEL] Failed to create exporter: ${err.message}`);
|
|
57
89
|
return;
|
|
58
90
|
}
|
|
59
|
-
const
|
|
60
|
-
const spanProcessor =
|
|
91
|
+
const isProduction2 = process.env.NODE_ENV === "production" || process.env.NODE_ENV === "staging";
|
|
92
|
+
const spanProcessor = isProduction2 ? new import_sdk_trace_base.BatchSpanProcessor(traceExporter, {
|
|
93
|
+
maxQueueSize: 2048,
|
|
94
|
+
maxExportBatchSize: 512,
|
|
95
|
+
scheduledDelayMillis: 5e3,
|
|
96
|
+
exportTimeoutMillis: exportTimeoutMs
|
|
97
|
+
}) : new import_sdk_trace_base.SimpleSpanProcessor(traceExporter);
|
|
98
|
+
let logRecordProcessors = [];
|
|
99
|
+
try {
|
|
100
|
+
const logExporter = new import_exporter_logs_otlp_http.OTLPLogExporter({
|
|
101
|
+
url: `${endpoint}/v1/logs`,
|
|
102
|
+
headers,
|
|
103
|
+
timeoutMillis: exportTimeoutMs
|
|
104
|
+
});
|
|
105
|
+
logRecordProcessors = [
|
|
106
|
+
isProduction2 ? new import_sdk_logs.BatchLogRecordProcessor(logExporter, {
|
|
107
|
+
maxQueueSize: 2048,
|
|
108
|
+
maxExportBatchSize: 512,
|
|
109
|
+
scheduledDelayMillis: 5e3,
|
|
110
|
+
exportTimeoutMillis: exportTimeoutMs
|
|
111
|
+
}) : new import_sdk_logs.SimpleLogRecordProcessor(logExporter)
|
|
112
|
+
];
|
|
113
|
+
} catch (err) {
|
|
114
|
+
console.warn(`[OTEL] Failed to create log exporter for ${serviceName}: ${err.message}`);
|
|
115
|
+
}
|
|
61
116
|
sdk = new import_sdk_node.NodeSDK({
|
|
62
117
|
resource: (0, import_resources.resourceFromAttributes)({
|
|
63
118
|
[import_semantic_conventions.ATTR_SERVICE_NAME]: serviceName,
|
|
@@ -65,6 +120,7 @@ function initInstrumentation(config) {
|
|
|
65
120
|
"deployment.environment.name": process.env.NODE_ENV || "development"
|
|
66
121
|
}),
|
|
67
122
|
spanProcessors: [spanProcessor],
|
|
123
|
+
logRecordProcessors,
|
|
68
124
|
instrumentations: []
|
|
69
125
|
});
|
|
70
126
|
try {
|
|
@@ -75,6 +131,24 @@ function initInstrumentation(config) {
|
|
|
75
131
|
sdk = null;
|
|
76
132
|
return;
|
|
77
133
|
}
|
|
134
|
+
setTraceContextProvider(() => {
|
|
135
|
+
const ctx = import_api.trace.getActiveSpan()?.spanContext();
|
|
136
|
+
return ctx && (0, import_api.isSpanContextValid)(ctx) ? { trace_id: ctx.traceId, span_id: ctx.spanId } : null;
|
|
137
|
+
});
|
|
138
|
+
if (logRecordProcessors.length > 0) {
|
|
139
|
+
const otelLogger = import_api_logs.logs.getLogger(serviceName);
|
|
140
|
+
setOtelLogSink((entry) => {
|
|
141
|
+
const { level, msg, service, timestamp, ...attrs } = entry;
|
|
142
|
+
const severity = SEVERITY_BY_LEVEL[level] ?? SEVERITY_BY_LEVEL.info;
|
|
143
|
+
otelLogger.emit({
|
|
144
|
+
severityNumber: severity.number,
|
|
145
|
+
severityText: severity.text,
|
|
146
|
+
body: msg,
|
|
147
|
+
attributes: { service, ...attrs }
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
console.log(`[OTEL] Logs exporter enabled for ${serviceName} \u2192 ${endpoint}/v1/logs`);
|
|
151
|
+
}
|
|
78
152
|
try {
|
|
79
153
|
const tracer = import_api.trace.getTracer(serviceName);
|
|
80
154
|
const testSpan = tracer.startSpan("otel.startup-test", {
|
|
@@ -95,13 +169,24 @@ function initInstrumentation(config) {
|
|
|
95
169
|
}
|
|
96
170
|
}
|
|
97
171
|
async function shutdownInstrumentation() {
|
|
98
|
-
if (sdk)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
172
|
+
if (!sdk) return;
|
|
173
|
+
setOtelLogSink(null);
|
|
174
|
+
setTraceContextProvider(null);
|
|
175
|
+
const shutdownTimeoutMs = Number(process.env.OTEL_SHUTDOWN_TIMEOUT_MS ?? 2e3);
|
|
176
|
+
let timer;
|
|
177
|
+
try {
|
|
178
|
+
await Promise.race([
|
|
179
|
+
sdk.shutdown(),
|
|
180
|
+
new Promise((resolve) => {
|
|
181
|
+
timer = setTimeout(resolve, shutdownTimeoutMs);
|
|
182
|
+
})
|
|
183
|
+
]);
|
|
184
|
+
console.log("[OTEL] Tracing shut down");
|
|
185
|
+
} catch (err) {
|
|
186
|
+
console.error("[OTEL] Error shutting down:", err.message);
|
|
187
|
+
} finally {
|
|
188
|
+
if (timer) clearTimeout(timer);
|
|
189
|
+
sdk = null;
|
|
105
190
|
}
|
|
106
191
|
}
|
|
107
192
|
function traceOperation(tracerName, spanName, attributes, fn) {
|
package/dist/instrumentation.js
CHANGED
package/dist/logger.cjs
CHANGED
|
@@ -20,7 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/logger.ts
|
|
21
21
|
var logger_exports = {};
|
|
22
22
|
__export(logger_exports, {
|
|
23
|
-
createLogger: () => createLogger
|
|
23
|
+
createLogger: () => createLogger,
|
|
24
|
+
emitLogToSink: () => emitLogToSink,
|
|
25
|
+
setOtelLogSink: () => setOtelLogSink,
|
|
26
|
+
setTraceContextProvider: () => setTraceContextProvider
|
|
24
27
|
});
|
|
25
28
|
module.exports = __toCommonJS(logger_exports);
|
|
26
29
|
var LOG_LEVELS = {
|
|
@@ -42,6 +45,21 @@ function formatEntry(entry) {
|
|
|
42
45
|
const extraStr = Object.keys(extra).length > 0 ? " " + JSON.stringify(extra) : "";
|
|
43
46
|
return `[${service}] ${msg}${extraStr}`;
|
|
44
47
|
}
|
|
48
|
+
var logSink = null;
|
|
49
|
+
function setOtelLogSink(sink) {
|
|
50
|
+
logSink = sink;
|
|
51
|
+
}
|
|
52
|
+
function emitLogToSink(entry) {
|
|
53
|
+
if (!logSink) return;
|
|
54
|
+
try {
|
|
55
|
+
logSink({ timestamp: (/* @__PURE__ */ new Date()).toISOString(), ...entry });
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
var traceContextProvider = null;
|
|
60
|
+
function setTraceContextProvider(provider) {
|
|
61
|
+
traceContextProvider = provider;
|
|
62
|
+
}
|
|
45
63
|
function createLogger(service, defaultExtra) {
|
|
46
64
|
function log(level, msg, extra) {
|
|
47
65
|
if (!shouldLog(level)) return;
|
|
@@ -53,6 +71,16 @@ function createLogger(service, defaultExtra) {
|
|
|
53
71
|
...defaultExtra,
|
|
54
72
|
...extra
|
|
55
73
|
};
|
|
74
|
+
if (traceContextProvider) {
|
|
75
|
+
try {
|
|
76
|
+
const tc = traceContextProvider();
|
|
77
|
+
if (tc) {
|
|
78
|
+
entry.trace_id = tc.trace_id;
|
|
79
|
+
entry.span_id = tc.span_id;
|
|
80
|
+
}
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
56
84
|
const formatted = formatEntry(entry);
|
|
57
85
|
switch (level) {
|
|
58
86
|
case "error":
|
|
@@ -65,6 +93,12 @@ function createLogger(service, defaultExtra) {
|
|
|
65
93
|
console.log(formatted);
|
|
66
94
|
break;
|
|
67
95
|
}
|
|
96
|
+
if (logSink) {
|
|
97
|
+
try {
|
|
98
|
+
logSink(entry);
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
}
|
|
68
102
|
}
|
|
69
103
|
return {
|
|
70
104
|
debug: (msg, extra) => log("debug", msg, extra),
|
|
@@ -76,6 +110,9 @@ function createLogger(service, defaultExtra) {
|
|
|
76
110
|
}
|
|
77
111
|
// Annotate the CommonJS export names for ESM import in node:
|
|
78
112
|
0 && (module.exports = {
|
|
79
|
-
createLogger
|
|
113
|
+
createLogger,
|
|
114
|
+
emitLogToSink,
|
|
115
|
+
setOtelLogSink,
|
|
116
|
+
setTraceContextProvider
|
|
80
117
|
});
|
|
81
118
|
//# sourceMappingURL=logger.cjs.map
|
package/dist/logger.d.cts
CHANGED
|
@@ -19,6 +19,13 @@
|
|
|
19
19
|
* reqLog.warn('slow query', { ms: 4200 })
|
|
20
20
|
*/
|
|
21
21
|
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
22
|
+
interface LogEntry {
|
|
23
|
+
level: LogLevel;
|
|
24
|
+
msg: string;
|
|
25
|
+
service: string;
|
|
26
|
+
timestamp: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
22
29
|
interface Logger {
|
|
23
30
|
debug(msg: string, extra?: Record<string, unknown>): void;
|
|
24
31
|
info(msg: string, extra?: Record<string, unknown>): void;
|
|
@@ -27,6 +34,69 @@ interface Logger {
|
|
|
27
34
|
/** Returns a new logger that merges `extra` into every log entry. */
|
|
28
35
|
child(extra: Record<string, unknown>): Logger;
|
|
29
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Optional sink that forwards every emitted log entry to an external
|
|
39
|
+
* destination (e.g. an OpenTelemetry `LoggerProvider` for OTLP export to
|
|
40
|
+
* SigNoz). Kept as a plain callback so this module has ZERO OpenTelemetry
|
|
41
|
+
* dependency — `instrumentation.ts` installs the sink only when OTEL is
|
|
42
|
+
* configured, and userland consumers that just want a console logger are
|
|
43
|
+
* unaffected. See `setOtelLogSink`.
|
|
44
|
+
*/
|
|
45
|
+
type LogSink = (entry: LogEntry) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Register (or clear, with `null`) a sink invoked for every log entry after
|
|
48
|
+
* it is written to the console. Errors thrown by the sink are swallowed —
|
|
49
|
+
* telemetry must never break application logging.
|
|
50
|
+
*/
|
|
51
|
+
declare function setOtelLogSink(sink: LogSink | null): void;
|
|
52
|
+
/**
|
|
53
|
+
* Forward a pre-built structured entry to the OTEL log sink (if one is
|
|
54
|
+
* installed via `setOtelLogSink`) WITHOUT writing it to the console.
|
|
55
|
+
*
|
|
56
|
+
* `createLogger` always writes to the console *and* the sink. Some callers
|
|
57
|
+
* already persist the line through another channel — e.g. the agent-runtime
|
|
58
|
+
* writes a project's build/console stdout+stderr to on-disk log files — and
|
|
59
|
+
* only need the *additional* OTLP export copy for SigNoz. Routing those lines
|
|
60
|
+
* through `createLogger` would re-print every one of them to the process's own
|
|
61
|
+
* stdout (doubling the on-disk logs and the volume), so this bypasses the
|
|
62
|
+
* console and emits straight to the sink.
|
|
63
|
+
*
|
|
64
|
+
* No-op when no sink is installed (e.g. OTEL disabled), so it is always safe to
|
|
65
|
+
* call unconditionally. Errors thrown by the sink are swallowed — telemetry
|
|
66
|
+
* must never break the caller. `timestamp` defaults to now; any extra fields
|
|
67
|
+
* become OTLP log-record attributes.
|
|
68
|
+
*/
|
|
69
|
+
declare function emitLogToSink(entry: {
|
|
70
|
+
level: LogLevel;
|
|
71
|
+
msg: string;
|
|
72
|
+
service: string;
|
|
73
|
+
timestamp?: string;
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
}): void;
|
|
76
|
+
/** Active trace context, in OpenTelemetry hex form (32-char / 16-char). */
|
|
77
|
+
interface TraceContext {
|
|
78
|
+
trace_id: string;
|
|
79
|
+
span_id: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Optional provider of the active trace context, used to stamp `trace_id` /
|
|
83
|
+
* `span_id` onto every log entry so the *stdout line itself* is trace-
|
|
84
|
+
* correlated. This is the durable "trace-ids-on-stdout" path: a log scraper
|
|
85
|
+
* (the SigNoz k8s-infra DaemonSet, or a host collector tailing serial output
|
|
86
|
+
* on bare-metal guests) can then link logs to traces WITHOUT depending on the
|
|
87
|
+
* app-level OTLP log export, which is unreliable under Bun event-loop pressure.
|
|
88
|
+
*
|
|
89
|
+
* Kept as a plain callback so this module keeps ZERO OpenTelemetry dependency —
|
|
90
|
+
* `instrumentation.ts` registers it once a tracer is live, and userland
|
|
91
|
+
* consumers that just want a console logger are unaffected.
|
|
92
|
+
*/
|
|
93
|
+
type TraceContextProvider = () => TraceContext | null;
|
|
94
|
+
/**
|
|
95
|
+
* Register (or clear, with `null`) the provider consulted on every log call to
|
|
96
|
+
* enrich entries with the active `trace_id` / `span_id`. Errors thrown by the
|
|
97
|
+
* provider are swallowed — telemetry must never break application logging.
|
|
98
|
+
*/
|
|
99
|
+
declare function setTraceContextProvider(provider: TraceContextProvider | null): void;
|
|
30
100
|
declare function createLogger(service: string, defaultExtra?: Record<string, unknown>): Logger;
|
|
31
101
|
|
|
32
|
-
export { type LogLevel, type Logger, createLogger };
|
|
102
|
+
export { type LogEntry, type LogLevel, type LogSink, type Logger, type TraceContext, type TraceContextProvider, createLogger, emitLogToSink, setOtelLogSink, setTraceContextProvider };
|
package/dist/logger.d.ts
CHANGED
|
@@ -19,6 +19,13 @@
|
|
|
19
19
|
* reqLog.warn('slow query', { ms: 4200 })
|
|
20
20
|
*/
|
|
21
21
|
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
22
|
+
interface LogEntry {
|
|
23
|
+
level: LogLevel;
|
|
24
|
+
msg: string;
|
|
25
|
+
service: string;
|
|
26
|
+
timestamp: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
22
29
|
interface Logger {
|
|
23
30
|
debug(msg: string, extra?: Record<string, unknown>): void;
|
|
24
31
|
info(msg: string, extra?: Record<string, unknown>): void;
|
|
@@ -27,6 +34,69 @@ interface Logger {
|
|
|
27
34
|
/** Returns a new logger that merges `extra` into every log entry. */
|
|
28
35
|
child(extra: Record<string, unknown>): Logger;
|
|
29
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Optional sink that forwards every emitted log entry to an external
|
|
39
|
+
* destination (e.g. an OpenTelemetry `LoggerProvider` for OTLP export to
|
|
40
|
+
* SigNoz). Kept as a plain callback so this module has ZERO OpenTelemetry
|
|
41
|
+
* dependency — `instrumentation.ts` installs the sink only when OTEL is
|
|
42
|
+
* configured, and userland consumers that just want a console logger are
|
|
43
|
+
* unaffected. See `setOtelLogSink`.
|
|
44
|
+
*/
|
|
45
|
+
type LogSink = (entry: LogEntry) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Register (or clear, with `null`) a sink invoked for every log entry after
|
|
48
|
+
* it is written to the console. Errors thrown by the sink are swallowed —
|
|
49
|
+
* telemetry must never break application logging.
|
|
50
|
+
*/
|
|
51
|
+
declare function setOtelLogSink(sink: LogSink | null): void;
|
|
52
|
+
/**
|
|
53
|
+
* Forward a pre-built structured entry to the OTEL log sink (if one is
|
|
54
|
+
* installed via `setOtelLogSink`) WITHOUT writing it to the console.
|
|
55
|
+
*
|
|
56
|
+
* `createLogger` always writes to the console *and* the sink. Some callers
|
|
57
|
+
* already persist the line through another channel — e.g. the agent-runtime
|
|
58
|
+
* writes a project's build/console stdout+stderr to on-disk log files — and
|
|
59
|
+
* only need the *additional* OTLP export copy for SigNoz. Routing those lines
|
|
60
|
+
* through `createLogger` would re-print every one of them to the process's own
|
|
61
|
+
* stdout (doubling the on-disk logs and the volume), so this bypasses the
|
|
62
|
+
* console and emits straight to the sink.
|
|
63
|
+
*
|
|
64
|
+
* No-op when no sink is installed (e.g. OTEL disabled), so it is always safe to
|
|
65
|
+
* call unconditionally. Errors thrown by the sink are swallowed — telemetry
|
|
66
|
+
* must never break the caller. `timestamp` defaults to now; any extra fields
|
|
67
|
+
* become OTLP log-record attributes.
|
|
68
|
+
*/
|
|
69
|
+
declare function emitLogToSink(entry: {
|
|
70
|
+
level: LogLevel;
|
|
71
|
+
msg: string;
|
|
72
|
+
service: string;
|
|
73
|
+
timestamp?: string;
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
}): void;
|
|
76
|
+
/** Active trace context, in OpenTelemetry hex form (32-char / 16-char). */
|
|
77
|
+
interface TraceContext {
|
|
78
|
+
trace_id: string;
|
|
79
|
+
span_id: string;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Optional provider of the active trace context, used to stamp `trace_id` /
|
|
83
|
+
* `span_id` onto every log entry so the *stdout line itself* is trace-
|
|
84
|
+
* correlated. This is the durable "trace-ids-on-stdout" path: a log scraper
|
|
85
|
+
* (the SigNoz k8s-infra DaemonSet, or a host collector tailing serial output
|
|
86
|
+
* on bare-metal guests) can then link logs to traces WITHOUT depending on the
|
|
87
|
+
* app-level OTLP log export, which is unreliable under Bun event-loop pressure.
|
|
88
|
+
*
|
|
89
|
+
* Kept as a plain callback so this module keeps ZERO OpenTelemetry dependency —
|
|
90
|
+
* `instrumentation.ts` registers it once a tracer is live, and userland
|
|
91
|
+
* consumers that just want a console logger are unaffected.
|
|
92
|
+
*/
|
|
93
|
+
type TraceContextProvider = () => TraceContext | null;
|
|
94
|
+
/**
|
|
95
|
+
* Register (or clear, with `null`) the provider consulted on every log call to
|
|
96
|
+
* enrich entries with the active `trace_id` / `span_id`. Errors thrown by the
|
|
97
|
+
* provider are swallowed — telemetry must never break application logging.
|
|
98
|
+
*/
|
|
99
|
+
declare function setTraceContextProvider(provider: TraceContextProvider | null): void;
|
|
30
100
|
declare function createLogger(service: string, defaultExtra?: Record<string, unknown>): Logger;
|
|
31
101
|
|
|
32
|
-
export { type LogLevel, type Logger, createLogger };
|
|
102
|
+
export { type LogEntry, type LogLevel, type LogSink, type Logger, type TraceContext, type TraceContextProvider, createLogger, emitLogToSink, setOtelLogSink, setTraceContextProvider };
|
package/dist/logger.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createLogger
|
|
3
|
-
|
|
2
|
+
createLogger,
|
|
3
|
+
emitLogToSink,
|
|
4
|
+
setOtelLogSink,
|
|
5
|
+
setTraceContextProvider
|
|
6
|
+
} from "./chunk-VW6ZGCBI.js";
|
|
4
7
|
export {
|
|
5
|
-
createLogger
|
|
8
|
+
createLogger,
|
|
9
|
+
emitLogToSink,
|
|
10
|
+
setOtelLogSink,
|
|
11
|
+
setTraceContextProvider
|
|
6
12
|
};
|
|
7
13
|
//# sourceMappingURL=logger.js.map
|