@forge/bundler 4.4.0 → 4.5.0-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @forge/bundler
2
2
 
3
+ ## 4.5.0-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [20c8fc14]
8
+ - Updated dependencies [272a7845]
9
+ - Updated dependencies [986ad5d5]
10
+ - @forge/runtime@4.2.0-next.1
11
+ - @forge/cli-shared@3.6.1-next.0
12
+ - @forge/lint@3.2.15-next.0
13
+
14
+ ## 4.5.0-next.0
15
+
16
+ ### Minor Changes
17
+
18
+ - a90c1412: Include Forge log header in log lines, for xen-logs-ingestor to have complete data when it processes log line events
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [18d686e4]
23
+ - Updated dependencies [a90c1412]
24
+ - @forge/runtime@4.2.0-next.0
25
+
3
26
  ## 4.4.0
4
27
 
5
28
  ### Minor Changes
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- import { ConsoleMethod } from '@forge/runtime';
1
+ import { ConsoleMethod, LogHeader } from '@forge/runtime';
3
2
  export declare const starSerializer: (arg: any) => any;
4
- export declare const forgeConsole: Pick<Console, ConsoleMethod>;
3
+ export declare function forgeConsole(consoleMethod: ConsoleMethod, header: LogHeader): (...rawData: any[]) => void;
5
4
  //# sourceMappingURL=console.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/stubs/console.ts"],"names":[],"mappings":";AAEA,OAAO,EAAsB,aAAa,EAA+B,MAAM,gBAAgB,CAAC;AAyChG,eAAO,MAAM,cAAc,QAAS,GAAG,KAAG,GAsBzC,CAAC;AAgDF,eAAO,MAAM,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,CAMrD,CAAC"}
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/stubs/console.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,aAAa,EAIb,SAAS,EAEV,MAAM,gBAAgB,CAAC;AA2CxB,eAAO,MAAM,cAAc,QAAS,GAAG,KAAG,GA0BzC,CAAC;AAkDF,wBAAgB,YAAY,CAAC,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,+BAW3E"}
@@ -59,9 +59,9 @@ exports.starSerializer = starSerializer;
59
59
  function formatLogMessage(requestId, logEventData) {
60
60
  const transformedMessage = transformSandBoxLogMessage(logEventData.logArguments);
61
61
  return {
62
- msg: transformedMessage.msg,
63
- id: requestId,
64
62
  type: 'log',
63
+ id: requestId,
64
+ msg: transformedMessage.msg,
65
65
  P: 3,
66
66
  ts: Date.now(),
67
67
  lvl: logEventData.logLevel,
@@ -73,7 +73,7 @@ const logger = (0, bunyan_1.createLogger)({
73
73
  level: bunyan_1.levelFromName.info,
74
74
  serializers: { '*': exports.starSerializer }
75
75
  });
76
- function customConsole(logMethod) {
76
+ function customConsole(logMethod, header) {
77
77
  return (...rawData) => {
78
78
  var _a;
79
79
  const runtime = (0, api_1.getRuntime)();
@@ -88,16 +88,21 @@ function customConsole(logMethod) {
88
88
  process.stdout.write(JSON.stringify((0, exports.starSerializer)(logEventData)) + '\n');
89
89
  }
90
90
  else {
91
- const data = formatLogMessage(awsRequestId, logEventData);
92
- logger.info(data, data.msg);
91
+ const logLine = formatLogMessage(awsRequestId, logEventData);
92
+ const headedLogLine = Object.assign(Object.assign({}, header), logLine);
93
+ logger.info(headedLogLine, logLine.msg);
93
94
  }
94
95
  }
95
96
  };
96
97
  }
97
- exports.forgeConsole = {
98
- log: customConsole('info'),
99
- info: customConsole('info'),
100
- warn: customConsole('warn'),
101
- debug: customConsole('debug'),
102
- error: customConsole('error')
103
- };
98
+ function forgeConsole(consoleMethod, header) {
99
+ switch (consoleMethod) {
100
+ case 'debug':
101
+ case 'warn':
102
+ case 'error':
103
+ return customConsole(consoleMethod, header);
104
+ default:
105
+ return customConsole('info', header);
106
+ }
107
+ }
108
+ exports.forgeConsole = forgeConsole;
@@ -0,0 +1,30 @@
1
+ export declare const AWS_EXECUTION_ENV_PREFIX = "AWS_Lambda_";
2
+ export declare const RUNTIME_NAME_FALLBACK = "node";
3
+ export declare function getRuntimeName(): string;
4
+ declare enum EventType {
5
+ HEADER = "header",
6
+ FOOTER = "footer",
7
+ LOG = "log"
8
+ }
9
+ export declare function emitHeaderEvent(lambdaEvent: any): {
10
+ type: EventType;
11
+ id: string;
12
+ time: string;
13
+ };
14
+ export declare function emitSuccessfulFooterEvent(): {
15
+ type: EventType;
16
+ id: string;
17
+ time: string;
18
+ };
19
+ export declare function emitFailedFooterEvent(): {
20
+ type: EventType;
21
+ id: string;
22
+ time: string;
23
+ };
24
+ export declare function emitErrorEvent(caughtObject: any): {
25
+ type: EventType;
26
+ id: string;
27
+ time: string;
28
+ };
29
+ export {};
30
+ //# sourceMappingURL=log-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-events.d.ts","sourceRoot":"","sources":["../../src/stubs/log-events.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,wBAAwB,gBAAgB,CAAC;AACtD,eAAO,MAAM,qBAAqB,SAAS,CAAC;AAE5C,wBAAgB,cAAc,IAAI,MAAM,CAavC;AA4CD,aAAK,SAAS;IACZ,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,GAAG,QAAQ;CACZ;AA8BD,wBAAgB,eAAe,CAAC,WAAW,EAAE,GAAG;;;;EAE/C;AAED,wBAAgB,yBAAyB;;;;EAExC;AAED,wBAAgB,qBAAqB;;;;EAEpC;AAED,wBAAgB,cAAc,CAAC,YAAY,EAAE,GAAG;;;;EAE/C"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitErrorEvent = exports.emitFailedFooterEvent = exports.emitSuccessfulFooterEvent = exports.emitHeaderEvent = exports.getRuntimeName = exports.RUNTIME_NAME_FALLBACK = exports.AWS_EXECUTION_ENV_PREFIX = void 0;
4
+ const api_1 = require("@forge/api");
5
+ const bunyan_1 = require("bunyan");
6
+ const console_1 = require("./console");
7
+ exports.AWS_EXECUTION_ENV_PREFIX = 'AWS_Lambda_';
8
+ exports.RUNTIME_NAME_FALLBACK = 'node';
9
+ function getRuntimeName() {
10
+ const awsRuntime = process.env.AWS_EXECUTION_ENV;
11
+ if (!awsRuntime) {
12
+ return exports.RUNTIME_NAME_FALLBACK;
13
+ }
14
+ if (awsRuntime.startsWith(exports.AWS_EXECUTION_ENV_PREFIX)) {
15
+ return awsRuntime.substring(exports.AWS_EXECUTION_ENV_PREFIX.length);
16
+ }
17
+ return awsRuntime;
18
+ }
19
+ exports.getRuntimeName = getRuntimeName;
20
+ function invocationHeaderLogs(lambdaEvent) {
21
+ const { featureFlags, contextAri, appContext, tracing } = lambdaEvent === null || lambdaEvent === void 0 ? void 0 : lambdaEvent._meta;
22
+ const { appId, environmentId, appVersion, functionKey, moduleKey, moduleType } = appContext !== null && appContext !== void 0 ? appContext : {};
23
+ return {
24
+ appId,
25
+ environmentId,
26
+ appVersion,
27
+ installationContext: contextAri,
28
+ functionKey,
29
+ moduleType,
30
+ moduleKey,
31
+ b3: `${tracing.traceId}-${tracing.spanId}`,
32
+ featureFlags: featureFlags || [],
33
+ runtime: getRuntimeName()
34
+ };
35
+ }
36
+ function invocationFooterLogs(successfulInvocation) {
37
+ return {
38
+ success: successfulInvocation,
39
+ logMetadata: {
40
+ bytes: 0,
41
+ truncated: false,
42
+ errorCount: 0
43
+ },
44
+ outboundCalls: {
45
+ count: 0,
46
+ stargateCount: 0,
47
+ externalCount: 0,
48
+ rejectedCount: 0,
49
+ bytesOut: 0,
50
+ bytesIn: 0,
51
+ msWaiting: 0
52
+ },
53
+ function: {
54
+ bytesIn: 0,
55
+ bytesOut: 0,
56
+ durationMs: 0,
57
+ mem: 0
58
+ }
59
+ };
60
+ }
61
+ var EventType;
62
+ (function (EventType) {
63
+ EventType["HEADER"] = "header";
64
+ EventType["FOOTER"] = "footer";
65
+ EventType["LOG"] = "log";
66
+ })(EventType || (EventType = {}));
67
+ function simpleBunyanLogEvent(eventType, eventLevel, data) {
68
+ function groupLogData(logData) {
69
+ if (eventType === 'footer' || eventType === 'header') {
70
+ return logData;
71
+ }
72
+ return {
73
+ '*': [(0, console_1.starSerializer)(logData)],
74
+ P: 3,
75
+ lvl: eventLevel,
76
+ ts: Date.now()
77
+ };
78
+ }
79
+ const invocationId = (0, api_1.getRuntime)().lambdaContext.awsRequestId;
80
+ const logEvent = Object.assign({ type: eventType, id: invocationId, time: new Date().toISOString() }, groupLogData(data));
81
+ process.stdout.write(JSON.stringify(logEvent) + '\n');
82
+ return logEvent;
83
+ }
84
+ function emitHeaderEvent(lambdaEvent) {
85
+ return simpleBunyanLogEvent(EventType.HEADER, bunyan_1.levelFromName.info, invocationHeaderLogs(lambdaEvent));
86
+ }
87
+ exports.emitHeaderEvent = emitHeaderEvent;
88
+ function emitSuccessfulFooterEvent() {
89
+ return simpleBunyanLogEvent(EventType.FOOTER, bunyan_1.levelFromName.info, invocationFooterLogs(true));
90
+ }
91
+ exports.emitSuccessfulFooterEvent = emitSuccessfulFooterEvent;
92
+ function emitFailedFooterEvent() {
93
+ return simpleBunyanLogEvent(EventType.FOOTER, bunyan_1.levelFromName.info, invocationFooterLogs(false));
94
+ }
95
+ exports.emitFailedFooterEvent = emitFailedFooterEvent;
96
+ function emitErrorEvent(caughtObject) {
97
+ return simpleBunyanLogEvent(EventType.LOG, bunyan_1.levelFromName.error, caughtObject);
98
+ }
99
+ exports.emitErrorEvent = emitErrorEvent;
@@ -1,88 +1,10 @@
1
1
  "use strict";
2
2
  var _a, _b;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- const bunyan_1 = require("bunyan");
5
4
  const api_1 = require("@forge/api");
6
5
  const runtime_1 = require("@forge/runtime");
7
6
  const console_1 = require("./console");
8
- for (const method of runtime_1.CONSOLE_METHODS) {
9
- global.console[method] = console_1.forgeConsole[method];
10
- }
11
- function invocationHeaderLogs(lambdaEvent) {
12
- const { featureFlags, contextAri, appContext, tracing } = lambdaEvent === null || lambdaEvent === void 0 ? void 0 : lambdaEvent._meta;
13
- const { appId, environmentId, appVersion, functionKey, moduleKey, moduleType } = appContext !== null && appContext !== void 0 ? appContext : {};
14
- return {
15
- appId,
16
- environmentId,
17
- appVersion,
18
- installationContext: contextAri,
19
- functionKey,
20
- moduleType,
21
- moduleKey,
22
- b3: `${tracing.traceId}-${tracing.spanId}`,
23
- featureFlags: featureFlags || [],
24
- runtime: 'banana'
25
- };
26
- }
27
- function invocationFooterLogs(successfulInvocation) {
28
- return {
29
- success: successfulInvocation,
30
- logMetadata: {
31
- bytes: 0,
32
- truncated: false,
33
- errorCount: 0
34
- },
35
- outboundCalls: {
36
- count: 0,
37
- stargateCount: 0,
38
- externalCount: 0,
39
- rejectedCount: 0,
40
- bytesOut: 0,
41
- bytesIn: 0,
42
- msWaiting: 0
43
- },
44
- function: {
45
- bytesIn: 0,
46
- bytesOut: 0,
47
- durationMs: 0,
48
- mem: 0
49
- }
50
- };
51
- }
52
- var EventType;
53
- (function (EventType) {
54
- EventType["HEADER"] = "header";
55
- EventType["FOOTER"] = "footer";
56
- EventType["LOG"] = "log";
57
- })(EventType || (EventType = {}));
58
- function simpleBunyanLogEvent(eventType, eventLevel, data) {
59
- function groupLogData(logData) {
60
- if (eventType === 'footer' || eventType === 'header') {
61
- return logData;
62
- }
63
- return {
64
- '*': [(0, console_1.starSerializer)(logData)],
65
- P: 3,
66
- lvl: eventLevel,
67
- ts: Date.now()
68
- };
69
- }
70
- const invocationId = (0, api_1.getRuntime)().lambdaContext.awsRequestId;
71
- const logEvent = Object.assign({ name: 'node-runtime', id: invocationId, hostname: 'some-runtime-hostname', pid: process.pid, level: 30, msg: '', time: new Date().toISOString(), v: 0, type: eventType }, groupLogData(data));
72
- process.stdout.write(JSON.stringify(logEvent) + '\n');
73
- }
74
- function emitHeaderEvent(lambdaEvent) {
75
- simpleBunyanLogEvent(EventType.HEADER, bunyan_1.levelFromName.info, invocationHeaderLogs(lambdaEvent));
76
- }
77
- function emitSuccessfulFooterEvent() {
78
- simpleBunyanLogEvent(EventType.FOOTER, bunyan_1.levelFromName.info, invocationFooterLogs(true));
79
- }
80
- function emitFailedFooterEvent() {
81
- simpleBunyanLogEvent(EventType.FOOTER, bunyan_1.levelFromName.info, invocationFooterLogs(false));
82
- }
83
- function emitErrorEvent(caughtObject) {
84
- simpleBunyanLogEvent(EventType.LOG, bunyan_1.levelFromName.error, caughtObject);
85
- }
7
+ const log_events_1 = require("./log-events");
86
8
  const wrappedFilename = __filename.replace(/\/[^/]+.js$/, (name) => '/bundled' + name);
87
9
  const realRequire = eval('require');
88
10
  if (!realRequire) {
@@ -108,10 +30,13 @@ const adapter = (name) => {
108
30
  process.env[key] = value;
109
31
  }
110
32
  try {
111
- emitHeaderEvent(lambdaEvent);
33
+ const header = (0, log_events_1.emitHeaderEvent)(lambdaEvent);
34
+ for (const method of runtime_1.CONSOLE_METHODS) {
35
+ global.console[method] = (0, console_1.forgeConsole)(method, header);
36
+ }
112
37
  const bundled = realRequire(wrappedFilename);
113
38
  const result = await bundled[name](event, context);
114
- emitSuccessfulFooterEvent();
39
+ (0, log_events_1.emitSuccessfulFooterEvent)();
115
40
  return {
116
41
  success: true,
117
42
  body: result,
@@ -119,8 +44,8 @@ const adapter = (name) => {
119
44
  };
120
45
  }
121
46
  catch (err) {
122
- emitErrorEvent(err);
123
- emitFailedFooterEvent();
47
+ (0, log_events_1.emitErrorEvent)(err);
48
+ (0, log_events_1.emitFailedFooterEvent)();
124
49
  const errorName = (0, api_1.isForgePlatformError)(err) ? err.name : api_1.FUNCTION_ERR;
125
50
  return {
126
51
  success: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/bundler",
3
- "version": "4.4.0",
3
+ "version": "4.5.0-next.1",
4
4
  "description": "Default bundler for Forge apps",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Atlassian",
@@ -20,9 +20,9 @@
20
20
  "@babel/preset-typescript": "^7.16.7",
21
21
  "@forge/api": "2.11.0",
22
22
  "@forge/babel-plugin-transform-ui": "1.1.0",
23
- "@forge/cli-shared": "3.6.0",
24
- "@forge/lint": "3.2.14",
25
- "@forge/runtime": "4.1.0",
23
+ "@forge/cli-shared": "3.6.1-next.0",
24
+ "@forge/lint": "3.2.15-next.0",
25
+ "@forge/runtime": "4.2.0-next.1",
26
26
  "@forge/util": "1.2.0",
27
27
  "assert": "^1.1.1",
28
28
  "babel-loader": "^8.2.3",