@dasasian/firebase-structured-logger 0.5.0 → 0.7.0
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/README.md +652 -91
- package/dist/client/breadcrumbs.d.ts +14 -2
- package/dist/client/breadcrumbs.d.ts.map +1 -1
- package/dist/client/breadcrumbs.js +39 -21
- package/dist/client/breadcrumbs.js.map +1 -1
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/logger.d.ts +29 -0
- package/dist/client/logger.d.ts.map +1 -1
- package/dist/client/logger.js +39 -5
- package/dist/client/logger.js.map +1 -1
- package/dist/client/rateLimiter.d.ts +8 -3
- package/dist/client/rateLimiter.d.ts.map +1 -1
- package/dist/client/rateLimiter.js +9 -4
- package/dist/client/rateLimiter.js.map +1 -1
- package/dist/functions/httpHandler.d.ts +89 -0
- package/dist/functions/httpHandler.d.ts.map +1 -0
- package/dist/functions/httpHandler.js +112 -0
- package/dist/functions/httpHandler.js.map +1 -0
- package/dist/functions/index.d.ts +6 -3
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js +6 -2
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/logHandler.d.ts +53 -2
- package/dist/functions/logHandler.d.ts.map +1 -1
- package/dist/functions/logHandler.js +38 -7
- package/dist/functions/logHandler.js.map +1 -1
- package/dist/functions/logger.d.ts.map +1 -1
- package/dist/functions/logger.js +95 -7
- package/dist/functions/logger.js.map +1 -1
- package/dist/functions/requestLogger.d.ts +2 -20
- package/dist/functions/requestLogger.d.ts.map +1 -1
- package/dist/functions/requestLogger.js +2 -39
- package/dist/functions/requestLogger.js.map +1 -1
- package/dist/functions/sourceMapCache.d.ts +27 -1
- package/dist/functions/sourceMapCache.d.ts.map +1 -1
- package/dist/functions/sourceMapCache.js +84 -9
- package/dist/functions/sourceMapCache.js.map +1 -1
- package/dist/functions/traceContext.d.ts +40 -0
- package/dist/functions/traceContext.d.ts.map +1 -0
- package/dist/functions/traceContext.js +93 -0
- package/dist/functions/traceContext.js.map +1 -0
- package/dist/shared/paths.d.ts +59 -0
- package/dist/shared/paths.d.ts.map +1 -0
- package/dist/shared/paths.js +126 -0
- package/dist/shared/paths.js.map +1 -0
- package/dist/shared/severity.d.ts +21 -0
- package/dist/shared/severity.d.ts.map +1 -1
- package/dist/shared/severity.js +31 -3
- package/dist/shared/severity.js.map +1 -1
- package/dist/shared/types.d.ts +1 -2
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/tools/index.js +13 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/uploadSourceMaps.d.ts +24 -1
- package/dist/tools/uploadSourceMaps.d.ts.map +1 -1
- package/dist/tools/uploadSourceMaps.js +31 -4
- package/dist/tools/uploadSourceMaps.js.map +1 -1
- package/package.json +4 -4
- package/skills/logs/SKILL.md +32 -9
- package/skills/query-logs/SKILL.md +14 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpHandler.js","sourceRoot":"","sources":["../../src/functions/httpHandler.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAgGH,oDA8DC;AA5JD,6CAAkG;AAElG,iDAAiE;AAwDjE,MAAM,MAAM,GAA2C;IACrD,kBAAkB,EAAE,GAAG;IACvB,QAAQ,EAAE,GAAG;CACd,CAAA;AAED,SAAS,IAAI,CAAC,GAAoB,EAAE,MAAc,EAAE,IAA6B;IAC/E,GAAG,CAAC,UAAU,GAAG,MAAM,CAAA;IACvB,IAAI,IAAI,EAAE,CAAC;QACT,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAA;QACjD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAC/B,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,GAAG,EAAE,CAAA;IACX,CAAC;AACH,CAAC;AA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ter } from './logger';
|
|
4
|
-
export { withLogging,
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
4
|
+
export { withLogging, getLogger } from './requestLogger';
|
|
5
|
+
export { configureAttachments } from './sourceMapCache';
|
|
6
|
+
export { createClientLogHandler, createClientLogFunction, ClientLogError } from './logHandler';
|
|
7
|
+
export { createHttpLogHandler } from './httpHandler';
|
|
8
|
+
export type { ClientLogHandlerConfig, ClientLogRequest } from './logHandler';
|
|
9
|
+
export type { HttpLogHandlerConfig, HttpLogRequest, HttpLogResponse } from './httpHandler';
|
|
7
10
|
export type { LogSeverity, LogPayload, BaseLabels } from '../shared/types';
|
|
8
11
|
export declare const logError: (...args: Parameters<LogWriter["error"]>) => void;
|
|
9
12
|
export declare const logWarn: (...args: Parameters<LogWriter["warning"]>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACpD,YAAY,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC5E,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC1F,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE1E,eAAO,MAAM,QAAQ,GAAI,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAG,IAAkC,CAAA;AACrG,eAAO,MAAM,OAAO,GAAI,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,KAAG,IAAoC,CAAA;AACxG,eAAO,MAAM,OAAO,GAAI,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,KAAG,IAAiC,CAAA;AAClG,eAAO,MAAM,QAAQ,GAAI,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAG,IAAkC,CAAA"}
|
package/dist/functions/index.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logDebug = exports.logInfo = exports.logWarn = exports.logError = exports.createClientLogFunction = exports.createClientLogHandler = exports.
|
|
3
|
+
exports.logDebug = exports.logInfo = exports.logWarn = exports.logError = exports.createHttpLogHandler = exports.ClientLogError = exports.createClientLogFunction = exports.createClientLogHandler = exports.configureAttachments = exports.getLogger = exports.withLogging = exports.initLogger = void 0;
|
|
4
4
|
const requestLogger_1 = require("./requestLogger");
|
|
5
5
|
var logger_1 = require("./logger");
|
|
6
6
|
Object.defineProperty(exports, "initLogger", { enumerable: true, get: function () { return logger_1.initLogger; } });
|
|
7
7
|
var requestLogger_2 = require("./requestLogger");
|
|
8
8
|
Object.defineProperty(exports, "withLogging", { enumerable: true, get: function () { return requestLogger_2.withLogging; } });
|
|
9
|
-
Object.defineProperty(exports, "initRequestLogger", { enumerable: true, get: function () { return requestLogger_2.initRequestLogger; } });
|
|
10
9
|
Object.defineProperty(exports, "getLogger", { enumerable: true, get: function () { return requestLogger_2.getLogger; } });
|
|
10
|
+
var sourceMapCache_1 = require("./sourceMapCache");
|
|
11
|
+
Object.defineProperty(exports, "configureAttachments", { enumerable: true, get: function () { return sourceMapCache_1.configureAttachments; } });
|
|
11
12
|
var logHandler_1 = require("./logHandler");
|
|
12
13
|
Object.defineProperty(exports, "createClientLogHandler", { enumerable: true, get: function () { return logHandler_1.createClientLogHandler; } });
|
|
13
14
|
Object.defineProperty(exports, "createClientLogFunction", { enumerable: true, get: function () { return logHandler_1.createClientLogFunction; } });
|
|
15
|
+
Object.defineProperty(exports, "ClientLogError", { enumerable: true, get: function () { return logHandler_1.ClientLogError; } });
|
|
16
|
+
var httpHandler_1 = require("./httpHandler");
|
|
17
|
+
Object.defineProperty(exports, "createHttpLogHandler", { enumerable: true, get: function () { return httpHandler_1.createHttpLogHandler; } });
|
|
14
18
|
const logError = (...args) => (0, requestLogger_1.getLogger)().error(...args);
|
|
15
19
|
exports.logError = logError;
|
|
16
20
|
const logWarn = (...args) => (0, requestLogger_1.getLogger)().warning(...args);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;;AAAA,mDAA2C;AAG3C,mCAAqC;AAA5B,oGAAA,UAAU,OAAA;AAEnB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;;AAAA,mDAA2C;AAG3C,mCAAqC;AAA5B,oGAAA,UAAU,OAAA;AAEnB,iDAAwD;AAA/C,4GAAA,WAAW,OAAA;AAAE,0GAAA,SAAS,OAAA;AAC/B,mDAAuD;AAA9C,sHAAA,oBAAoB,OAAA;AAC7B,2CAA8F;AAArF,oHAAA,sBAAsB,OAAA;AAAE,qHAAA,uBAAuB,OAAA;AAAE,4GAAA,cAAc,OAAA;AACxE,6CAAoD;AAA3C,mHAAA,oBAAoB,OAAA;AAKtB,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAoC,EAAQ,EAAE,CAAC,IAAA,yBAAS,GAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;AAAxF,QAAA,QAAQ,YAAgF;AAC9F,MAAM,OAAO,GAAG,CAAC,GAAG,IAAsC,EAAQ,EAAE,CAAC,IAAA,yBAAS,GAAE,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAA;AAA3F,QAAA,OAAO,WAAoF;AACjG,MAAM,OAAO,GAAG,CAAC,GAAG,IAAmC,EAAQ,EAAE,CAAC,IAAA,yBAAS,GAAE,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;AAArF,QAAA,OAAO,WAA8E;AAC3F,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAoC,EAAQ,EAAE,CAAC,IAAA,yBAAS,GAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;AAAxF,QAAA,QAAQ,YAAgF"}
|
|
@@ -1,9 +1,60 @@
|
|
|
1
|
-
import { type CallableRequest } from 'firebase-functions/v2/https';
|
|
2
1
|
import type { LogPayload } from '../shared/types';
|
|
3
2
|
export interface ClientLogHandlerConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Storage bucket for **both** source maps and attachments.
|
|
5
|
+
*
|
|
6
|
+
* Maps go to `sourcemaps/{releaseId}/`, attachments to `logAttachments/{logId}/`.
|
|
7
|
+
* Defaults to the project's default bucket.
|
|
8
|
+
*
|
|
9
|
+
* Attachments read it as a fallback, not directly — this sets the process-wide
|
|
10
|
+
* default that `writeLog` reaches for, since the upload happens outside any
|
|
11
|
+
* handler. Override either half independently with `sourceMaps` below or
|
|
12
|
+
* `configureAttachments()`.
|
|
13
|
+
*/
|
|
4
14
|
bucketName?: string;
|
|
5
15
|
cors?: boolean | string | string[];
|
|
6
16
|
maxInstances?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Where this handler looks for source maps in Cloud Storage.
|
|
19
|
+
*
|
|
20
|
+
* Genuinely per-handler: both values travel explicitly to `getSourceMap`, so
|
|
21
|
+
* two handlers configured differently cannot resolve to whichever was
|
|
22
|
+
* constructed last. `bucket` overrides `bucketName` for map lookups only.
|
|
23
|
+
*
|
|
24
|
+
* `prefix` must match `fsl upload-sourcemaps --prefix`. They are the two ends
|
|
25
|
+
* of one contract (#35) and nothing checks them against each other — when they
|
|
26
|
+
* disagree the maps are simply not found and stacks stay minified.
|
|
27
|
+
*
|
|
28
|
+
* Attachments are configured separately, with `configureAttachments()` — the
|
|
29
|
+
* upload happens outside any handler, so a field here would be a lie.
|
|
30
|
+
*/
|
|
31
|
+
sourceMaps?: {
|
|
32
|
+
bucket?: string;
|
|
33
|
+
prefix?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What the bare handler throws.
|
|
38
|
+
*
|
|
39
|
+
* It used to throw `HttpsError` directly, which made the handler
|
|
40
|
+
* Firebase-shaped in its failures as well as its input — a caller running it
|
|
41
|
+
* behind anything else got an error carrying a callable protocol's vocabulary.
|
|
42
|
+
* `createClientLogFunction` converts these back, so a callable client sees
|
|
43
|
+
* exactly what it saw before.
|
|
44
|
+
*/
|
|
45
|
+
export declare class ClientLogError extends Error {
|
|
46
|
+
readonly code: 'invalid-argument' | 'internal';
|
|
47
|
+
constructor(code: 'invalid-argument' | 'internal', message: string);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The minimum the handler actually reads.
|
|
51
|
+
*
|
|
52
|
+
* `CallableRequest` was in the signature and only `.data` was ever touched —
|
|
53
|
+
* not `.auth`, not `.rawRequest`. Saying so is what lets an Express adapter, or
|
|
54
|
+
* anything else, call this without constructing a callable request (#34).
|
|
55
|
+
*/
|
|
56
|
+
export interface ClientLogRequest {
|
|
57
|
+
data: LogPayload;
|
|
7
58
|
}
|
|
8
59
|
/**
|
|
9
60
|
* Create an onCall handler that receives LogPayload from the client,
|
|
@@ -12,7 +63,7 @@ export interface ClientLogHandlerConfig {
|
|
|
12
63
|
* @example
|
|
13
64
|
* export const logFrontendEvent = onCall(createClientLogHandler({ bucketName: 'my-bucket' }))
|
|
14
65
|
*/
|
|
15
|
-
export declare function createClientLogHandler(config: ClientLogHandlerConfig): (request:
|
|
66
|
+
export declare function createClientLogHandler(config: ClientLogHandlerConfig): (request: ClientLogRequest) => Promise<void>;
|
|
16
67
|
/**
|
|
17
68
|
* Convenience factory that wraps createClientLogHandler in onCall.
|
|
18
69
|
* Use when you want a ready-to-export Cloud Function.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logHandler.d.ts","sourceRoot":"","sources":["../../src/functions/logHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logHandler.d.ts","sourceRoot":"","sources":["../../src/functions/logHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,iBAAiB,CAAA;AAU/D,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;;;OAUG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,CAAA;IAClC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;;;;;;;;;;OAaG;IACH,UAAU,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAClD;AAID;;;;;;;;GAQG;AACH,qBAAa,cAAe,SAAQ,KAAK;IAErC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,GAAG,UAAU;gBAArC,IAAI,EAAE,kBAAkB,GAAG,UAAU,EAC9C,OAAO,EAAE,MAAM;CAKlB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAA;CACjB;AA6DD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,IAGrD,SAAS,gBAAgB,KAAG,OAAO,CAAC,IAAI,CAAC,CAqCxD;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,sBAAsB,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,8FAgB/F"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientLogError = void 0;
|
|
3
4
|
exports.createClientLogHandler = createClientLogHandler;
|
|
4
5
|
exports.createClientLogFunction = createClientLogFunction;
|
|
5
6
|
const https_1 = require("firebase-functions/v2/https");
|
|
@@ -8,6 +9,24 @@ const logger_1 = require("./logger");
|
|
|
8
9
|
const sourceMapCache_1 = require("./sourceMapCache");
|
|
9
10
|
const symbolicate_1 = require("./symbolicate");
|
|
10
11
|
const VALID_SEVERITIES = new Set(severity_1.SEVERITIES);
|
|
12
|
+
/**
|
|
13
|
+
* What the bare handler throws.
|
|
14
|
+
*
|
|
15
|
+
* It used to throw `HttpsError` directly, which made the handler
|
|
16
|
+
* Firebase-shaped in its failures as well as its input — a caller running it
|
|
17
|
+
* behind anything else got an error carrying a callable protocol's vocabulary.
|
|
18
|
+
* `createClientLogFunction` converts these back, so a callable client sees
|
|
19
|
+
* exactly what it saw before.
|
|
20
|
+
*/
|
|
21
|
+
class ClientLogError extends Error {
|
|
22
|
+
code;
|
|
23
|
+
constructor(code, message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.name = 'ClientLogError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ClientLogError = ClientLogError;
|
|
11
30
|
/**
|
|
12
31
|
* Extract the bundle filename (e.g. "index-DnZ05f3M.js") from a frame URL.
|
|
13
32
|
*/
|
|
@@ -19,7 +38,7 @@ function bundleFileFromUrl(url) {
|
|
|
19
38
|
* Attempt to symbolicate a minified error stack trace using source maps.
|
|
20
39
|
* Loads source maps per-bundle so multiple chunks are handled correctly.
|
|
21
40
|
*/
|
|
22
|
-
async function symbolicateError(releaseId, error, bucketName) {
|
|
41
|
+
async function symbolicateError(releaseId, error, bucketName, prefix) {
|
|
23
42
|
if (!error?.stack)
|
|
24
43
|
return error;
|
|
25
44
|
try {
|
|
@@ -38,7 +57,7 @@ async function symbolicateError(releaseId, error, bucketName) {
|
|
|
38
57
|
// Load source map for each unique bundle (getSourceMap handles caching)
|
|
39
58
|
const sourceMaps = new Map();
|
|
40
59
|
await Promise.all(Array.from(bundleFiles).map(async (bundle) => {
|
|
41
|
-
const map = await (0, sourceMapCache_1.getSourceMap)(releaseId, bundle, bucketName);
|
|
60
|
+
const map = await (0, sourceMapCache_1.getSourceMap)(releaseId, bundle, bucketName, prefix);
|
|
42
61
|
if (map)
|
|
43
62
|
sourceMaps.set(bundle, map);
|
|
44
63
|
}));
|
|
@@ -69,17 +88,17 @@ function createClientLogHandler(config) {
|
|
|
69
88
|
return async (request) => {
|
|
70
89
|
const { message, severity, labels, jsonPayload } = request.data;
|
|
71
90
|
if (!message || !severity) {
|
|
72
|
-
throw new
|
|
91
|
+
throw new ClientLogError('invalid-argument', 'Missing message or severity');
|
|
73
92
|
}
|
|
74
93
|
if (!VALID_SEVERITIES.has(severity)) {
|
|
75
|
-
throw new
|
|
94
|
+
throw new ClientLogError('invalid-argument', `Invalid severity: ${severity}`);
|
|
76
95
|
}
|
|
77
96
|
const isEmulator = process.env.FUNCTIONS_EMULATOR === 'true';
|
|
78
97
|
try {
|
|
79
98
|
let processedError = jsonPayload?.error;
|
|
80
99
|
if (processedError?.stack && !isEmulator) {
|
|
81
100
|
const releaseId = labels?.releaseId ?? 'unknown';
|
|
82
|
-
processedError = await symbolicateError(releaseId, processedError, config.bucketName);
|
|
101
|
+
processedError = await symbolicateError(releaseId, processedError, config.sourceMaps?.bucket ?? config.bucketName, config.sourceMaps?.prefix);
|
|
83
102
|
}
|
|
84
103
|
(0, logger_1.writeLog)({
|
|
85
104
|
message,
|
|
@@ -91,7 +110,7 @@ function createClientLogHandler(config) {
|
|
|
91
110
|
}
|
|
92
111
|
catch (err) {
|
|
93
112
|
console.error('[fsl] Error processing client log:', err);
|
|
94
|
-
throw new
|
|
113
|
+
throw new ClientLogError('internal', 'Failed to process log');
|
|
95
114
|
}
|
|
96
115
|
};
|
|
97
116
|
}
|
|
@@ -103,6 +122,18 @@ function createClientLogHandler(config) {
|
|
|
103
122
|
* export const logFrontendEvent = createClientLogFunction({ bucketName: 'my-bucket' })
|
|
104
123
|
*/
|
|
105
124
|
function createClientLogFunction(config) {
|
|
106
|
-
|
|
125
|
+
const handler = createClientLogHandler(config);
|
|
126
|
+
return (0, https_1.onCall)({ cors: config.cors ?? true, maxInstances: config.maxInstances ?? 1 }, async (request) => {
|
|
127
|
+
try {
|
|
128
|
+
await handler(request);
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
// Convert back at the Firebase boundary, so a callable client sees the
|
|
132
|
+
// same error it always did.
|
|
133
|
+
if (err instanceof ClientLogError)
|
|
134
|
+
throw new https_1.HttpsError(err.code, err.message);
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
107
138
|
}
|
|
108
139
|
//# sourceMappingURL=logHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logHandler.js","sourceRoot":"","sources":["../../src/functions/logHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logHandler.js","sourceRoot":"","sources":["../../src/functions/logHandler.ts"],"names":[],"mappings":";;;AA6IA,wDAwCC;AASD,0DAiBC;AA/MD,uDAAgE;AAEhE,iDAA+C;AAC/C,qCAAgD;AAChD,qDAAyE;AACzE,+CA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AO,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAA;IAC9C,OAAO,IAAA,cAAM,EACX,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC,EAAE,EACrE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChB,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;QACxB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,uEAAuE;YACvE,4BAA4B;YAC5B,IAAI,GAAG,YAAY,cAAc;gBAAE,MAAM,IAAI,kBAAU,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;YAC9E,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC,CACF,CAAA;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/functions/logger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/functions/logger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAQ/D,eAAO,MAAM,YAAY,cAAc,CAAC;AAExC,UAAU,qBAAqB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAKD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAQ9D;AAoFD;;GAEG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM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ulid");
|
|
|
45
45
|
const severity_1 = require("../shared/severity");
|
|
46
46
|
const error_1 = require("../shared/error");
|
|
47
47
|
const sourceMapCache_1 = require("./sourceMapCache");
|
|
48
|
+
const paths_js_1 = require("../shared/paths.js");
|
|
49
|
+
const traceContext_1 = require("./traceContext");
|
|
48
50
|
const IS_EMULATOR = process.env.FUNCTIONS_EMULATOR === "true";
|
|
49
51
|
exports.LOG_FILENAME = "dev.jsonl";
|
|
50
52
|
let globalConfig = null;
|
|
@@ -102,15 +104,30 @@ function rotateLogFile(logDir, maxRotatedFiles) {
|
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
async function uploadLogAttachments(logId, logAttachments) {
|
|
105
|
-
const bucket = (0, sourceMapCache_1.
|
|
107
|
+
const bucket = (0, sourceMapCache_1.getAttachmentBucket)();
|
|
106
108
|
await Promise.all(Object.entries(logAttachments).map(async ([name, data]) => {
|
|
107
|
-
const file = bucket.file(
|
|
109
|
+
const file = bucket.file((0, paths_js_1.attachmentPath)(logId, name, (0, sourceMapCache_1.getAttachmentPrefix)()));
|
|
108
110
|
await file.save(Buffer.from(data, "base64"));
|
|
109
111
|
}));
|
|
110
112
|
}
|
|
113
|
+
// Warn once per bad value: writeLog is on the per-log path, and a caller with a
|
|
114
|
+
// broken severity will hit it every time.
|
|
115
|
+
const warnedSeverities = new Set();
|
|
116
|
+
function coerceUnknownSeverity(value) {
|
|
117
|
+
const shown = typeof value === "string" ? value : String(value);
|
|
118
|
+
if (!warnedSeverities.has(shown)) {
|
|
119
|
+
warnedSeverities.add(shown);
|
|
120
|
+
console.warn(`[fsl] Unknown severity ${JSON.stringify(shown)} — writing as ERROR. ` +
|
|
121
|
+
`Valid values: ${severity_1.SEVERITIES.join(", ")}.`);
|
|
122
|
+
}
|
|
123
|
+
return "ERROR";
|
|
124
|
+
}
|
|
111
125
|
const CONSOLE_FN = {
|
|
112
126
|
ERROR: console.error,
|
|
113
127
|
WARNING: console.warn,
|
|
128
|
+
// There is no console.notice. firebase-functions maps NOTICE to console.info
|
|
129
|
+
// on the production side, so match that rather than inventing a mapping.
|
|
130
|
+
NOTICE: console.info,
|
|
114
131
|
DEBUG: console.debug,
|
|
115
132
|
INFO: console.log,
|
|
116
133
|
};
|
|
@@ -132,9 +149,31 @@ function cleanLabels(labels) {
|
|
|
132
149
|
* Write a structured log entry. Transport depends on environment.
|
|
133
150
|
*/
|
|
134
151
|
function writeLog(payload) {
|
|
152
|
+
// An unrecognised severity is not merely mislabelled — it is fatal. Both
|
|
153
|
+
// dispatches look the value up in a fixed table: CONSOLE_FN below, and
|
|
154
|
+
// firebase-functions' own CONSOLE_SEVERITY inside ffWrite. A miss resolves to
|
|
155
|
+
// undefined and calling it throws, which Logger.send()'s catch then swallows,
|
|
156
|
+
// so the entry disappears with no useful diagnostic — and only in production,
|
|
157
|
+
// since the emulator takes the other branch.
|
|
158
|
+
//
|
|
159
|
+
// It also slips past the floor: SEVERITY_ORDER[unknown] is undefined, and
|
|
160
|
+
// `undefined > n` is false, so the check below would not have stopped it.
|
|
161
|
+
//
|
|
162
|
+
// writeLog is exported, so a caller can reach this with a value read from
|
|
163
|
+
// config, crossing a type boundary, or from plain JavaScript. Coerce to ERROR
|
|
164
|
+
// rather than drop: an entry arriving loud beats one vanishing quietly.
|
|
165
|
+
const severity = (0, severity_1.isLogSeverity)(payload.severity)
|
|
166
|
+
? payload.severity
|
|
167
|
+
: coerceUnknownSeverity(payload.severity);
|
|
168
|
+
// Feedback bypasses the floor. The client already bypassed its own, but the
|
|
169
|
+
// payload still passes through here on its way to Cloud Logging, and this
|
|
170
|
+
// floor defaults to WARNING in production — so without the exemption every
|
|
171
|
+
// report would be dropped here instead. Verified: it was.
|
|
135
172
|
const minSeverity = globalConfig?.minSeverity ?? (IS_EMULATOR ? "DEBUG" : "WARNING");
|
|
136
|
-
if (severity_1.
|
|
173
|
+
if (!(0, severity_1.isFeedback)(payload.labels) &&
|
|
174
|
+
severity_1.SEVERITY_ORDER[severity] > severity_1.SEVERITY_ORDER[minSeverity]) {
|
|
137
175
|
return;
|
|
176
|
+
}
|
|
138
177
|
const logId = (0, ulid_1.ulid)();
|
|
139
178
|
const hasAttachments = payload.attachments && Object.keys(payload.attachments).length > 0;
|
|
140
179
|
const labels = {
|
|
@@ -152,7 +191,7 @@ function writeLog(payload) {
|
|
|
152
191
|
try {
|
|
153
192
|
const entry = {
|
|
154
193
|
timestamp: new Date().toISOString(),
|
|
155
|
-
severity
|
|
194
|
+
severity,
|
|
156
195
|
message: payload.message,
|
|
157
196
|
labels,
|
|
158
197
|
jsonPayload: payload.jsonPayload,
|
|
@@ -176,7 +215,7 @@ function writeLog(payload) {
|
|
|
176
215
|
}
|
|
177
216
|
}
|
|
178
217
|
// Also write to console for immediate visibility
|
|
179
|
-
CONSOLE_FN[
|
|
218
|
+
CONSOLE_FN[severity](`[${severity}] ${payload.message}`, labels);
|
|
180
219
|
return;
|
|
181
220
|
}
|
|
182
221
|
// Production: use firebase-functions/logger write() directly, bypassing entryFromArgs.
|
|
@@ -189,11 +228,60 @@ function writeLog(payload) {
|
|
|
189
228
|
// not one of them, so it lands in jsonPayload.labels and `labels.appId="..."`
|
|
190
229
|
// filters match nothing. Verified live: the smoke run's entry labels contained only
|
|
191
230
|
// Cloud Functions' own platform labels until this changed.
|
|
231
|
+
// Cloud Error Reporting reads Cloud Logging and groups by exception type plus
|
|
232
|
+
// the five top-most frames — the fingerprint we would otherwise build. It
|
|
233
|
+
// looks for `stack_trace` at the TOP level of jsonPayload; ours lives one
|
|
234
|
+
// level down under `error`, so it has never been seen (#31).
|
|
235
|
+
//
|
|
236
|
+
// Moved, not duplicated. The stack is the largest field in an entry capped at
|
|
237
|
+
// 256 KB, and two copies of it buys nothing — so a reportable error carries its
|
|
238
|
+
// stack at `stack_trace` and its `error` object loses the `stack` key.
|
|
239
|
+
//
|
|
240
|
+
// A non-reportable entry keeps the stack where it was. It has to go somewhere,
|
|
241
|
+
// and the alternative — emitting `stack_trace` for warnings too — would likely
|
|
242
|
+
// turn every warning into something a person has to resolve in the Error
|
|
243
|
+
// Reporting console. The smoke run measures whether that is true; until it
|
|
244
|
+
// does, the cautious shape is the one that ships.
|
|
245
|
+
//
|
|
246
|
+
// ERROR and above only. A WARNING carrying a stack is not an error someone
|
|
247
|
+
// should have to resolve, and neither is a NOTICE feedback report — turning
|
|
248
|
+
// either into an Error Reporting group would be a regression of a deliberate
|
|
249
|
+
// product decision.
|
|
250
|
+
const stack = payload.jsonPayload?.error?.stack;
|
|
251
|
+
const reportable = stack && severity_1.SEVERITY_ORDER[severity] <= severity_1.SEVERITY_ORDER.ERROR && !(0, severity_1.isFeedback)(payload.labels);
|
|
252
|
+
const service = labels.appId ?? globalConfig?.appId;
|
|
253
|
+
const isReported = Boolean(reportable && service);
|
|
254
|
+
const errorReporting = isReported
|
|
255
|
+
? {
|
|
256
|
+
stack_trace: stack,
|
|
257
|
+
serviceContext: {
|
|
258
|
+
service: service,
|
|
259
|
+
...(labels.releaseId ? { version: labels.releaseId } : {}),
|
|
260
|
+
},
|
|
261
|
+
}
|
|
262
|
+
: {};
|
|
263
|
+
// Strip the now-redundant copy. Rebuilt rather than mutated: payload is the
|
|
264
|
+
// caller's object and writeLog has no business editing it.
|
|
265
|
+
const jsonPayload = isReported
|
|
266
|
+
? (() => {
|
|
267
|
+
const { error, ...rest } = payload.jsonPayload;
|
|
268
|
+
const { stack: _dropped, ...errorWithoutStack } = error;
|
|
269
|
+
return { ...rest, error: errorWithoutStack };
|
|
270
|
+
})()
|
|
271
|
+
: payload.jsonPayload;
|
|
272
|
+
// Set the trace ourselves when we have one. ffWrite attaches this from
|
|
273
|
+
// firebase-functions' own store, which is only populated inside their request
|
|
274
|
+
// wrapper — empty on Cloud Run and anything behind createHttpLogHandler. When
|
|
275
|
+
// theirs IS populated it overwrites this, which is the right precedence: inside
|
|
276
|
+
// Cloud Functions their value is authoritative.
|
|
277
|
+
const trace = (0, traceContext_1.traceResourceName)();
|
|
192
278
|
(0, logger_1.write)({
|
|
193
|
-
severity
|
|
279
|
+
severity,
|
|
194
280
|
message: payload.message,
|
|
195
281
|
"logging.googleapis.com/labels": labels,
|
|
196
|
-
...
|
|
282
|
+
...(trace ? { "logging.googleapis.com/trace": trace } : {}),
|
|
283
|
+
...errorReporting,
|
|
284
|
+
...jsonPayload,
|
|
197
285
|
});
|
|
198
286
|
}
|
|
199
287
|
function logAttachmentsToBase64(logAttachments) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/functions/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/functions/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,gCAQC;AAuFD,kCAWC;AAKD,4BAyJC;AAgBD,0CAyDC;AA9WD,uCAAyB;AACzB,2CAA6B;AAC7B,sDAA6D;AAC7D,+BAA4B;AAE5B,iDAA2F;AAC3F,2CAA0D;AAC1D,qDAA4E;AAC5E,iDAAoD;AACpD,iDAAmD;AAEnD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,CAAC;AACjD,QAAA,YAAY,GAAG,WAAW,CAAC;AAUxC,IAAI,YAAY,GAAiC,IAAI,CAAC;AACtD,IAAI,kBAAkB,GAAG,CAAC,CAAC;AAE3B;;;GAGG;AACH,SAAgB,UAAU,CAAC,MAA6B;IACtD,YAAY,GAAG,MAAM,CAAC;IACtB,kBAAkB,GAAG,CAAC,CAAC;IAEvB,IAAI,WAAW,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACtC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,aAAa,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,kBAAkB,IAAI,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EAC3C,OAAiC,EACjC,WAA6C;YAE7C,MAAM,KAAK,GAAG,IAAA,eAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,QAAQ,CAAC;gBACP,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,QAAQ,EAAE,OAAO;gBACjB,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC;gBACnD,WAAW,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,IAAA,sBAAc,EAAC,KAAK,CAAC,EAAE;gBACtD,WAAW,EAAE,sBAAsB,CAAC,WAAW,CAAC;aACjD,CAAC,CAAC;QACL,CAAC;QACD,IAAI,EAAE,CACJ,OAAe,EACf,MAA2C,EAC3C,OAAiC,EACjC,WAA6C,EACvC,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC;QAC/D,OAAO,EAAE,CACP,OAAe,EACf,MAA2C,EAC3C,OAAiC,EACjC,WAA6C,EACvC,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC;QAClE,KAAK,EAAE,CACL,OAAe,EACf,MAA2C,EAC3C,OAAiC,EACjC,WAA6C,EACvC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC;KACjE,CAAC;AACJ,CAAC"}
|
|
@@ -28,30 +28,12 @@ interface RequestLoggerOptions<AppLabels extends Record<string, string | undefin
|
|
|
28
28
|
* )
|
|
29
29
|
*/
|
|
30
30
|
export declare function withLogging<AppLabels extends Record<string, string | undefined> = Record<string, string | undefined>, Req extends CallableRequest = CallableRequest, Res = unknown>(options: RequestLoggerOptions<AppLabels> | ((request: Req) => RequestLoggerOptions<AppLabels>), handler: (request: Req) => Res | Promise<Res>): (request: Req) => Promise<Res>;
|
|
31
|
-
/**
|
|
32
|
-
* Initialize a request-scoped logger and store it in AsyncLocalStorage.
|
|
33
|
-
*
|
|
34
|
-
* @deprecated Use {@link withLogging}. This leaks the request scope: it binds
|
|
35
|
-
* with `AsyncLocalStorage.enterWith()`, which persists for the remainder of the
|
|
36
|
-
* execution context and is never unwound. The labels therefore outlive the
|
|
37
|
-
* request, and any later handler that does NOT call this — a scheduled
|
|
38
|
-
* function, a Firestore or Storage trigger, or anything relying on
|
|
39
|
-
* `getLogger()`'s anonymous fallback — inherits whichever user last touched the
|
|
40
|
-
* warm instance.
|
|
41
|
-
*
|
|
42
|
-
* Handlers that all call this are unaffected: each overwrites the store with
|
|
43
|
-
* its own labels. The hazard is the handlers that do not.
|
|
44
|
-
*
|
|
45
|
-
* Removed in 0.6.0.
|
|
46
|
-
*/
|
|
47
|
-
export declare function initRequestLogger<AppLabels extends Record<string, string | undefined> = Record<string, string | undefined>>(request: CallableRequest, extra?: RequestLoggerOptions<AppLabels>): LogWriter;
|
|
48
31
|
/**
|
|
49
32
|
* Retrieve the request-scoped logger.
|
|
50
33
|
*
|
|
51
34
|
* Returns an anonymous writer (no request labels) when called outside a
|
|
52
|
-
* request.
|
|
53
|
-
*
|
|
54
|
-
* request's writer can still be in scope here.
|
|
35
|
+
* request. `withLogging` unwinds the scope when a handler settles, so this is
|
|
36
|
+
* genuinely anonymous rather than whatever ran last.
|
|
55
37
|
*/
|
|
56
38
|
export declare function getLogger(): LogWriter;
|
|
57
39
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestLogger.d.ts","sourceRoot":"","sources":["../../src/functions/requestLogger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAgC,KAAK,SAAS,EAAE,MAAM,UAAU,CAAA;AAIvE,UAAU,oBAAoB,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACjF,YA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AC,EACzF,GAAG,SAAS,eAAe,GAAG,eAAe,EAC7C,GAAG,GAAG,OAAO,EAEb,OAAO,EACH,oBAAoB,CAAC,SAAS,CAAC,GAC/B,CAAC,CAAC,OAAO,EAAE,GAAG,KAAK,oBAAoB,CAAC,SAAS,CAAC,CAAC,EACvD,OAAO,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAC5C,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAMhC;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,IAAI,SAAS,CAErC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withLogging = withLogging;
|
|
4
|
-
exports.initRequestLogger = initRequestLogger;
|
|
5
4
|
exports.getLogger = getLogger;
|
|
6
5
|
const async_hooks_1 = require("async_hooks");
|
|
7
6
|
const logger_1 = require("./logger");
|
|
@@ -43,48 +42,12 @@ function withLogging(options, handler) {
|
|
|
43
42
|
return storage.run(writer, async () => handler(request));
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
|
-
/**
|
|
47
|
-
* Initialize a request-scoped logger and store it in AsyncLocalStorage.
|
|
48
|
-
*
|
|
49
|
-
* @deprecated Use {@link withLogging}. This leaks the request scope: it binds
|
|
50
|
-
* with `AsyncLocalStorage.enterWith()`, which persists for the remainder of the
|
|
51
|
-
* execution context and is never unwound. The labels therefore outlive the
|
|
52
|
-
* request, and any later handler that does NOT call this — a scheduled
|
|
53
|
-
* function, a Firestore or Storage trigger, or anything relying on
|
|
54
|
-
* `getLogger()`'s anonymous fallback — inherits whichever user last touched the
|
|
55
|
-
* warm instance.
|
|
56
|
-
*
|
|
57
|
-
* Handlers that all call this are unaffected: each overwrites the store with
|
|
58
|
-
* its own labels. The hazard is the handlers that do not.
|
|
59
|
-
*
|
|
60
|
-
* Removed in 0.6.0.
|
|
61
|
-
*/
|
|
62
|
-
function initRequestLogger(request, extra) {
|
|
63
|
-
warnDeprecated(extra?.functionName);
|
|
64
|
-
const writer = writerFor(request, extra);
|
|
65
|
-
storage.enterWith(writer);
|
|
66
|
-
return writer;
|
|
67
|
-
}
|
|
68
|
-
// Warn once per function name rather than per invocation — a per-request warning
|
|
69
|
-
// on a hot path is noise that gets filtered out and then ignored.
|
|
70
|
-
const warned = new Set();
|
|
71
|
-
function warnDeprecated(functionName) {
|
|
72
|
-
const key = functionName ?? '(unnamed)';
|
|
73
|
-
if (warned.has(key))
|
|
74
|
-
return;
|
|
75
|
-
warned.add(key);
|
|
76
|
-
console.warn(`[fsl] initRequestLogger() is deprecated (${key}). It binds the request scope with ` +
|
|
77
|
-
'enterWith(), which is never unwound — the labels outlive the request, so a later ' +
|
|
78
|
-
'handler that does not call it inherits this request\'s userId. Wrap the handler ' +
|
|
79
|
-
'with withLogging() instead. Removed in 0.6.0.');
|
|
80
|
-
}
|
|
81
45
|
/**
|
|
82
46
|
* Retrieve the request-scoped logger.
|
|
83
47
|
*
|
|
84
48
|
* Returns an anonymous writer (no request labels) when called outside a
|
|
85
|
-
* request.
|
|
86
|
-
*
|
|
87
|
-
* request's writer can still be in scope here.
|
|
49
|
+
* request. `withLogging` unwinds the scope when a handler settles, so this is
|
|
50
|
+
* genuinely anonymous rather than whatever ran last.
|
|
88
51
|
*/
|
|
89
52
|
function getLogger() {
|
|
90
53
|
return storage.getStore() ?? (0, logger_1.createLogWriter)({});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestLogger.js","sourceRoot":"","sources":["../../src/functions/requestLogger.ts"],"names":[],"mappings":";;AAgDA,kCAeC;
|
|
1
|
+
{"version":3,"file":"requestLogger.js","sourceRoot":"","sources":["../../src/functions/requestLogger.ts"],"names":[],"mappings":";;AAgDA,kCAeC;AASD,8BAEC;AA1ED,6CAA+C;AAE/C,qCAAuE;AAEvE,MAAM,OAAO,GAAG,IAAI,+BAAiB,EAAa,CAAA;AAQlD,SAAS,SAAS,CAChB,OAAwB,EACxB,KAAuC;IAEvC,OAAO,IAAA,wBAAe,EACpB,IAAA,oBAAW,EAAC;QACV,YAAY,EAAE,KAAK,EAAE,YAAY;QACjC,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG;QACzB,KAAK,EAAE,KAAK,EAAE,KAAK;QACnB,GAAG,KAAK,EAAE,MAAM;KACjB,CAAC,CACH,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,WAAW,CAKzB,OAEuD,EACvD,OAA6C;IAE7C,OAAO,CAAC,OAAY,EAAE,EAAE;QACtB,MAAM,QAAQ,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QAC3E,MAAM,MAAM,GAAG,SAAS,CAAY,OAAO,EAAE,QAAQ,CAAC,CAAA;QACtD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IAC1D,CAAC,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS;IACvB,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,IAAA,wBAAe,EAAC,EAAE,CAAC,CAAA;AAClD,CAAC"}
|
|
@@ -20,6 +20,30 @@ export declare const __cacheForTests: {
|
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
export declare function configureSourceMapBucket(bucketName: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Where attachments are written.
|
|
25
|
+
*
|
|
26
|
+
* Global on purpose, and global in the API so the shape does not lie. The
|
|
27
|
+
* upload happens in `writeLog`, which is reached from every log call — including
|
|
28
|
+
* `logError()` inside a handler that never went through `createClientLogHandler`
|
|
29
|
+
* — so there is no per-instance config for it to read. Accepting this as a field
|
|
30
|
+
* on the handler would let a second handler silently retarget the first's
|
|
31
|
+
* attachments, which is the module-scoped-state trap in CLAUDE.md.
|
|
32
|
+
*
|
|
33
|
+
* Unset fields keep today's behaviour: the bucket falls back to
|
|
34
|
+
* `configureSourceMapBucket`'s value and then to the project default, and the
|
|
35
|
+
* prefix to `logAttachments/`. Never calling this changes nothing.
|
|
36
|
+
*/
|
|
37
|
+
export declare function configureAttachments(options: {
|
|
38
|
+
bucket?: string;
|
|
39
|
+
prefix?: string;
|
|
40
|
+
}): void;
|
|
41
|
+
/** Bucket for attachments: explicit, then the source-map bucket, then the project default. */
|
|
42
|
+
export declare function getAttachmentBucket(): Bucket;
|
|
43
|
+
/** Prefix for attachments, defaulting to the documented one. */
|
|
44
|
+
export declare function getAttachmentPrefix(): string | undefined;
|
|
45
|
+
/** Reset attachment config. Tests only — production configures once at module load. */
|
|
46
|
+
export declare function resetAttachmentConfig(): void;
|
|
23
47
|
/**
|
|
24
48
|
* Resolve the configured Storage bucket, falling back to the project default.
|
|
25
49
|
*
|
|
@@ -49,7 +73,9 @@ export declare function getBucket(bucketName?: string | undefined): Bucket;
|
|
|
49
73
|
* That is strictly better than preferring embedded in every case, and it leaves
|
|
50
74
|
* the unversioned setup working exactly as before.
|
|
51
75
|
*/
|
|
52
|
-
export declare function getSourceMap(releaseId: string, fileName: string, bucketName?: string): Promise<EncodedSourceMap | null>;
|
|
76
|
+
export declare function getSourceMap(releaseId: string, fileName: string, bucketName?: string, prefix?: string): Promise<EncodedSourceMap | null>;
|
|
77
|
+
/** Reset the warn-once sets. Tests only. */
|
|
78
|
+
export declare function resetSourceMapWarnings(): void;
|
|
53
79
|
export declare function clearSourceMapCache(): void;
|
|
54
80
|
export {};
|
|
55
81
|
//# sourceMappingURL=sourceMapCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourceMapCache.d.ts","sourceRoot":"","sources":["../../src/functions/sourceMapCache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"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