Skip to content

Commit caeb916

Browse files
authored
chore: Deprecate ActivityInboundLogInterceptor (#1284)
1 parent 3088f86 commit caeb916

22 files changed

+468
-281
lines changed

packages/activity/src/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,17 @@ export class Context {
253253
/**
254254
* The logger for this Activity.
255255
*
256-
* This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). If the {@link ActivityInboundLogInterceptor}
257-
* is installed (by default, it is; see {@link WorkerOptions.interceptors}), then various attributes from the current
258-
* Activity context will automatically be included as metadata on every log entries, and some key events of the
259-
* Activity's life cycle will automatically be logged (at 'DEBUG' level for most messages; 'WARN' for failures).
256+
* This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
257+
* will automatically be included as metadata on every log entries, and some key events of the Activity's lifecycle
258+
* will automatically be logged (at 'DEBUG' level for most messages; 'WARN' for failures).
260259
*
261-
* To use a different Logger, either overwrite this property from an Activity Interceptor, or explicitly register the
262-
* `ActivityInboundLogInterceptor` with your custom Logger. You may also subclass `ActivityInboundLogInterceptor` to
263-
* customize attributes that are emitted as metadata.
260+
* To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
261+
* `getLogAttributes()` method.
262+
*
263+
* Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
264+
* with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
265+
* through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
266+
* {@link Runtime.logger} property instead.
264267
*/
265268
public log: Logger;
266269

@@ -274,13 +277,13 @@ export class Context {
274277
cancelled: Promise<never>,
275278
cancellationSignal: AbortSignal,
276279
heartbeat: (details?: any) => void,
277-
logger: Logger
280+
log: Logger
278281
) {
279282
this.info = info;
280283
this.cancelled = cancelled;
281284
this.cancellationSignal = cancellationSignal;
282285
this.heartbeatFn = heartbeat;
283-
this.log = logger;
286+
this.log = log;
284287
}
285288

286289
/**

packages/common/src/converter/failure-converter.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,42 @@ import {
1515
import { isError } from '../type-helpers';
1616
import { arrayFromPayloads, fromPayloadsAtIndex, PayloadConverter, toPayloads } from './payload-converter';
1717

18+
function combineRegExp(...regexps: RegExp[]): RegExp {
19+
return new RegExp(regexps.map((x) => `(?:${x.source})`).join('|'));
20+
}
21+
1822
/**
1923
* Stack traces will be cutoff when on of these patterns is matched
2024
*/
21-
const CUTOFF_STACK_PATTERNS = [
25+
const CUTOFF_STACK_PATTERNS = combineRegExp(
2226
/** Activity execution */
2327
/\s+at Activity\.execute \(.*[\\/]worker[\\/](?:src|lib)[\\/]activity\.[jt]s:\d+:\d+\)/,
2428
/** Workflow activation */
2529
/\s+at Activator\.\S+NextHandler \(.*[\\/]workflow[\\/](?:src|lib)[\\/]internals\.[jt]s:\d+:\d+\)/,
2630
/** Workflow run anything in context */
27-
/\s+at Script\.runInContext \((?:node:vm|vm\.js):\d+:\d+\)/,
28-
];
31+
/\s+at Script\.runInContext \((?:node:vm|vm\.js):\d+:\d+\)/
32+
);
33+
34+
/**
35+
* Any stack trace frames that match any of those wil be dopped.
36+
* The "null." prefix on some cases is to avoid https://github.com/nodejs/node/issues/42417
37+
*/
38+
const DROPPED_STACK_FRAMES_PATTERNS = combineRegExp(
39+
/** Internal functions used to recursively chain interceptors */
40+
/\s+at (null\.)?next \(.*[\\/]common[\\/](?:src|lib)[\\/]interceptors\.[jt]s:\d+:\d+\)/,
41+
/** Internal functions used to recursively chain interceptors */
42+
/\s+at (null\.)?executeNextHandler \(.*[\\/]worker[\\/](?:src|lib)[\\/]activity\.[jt]s:\d+:\d+\)/
43+
);
2944

3045
/**
3146
* Cuts out the framework part of a stack trace, leaving only user code entries
3247
*/
3348
export function cutoffStackTrace(stack?: string): string {
3449
const lines = (stack ?? '').split(/\r?\n/);
3550
const acc = Array<string>();
36-
lineLoop: for (const line of lines) {
37-
for (const pattern of CUTOFF_STACK_PATTERNS) {
38-
if (pattern.test(line)) break lineLoop;
39-
}
40-
acc.push(line);
51+
for (const line of lines) {
52+
if (CUTOFF_STACK_PATTERNS.test(line)) break;
53+
if (!DROPPED_STACK_FRAMES_PATTERNS.test(line)) acc.push(line);
4154
}
4255
return acc.join('\n');
4356
}

packages/common/src/interceptors.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export type Next<IF, FN extends keyof IF> = Required<IF>[FN] extends AnyFunc ? O
1212
export type Headers = Record<string, Payload>;
1313

1414
/**
15-
* Composes all interceptor methods into a single function
15+
* Compose all interceptor methods into a single function.
16+
*
17+
* Calling the composed function results in calling each of the provided interceptor, in order (from the first to
18+
* the last), followed by the original function provided as argument to `composeInterceptors()`.
1619
*
1720
* @param interceptors a list of interceptors
1821
* @param method the name of the interceptor method to compose

packages/test/src/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export function cleanStackTrace(ostack: string): string {
5252
.replace(/:\d+:\d+/g, '')
5353
.replace(/^\s*/gms, ' at ')
5454
.replace(/\[as fn\] /, '')
55+
// Avoid https://github.com/nodejs/node/issues/42417
56+
.replace(/at null\./g, 'at ')
5557
.replace(/\\/g, '/');
5658

5759
return normalizedStack ? `${firstLine}\n${normalizedStack}` : firstLine;

packages/test/src/integration-tests.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
WorkflowNotFoundError,
3535
} from '@temporalio/common';
3636
import { msToNumber, tsToMs } from '@temporalio/common/lib/time';
37-
import { decode, decodeFromPayloadsAtIndex, loadDataConverter } from '@temporalio/common/lib/internal-non-workflow';
37+
import { decode, decodeFromPayloadsAtIndex } from '@temporalio/common/lib/internal-non-workflow';
3838
import * as iface from '@temporalio/proto';
3939
import { appendDefaultInterceptors, DefaultLogger, makeTelemetryFilterString, Runtime } from '@temporalio/worker';
4040
import pkg from '@temporalio/worker/lib/pkg';
@@ -96,7 +96,7 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
9696
taskQueue: 'test',
9797
dataConverter,
9898
interceptors: appendDefaultInterceptors({
99-
activityInbound: [() => new ConnectionInjectorInterceptor(connection, loadDataConverter(dataConverter))],
99+
activity: [() => ({ inbound: new ConnectionInjectorInterceptor(connection, loadedDataConverter) })],
100100
}),
101101
showStackTraceSources: true,
102102
});
@@ -222,7 +222,8 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
222222
cleanOptionalStackTrace(err.cause.cause.stack),
223223
dedent`
224224
Error: Fail me
225-
at Activity.throwAnError (test/src/activities/index.ts)
225+
at throwAnError (test/src/activities/index.ts)
226+
at ConnectionInjectorInterceptor.execute (test/src/activities/interceptors.ts)
226227
`
227228
);
228229
});
@@ -256,7 +257,8 @@ export function runIntegrationTests(codec?: PayloadCodec): void {
256257
dedent`
257258
ApplicationFailure: Fail me
258259
at Function.nonRetryable (common/src/failure.ts)
259-
at Activity.throwAnError (test/src/activities/index.ts)
260+
at throwAnError (test/src/activities/index.ts)
261+
at ConnectionInjectorInterceptor.execute (test/src/activities/interceptors.ts)
260262
`
261263
);
262264
});

packages/test/src/load/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ async function main() {
182182
maxConcurrentActivityTaskPolls,
183183
maxConcurrentWorkflowTaskPolls,
184184
interceptors: {
185-
activityInbound: [() => new ConnectionInjectorInterceptor(clientConnection)],
185+
activity: [() => ({ inbound: new ConnectionInjectorInterceptor(clientConnection) })],
186186
},
187187
// Can't reuse the helper because it defines `test` and ava thinks it's an ava test.
188188
reuseV8Context: ['1', 't', 'true'].includes((process.env.REUSE_V8_CONTEXT ?? 'false').toLowerCase()),

0 commit comments

Comments
 (0)