@outputai/core 0.16.0 → 0.16.1-next.a116929.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/package.json +1 -1
- package/src/consts.js +4 -3
- package/src/hooks/index.js +1 -1
- package/src/interface/logger.js +4 -4
- package/src/llm/utils/models_pricing_snapshot.json +1 -1
- package/src/worker/configs.js +40 -11
- package/src/worker/global_functions.js +11 -6
- package/src/worker/index.js +27 -9
- package/src/worker/log_hooks.js +8 -0
- package/src/worker/shutdown.js +5 -11
- package/src/worker/temporal_logger.js +45 -12
- package/src/worker/worker_options.js +4 -4
package/package.json
CHANGED
package/src/consts.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export const ACTIVITY_GET_TRACE_DESTINATIONS = '__internal#getTraceDestinations';
|
|
2
2
|
export const ACTIVITY_OPTIONS_FILENAME = '__activity_options.js';
|
|
3
3
|
export const ACTIVITY_SEND_HTTP_REQUEST = '__internal#sendHttpRequest';
|
|
4
|
-
export const ACTIVITY_LOGGER_SYMBOL = Symbol.for( '__activity_logger' );
|
|
5
|
-
export const METADATA_ACCESS_SYMBOL = Symbol( '__metadata' );
|
|
6
4
|
export const WORKFLOW_CATALOG = '$catalog';
|
|
7
5
|
export const WORKFLOW_OPTIONS_FILENAME = '__workflow_options.js';
|
|
8
6
|
export const WORKFLOWS_INDEX_FILENAME = '__workflows_entrypoint.js';
|
|
9
7
|
|
|
10
8
|
export const INVOKE_ACTIVITY_SYMBOL = Symbol.for( '@outputai/core:__invoke_activity' );
|
|
9
|
+
export const METADATA_ACCESS_SYMBOL = Symbol( '__metadata' );
|
|
10
|
+
export const WORKER_LOGGER_SYMBOL = Symbol.for( '@outputai/core:__worker_logger' );
|
|
11
11
|
|
|
12
12
|
export const ComponentType = {
|
|
13
13
|
EVALUATOR: 'evaluator',
|
|
@@ -33,7 +33,8 @@ export const BusEventType = {
|
|
|
33
33
|
ACTIVITY_LOG: 'activity:log',
|
|
34
34
|
ACTIVITY_START: 'activity:start',
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
WORKER_ERROR: 'worker:error',
|
|
37
|
+
WORKER_LOG: 'worker:log'
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
export const WorkflowSpecialOutput = {
|
package/src/hooks/index.js
CHANGED
|
@@ -29,7 +29,7 @@ const onError = cb => {
|
|
|
29
29
|
callHookCb( cb, { source: 'activity', ...payload }, 'onError' ) );
|
|
30
30
|
mainEventBus.on( BusEventType.WORKFLOW_ERROR, async payload =>
|
|
31
31
|
callHookCb( cb, { source: 'workflow', ...payload }, 'onError' ) );
|
|
32
|
-
mainEventBus.on( BusEventType.
|
|
32
|
+
mainEventBus.on( BusEventType.WORKER_ERROR, async payload =>
|
|
33
33
|
callHookCb( cb, { source: 'runtime', ...payload }, 'onError' ) );
|
|
34
34
|
};
|
|
35
35
|
|
package/src/interface/logger.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inWorkflowContext } from '@temporalio/workflow';
|
|
2
2
|
import { proxySinks } from '@temporalio/workflow';
|
|
3
|
-
import {
|
|
3
|
+
import { WORKER_LOGGER_SYMBOL } from '#consts';
|
|
4
4
|
import { isPlainObject } from '#helpers/object';
|
|
5
5
|
|
|
6
6
|
const reservedMetadataFields = new Set( [
|
|
@@ -52,9 +52,9 @@ const log = ( level, namespace, message, metadata ) => {
|
|
|
52
52
|
// When inside workflow, use sinks to send logs out
|
|
53
53
|
if ( inWorkflowContext() ) {
|
|
54
54
|
sinks.workflow.log( { level, ...sanitized } );
|
|
55
|
-
// When
|
|
56
|
-
} else if ( typeof globalThis[
|
|
57
|
-
globalThis[
|
|
55
|
+
// When on a worker (activity or host), use the global function to ship logs
|
|
56
|
+
} else if ( typeof globalThis[WORKER_LOGGER_SYMBOL] === 'function' ) {
|
|
57
|
+
globalThis[WORKER_LOGGER_SYMBOL]( { level, ...sanitized } );
|
|
58
58
|
// This fallback is used on unit tests
|
|
59
59
|
} else {
|
|
60
60
|
console[levelToConsole[level]]( sanitized.message, sanitized.metadata );
|
package/src/worker/configs.js
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
2
|
import { isStringboolTrue } from '#helpers/string';
|
|
3
|
+
import { createChildLogger } from '#logger';
|
|
3
4
|
import { workerTunerEnvSchema } from './configs_tuner_schema.js';
|
|
4
5
|
|
|
6
|
+
const log = createChildLogger( 'Worker' );
|
|
7
|
+
|
|
5
8
|
class InvalidEnvVarsErrors extends Error { }
|
|
6
9
|
|
|
7
10
|
const coalesceEmptyString = v => v === '' ? undefined : v;
|
|
8
11
|
|
|
9
|
-
const
|
|
12
|
+
const durationUnitsMs = { ms: 1, s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000 };
|
|
13
|
+
|
|
14
|
+
// Plain integer ms, or `<n>(ms|s|m|h|d)` where n may be decimal
|
|
15
|
+
const durationPattern = /^(?:(?<plainMs>\d+)|(?<amount>\d+(?:\.\d+)?)\s?(?<unit>ms|s|m|h|d))$/i;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Converts a duration matching `durationPattern` into milliseconds.
|
|
19
|
+
* @param {string} value
|
|
20
|
+
* @returns {number}
|
|
21
|
+
*/
|
|
22
|
+
const convertDurationToMs = value => {
|
|
23
|
+
const { plainMs, amount, unit } = value.match( durationPattern ).groups;
|
|
24
|
+
return plainMs === undefined ? Math.round( Number( amount ) * durationUnitsMs[unit.toLowerCase()] ) : Number( plainMs );
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const durationMsSchema = z.preprocess(
|
|
10
28
|
coalesceEmptyString,
|
|
11
|
-
z.string()
|
|
12
|
-
.regex( /^\d+$|^\d+(\.\d+)?\s?(ms|s|m|h|d)$/i )
|
|
13
|
-
.optional()
|
|
29
|
+
z.string().regex( durationPattern ).transform( convertDurationToMs ).optional()
|
|
14
30
|
);
|
|
15
31
|
|
|
16
32
|
const envVarSchema = z.object( {
|
|
@@ -54,13 +70,18 @@ const envVarSchema = z.object( {
|
|
|
54
70
|
OUTPUT_ACTIVITY_HEARTBEAT_INTERVAL_MS: z.preprocess( coalesceEmptyString, z.coerce.number().int().positive().default( 2 * 60 * 1000 ) ), // 2min
|
|
55
71
|
// Whether to send activity heartbeats (enabled by default)
|
|
56
72
|
OUTPUT_ACTIVITY_HEARTBEAT_ENABLED: z.transform( v => v === undefined ? true : isStringboolTrue( v ) ),
|
|
57
|
-
// Set temporal worker shutdown force time.
|
|
58
|
-
//
|
|
59
|
-
TEMPORAL_SHUTDOWN_FORCE_TIME:
|
|
73
|
+
// Set temporal worker shutdown force time. Worst case shutdown is force time + OUTPUT_HOOK_FLUSH_TIMEOUT_MS,
|
|
74
|
+
// which must fit the window the platform allows before SIGKILL (30s by default on Render and Kubernetes).
|
|
75
|
+
TEMPORAL_SHUTDOWN_FORCE_TIME: durationMsSchema.default( 20_000 ), // 20s
|
|
60
76
|
// Set temporal worker shutdown grace time, when in-flight activities are asked to cancel
|
|
61
|
-
TEMPORAL_SHUTDOWN_GRACE_TIME:
|
|
77
|
+
TEMPORAL_SHUTDOWN_GRACE_TIME: durationMsSchema.default( 15_000 ), // 15s
|
|
62
78
|
// How long the worker awaits pending hook callbacks once the drain is over, before exiting anyway
|
|
63
|
-
OUTPUT_HOOK_FLUSH_TIMEOUT_MS: z.preprocess( coalesceEmptyString, z.coerce.number().int().positive().default(
|
|
79
|
+
OUTPUT_HOOK_FLUSH_TIMEOUT_MS: z.preprocess( coalesceEmptyString, z.coerce.number().int().positive().default( 5_000 ) ), // 5s
|
|
80
|
+
// Verbosity of the Temporal SDK and Core logs. Takes Temporal levels, not Winston ones. Case-insensitive.
|
|
81
|
+
OUTPUT_TEMPORAL_LOG_LEVEL: z.preprocess(
|
|
82
|
+
v => coalesceEmptyString( v )?.toUpperCase(),
|
|
83
|
+
z.enum( [ 'TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR' ] ).default( 'INFO' )
|
|
84
|
+
),
|
|
64
85
|
// HTTP CONNECT proxy for Temporal gRPC connections (e.g. "proxy-host:8080").
|
|
65
86
|
// Must be a bare host:port — no scheme (Temporal's native HTTP CONNECT
|
|
66
87
|
// option is not a URL).
|
|
@@ -75,6 +96,13 @@ if ( error ) {
|
|
|
75
96
|
throw new InvalidEnvVarsErrors( z.prettifyError( error ) );
|
|
76
97
|
}
|
|
77
98
|
|
|
99
|
+
if ( envVars.TEMPORAL_SHUTDOWN_FORCE_TIME <= envVars.TEMPORAL_SHUTDOWN_GRACE_TIME ) {
|
|
100
|
+
log.warn( 'Temporal shutdown force time is not bigger than its grace time, so activities have no window to react to cancellation', {
|
|
101
|
+
shutdownForceTimeMs: envVars.TEMPORAL_SHUTDOWN_FORCE_TIME,
|
|
102
|
+
shutdownGraceTimeMs: envVars.TEMPORAL_SHUTDOWN_GRACE_TIME
|
|
103
|
+
} );
|
|
104
|
+
}
|
|
105
|
+
|
|
78
106
|
export const address = envVars.TEMPORAL_ADDRESS;
|
|
79
107
|
export const apiKey = envVars.TEMPORAL_API_KEY;
|
|
80
108
|
export const maxConcurrentActivityTaskExecutions = envVars.TEMPORAL_MAX_CONCURRENT_ACTIVITY_TASK_EXECUTIONS;
|
|
@@ -90,7 +118,8 @@ export const catalogId = envVars.OUTPUT_CATALOG_ID;
|
|
|
90
118
|
export const workerTelemetryIntervalMs = envVars.OUTPUT_WORKER_TELEMETRY_INTERVAL_MS;
|
|
91
119
|
export const activityHeartbeatIntervalMs = envVars.OUTPUT_ACTIVITY_HEARTBEAT_INTERVAL_MS;
|
|
92
120
|
export const activityHeartbeatEnabled = envVars.OUTPUT_ACTIVITY_HEARTBEAT_ENABLED;
|
|
93
|
-
export const
|
|
94
|
-
export const
|
|
121
|
+
export const shutdownForceTimeMs = envVars.TEMPORAL_SHUTDOWN_FORCE_TIME;
|
|
122
|
+
export const shutdownGraceTimeMs = envVars.TEMPORAL_SHUTDOWN_GRACE_TIME;
|
|
95
123
|
export const hookFlushTimeoutMs = envVars.OUTPUT_HOOK_FLUSH_TIMEOUT_MS;
|
|
124
|
+
export const temporalLogLevel = envVars.OUTPUT_TEMPORAL_LOG_LEVEL;
|
|
96
125
|
export const grpcProxy = envVars.TEMPORAL_GRPC_PROXY;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { mainEventBus } from '#bus';
|
|
2
|
-
import {
|
|
3
|
-
import { activityInfo as activityInfoFn } from '@temporalio/activity';
|
|
2
|
+
import { WORKER_LOGGER_SYMBOL, BusEventType } from '#consts';
|
|
3
|
+
import { activityInfo as activityInfoFn, asyncLocalStorage } from '@temporalio/activity';
|
|
4
4
|
import { assignImmutableProperty } from '#helpers/object';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Sets global functions on globalThis
|
|
8
8
|
*/
|
|
9
9
|
export const bindGlobalFunctions = () => {
|
|
10
|
-
/** Defines the
|
|
11
|
-
assignImmutableProperty( globalThis,
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/** Defines the worker logger function, accessible from activity and worker (host) context via logger interface */
|
|
11
|
+
assignImmutableProperty( globalThis, WORKER_LOGGER_SYMBOL, ( { level, message, metadata } ) => {
|
|
12
|
+
const context = asyncLocalStorage.getStore();
|
|
13
|
+
if ( context ) { // means we are in an activity
|
|
14
|
+
mainEventBus.emit( BusEventType.ACTIVITY_LOG, { level, message, metadata, activityInfo: activityInfoFn() } );
|
|
15
|
+
} else { // means we are at the worker level, maybe a hook, but not inside the sandbox
|
|
16
|
+
mainEventBus.emit( BusEventType.WORKER_LOG, { level, message, metadata } );
|
|
17
|
+
}
|
|
18
|
+
} );
|
|
14
19
|
};
|
package/src/worker/index.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Worker, NativeConnection } from '@temporalio/worker';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
address,
|
|
4
|
+
apiKey,
|
|
5
|
+
namespace,
|
|
6
|
+
taskQueue,
|
|
7
|
+
grpcProxy,
|
|
8
|
+
hookFlushTimeoutMs,
|
|
9
|
+
shutdownForceTimeMs,
|
|
10
|
+
shutdownGraceTimeMs
|
|
11
|
+
} from './configs.js';
|
|
3
12
|
import { loadActivities } from './loader/activities.js';
|
|
4
13
|
import { loadWorkflows } from './loader/workflows.js';
|
|
5
14
|
import { loadHooks } from './loader/hooks.js';
|
|
@@ -52,6 +61,9 @@ const execute = async () => {
|
|
|
52
61
|
log.info( 'Setting up Temporal Logger...' );
|
|
53
62
|
run( setupTemporalLogger );
|
|
54
63
|
|
|
64
|
+
log.info( 'Binding globals...' );
|
|
65
|
+
run( bindGlobalFunctions );
|
|
66
|
+
|
|
55
67
|
log.info( 'Loading config...', { callerDir } );
|
|
56
68
|
await run( () => loadHooks( callerDir ) );
|
|
57
69
|
|
|
@@ -73,9 +85,6 @@ const execute = async () => {
|
|
|
73
85
|
log.info( 'Computing catalog source code hash...' );
|
|
74
86
|
const catalogHash = await run( () => hashSourceCode( callerDir ) );
|
|
75
87
|
|
|
76
|
-
log.info( 'Binding globals...' );
|
|
77
|
-
run( bindGlobalFunctions );
|
|
78
|
-
|
|
79
88
|
log.info( 'Connecting Temporal...' );
|
|
80
89
|
const proxy = grpcProxy ? { type: 'http-connect', targetHost: grpcProxy } : undefined;
|
|
81
90
|
if ( proxy ) {
|
|
@@ -134,21 +143,30 @@ const execute = async () => {
|
|
|
134
143
|
execute()
|
|
135
144
|
.catch( async error => abortController.abort( error ) )
|
|
136
145
|
.finally( async () => {
|
|
137
|
-
|
|
146
|
+
log.info( 'Shutting down', {
|
|
147
|
+
shutdownForceTimeMs,
|
|
148
|
+
shutdownGraceTimeMs,
|
|
149
|
+
hookFlushTimeoutMs
|
|
150
|
+
} );
|
|
151
|
+
|
|
152
|
+
const shutdownStartedAt = Date.now();
|
|
153
|
+
await shutdownServices( services );
|
|
138
154
|
|
|
139
155
|
const hasError = signal.aborted && !( signal.reason instanceof KillSignError );
|
|
140
156
|
if ( hasError ) {
|
|
141
157
|
log.error( 'Worker error', { error: serializeError( signal.reason ) } );
|
|
142
|
-
mainEventBus.emit( BusEventType.
|
|
158
|
+
mainEventBus.emit( BusEventType.WORKER_ERROR, { error: signal.reason } );
|
|
143
159
|
}
|
|
144
160
|
|
|
145
161
|
log.info( 'Flushing hook callbacks...' );
|
|
146
162
|
await flushPendingHooks( hookFlushTimeoutMs );
|
|
147
163
|
|
|
148
|
-
const workerFailedToStop = shutdownFailures.some( v => v.service === 'worker' );
|
|
149
|
-
const exitCode = workerFailedToStop || hasError ? 1 : 0;
|
|
150
164
|
setTimeout( () => {
|
|
151
|
-
|
|
165
|
+
const exitCode = hasError ? 1 : 0;
|
|
166
|
+
log.info( 'Bye', {
|
|
167
|
+
exitCode,
|
|
168
|
+
shutdownDurationMs: Date.now() - shutdownStartedAt
|
|
169
|
+
} );
|
|
152
170
|
process.exit( exitCode );
|
|
153
171
|
} );
|
|
154
172
|
} );
|
package/src/worker/log_hooks.js
CHANGED
|
@@ -5,6 +5,7 @@ import { serializeError } from '#helpers/error_serializer';
|
|
|
5
5
|
|
|
6
6
|
const activityLog = createChildLogger( 'Activity' );
|
|
7
7
|
const workflowLog = createChildLogger( 'Workflow' );
|
|
8
|
+
const workerLog = createChildLogger( 'Worker' );
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Intercepts internal bus events for activity and workflow lifecycle and log them
|
|
@@ -56,6 +57,13 @@ mainEventBus.on( BusEventType.ACTIVITY_LOG, ( { level, message, metadata, activi
|
|
|
56
57
|
} )
|
|
57
58
|
);
|
|
58
59
|
|
|
60
|
+
/*
|
|
61
|
+
╔═══════════════╗
|
|
62
|
+
║ Worker events ║
|
|
63
|
+
╚═══════════════╝
|
|
64
|
+
*/
|
|
65
|
+
mainEventBus.on( BusEventType.WORKER_LOG, ( { level, message, metadata } ) => workerLog[level]( message, metadata ) );
|
|
66
|
+
|
|
59
67
|
/*
|
|
60
68
|
╔═════════════════╗
|
|
61
69
|
║ Workflow events ║
|
package/src/worker/shutdown.js
CHANGED
|
@@ -5,49 +5,43 @@ const log = createChildLogger( 'Worker Shutdown' );
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Gracefully shuts every running service down, in order.
|
|
8
|
-
* A service that fails to stop never interrupts the sequence
|
|
9
|
-
* @returns {Promise<Array<{ service: string, error: Error }>>} one entry per service that failed to stop
|
|
8
|
+
* A service that fails to stop never interrupts the sequence
|
|
10
9
|
*/
|
|
11
10
|
export const shutdownServices = async ( { workerRunner, connectionMonitor, catalogPublisher, connection } ) => {
|
|
12
11
|
const shutdownJobs = [
|
|
13
12
|
{
|
|
14
|
-
service: 'worker',
|
|
15
13
|
label: 'Stopping Worker',
|
|
16
14
|
isActive: () => workerRunner?.running,
|
|
17
15
|
stop: () => workerRunner.stop()
|
|
18
16
|
},
|
|
19
17
|
{
|
|
20
|
-
service: 'connection_monitor',
|
|
21
18
|
label: 'Stopping Connection Monitor',
|
|
22
19
|
isActive: () => connectionMonitor?.running,
|
|
23
20
|
stop: () => connectionMonitor.stop()
|
|
24
21
|
},
|
|
25
22
|
{
|
|
26
|
-
service: 'catalog_publisher',
|
|
27
23
|
label: 'Interrupting Catalog Publisher',
|
|
28
24
|
isActive: () => catalogPublisher?.running,
|
|
29
25
|
stop: () => catalogPublisher.interrupt()
|
|
30
26
|
},
|
|
31
27
|
{
|
|
32
|
-
service: 'connection',
|
|
33
28
|
label: 'Closing Connection',
|
|
34
29
|
isActive: () => connection,
|
|
35
30
|
stop: () => connection.close()
|
|
36
31
|
}
|
|
37
32
|
];
|
|
38
33
|
|
|
39
|
-
const
|
|
40
|
-
for ( const { service, label, isActive, stop } of shutdownJobs ) {
|
|
34
|
+
for ( const { label, isActive, stop } of shutdownJobs ) {
|
|
41
35
|
if ( isActive() ) {
|
|
36
|
+
const shutdownStartedAt = Date.now();
|
|
42
37
|
log.info( `${label}...` );
|
|
43
38
|
// a try covers a service that throws instead of rejecting, which a catch on the promise would miss
|
|
44
39
|
try {
|
|
45
40
|
await stop();
|
|
41
|
+
log.info( `${label} complete`, { shutdownDurationMs: Date.now() - shutdownStartedAt } );
|
|
46
42
|
} catch ( error ) {
|
|
47
|
-
|
|
48
|
-
log.warn( `${label} error`, { error: serializeError( error ) } );
|
|
43
|
+
log.warn( `${label} failed`, { error: serializeError( error ), shutdownDurationMs: Date.now() - shutdownStartedAt } );
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
|
-
return failures;
|
|
53
47
|
};
|
|
@@ -1,32 +1,65 @@
|
|
|
1
|
-
import { DefaultLogger,
|
|
1
|
+
import { DefaultLogger, GracefulShutdownPeriodExpiredError, Runtime } from '@temporalio/worker';
|
|
2
2
|
import { createChildLogger } from '#logger';
|
|
3
|
+
import { serializeError } from '#helpers/error_serializer';
|
|
4
|
+
import { temporalLogLevel } from './configs.js';
|
|
3
5
|
|
|
4
6
|
const log = createChildLogger( 'Temporal' );
|
|
5
7
|
const OMITTED_MESSAGES = [ 'Activity failed', 'Workflow failed' ];
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/** Whether the entry reports the shutdown force time expiring, an expected outcome of a deploy that is logged as a warning, not an error */
|
|
10
|
+
const isForcedShutdownEntry = ( { meta } ) => meta?.error instanceof GracefulShutdownPeriodExpiredError;
|
|
11
|
+
|
|
12
|
+
/** Serializes Error values in the meta, otherwise they would be logged as an empty object */
|
|
13
|
+
const serializeMetaErrors = meta => meta && Object.fromEntries(
|
|
14
|
+
Object.entries( meta ).map( ( [ key, value ] ) => [ key, value instanceof Error ? serializeError( value ) : value ] )
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const TemporalLogLevel = {
|
|
18
|
+
TRACE: 'TRACE',
|
|
19
|
+
DEBUG: 'DEBUG',
|
|
20
|
+
INFO: 'INFO',
|
|
21
|
+
WARN: 'WARN',
|
|
22
|
+
ERROR: 'ERROR'
|
|
13
23
|
};
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
const temporalToInternalLogLevel = {
|
|
26
|
+
[TemporalLogLevel.TRACE]: 'debug',
|
|
27
|
+
[TemporalLogLevel.DEBUG]: 'debug',
|
|
28
|
+
[TemporalLogLevel.INFO]: 'info',
|
|
29
|
+
[TemporalLogLevel.WARN]: 'warn',
|
|
30
|
+
[TemporalLogLevel.ERROR]: 'error'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const temporalLogLevelsOrder = [
|
|
34
|
+
TemporalLogLevel.TRACE,
|
|
35
|
+
TemporalLogLevel.DEBUG,
|
|
36
|
+
TemporalLogLevel.INFO,
|
|
37
|
+
TemporalLogLevel.WARN,
|
|
38
|
+
TemporalLogLevel.ERROR
|
|
39
|
+
];
|
|
17
40
|
|
|
41
|
+
const isLogLevelEnabled = ( configuredLevel, entryLevel ) =>
|
|
42
|
+
temporalLogLevelsOrder.indexOf( entryLevel ) >= temporalLogLevelsOrder.indexOf( configuredLevel );
|
|
43
|
+
|
|
44
|
+
export const setupTemporalLogger = () => {
|
|
18
45
|
Runtime.install( {
|
|
19
|
-
logger: new DefaultLogger(
|
|
46
|
+
logger: new DefaultLogger( temporalLogLevel, entry => {
|
|
20
47
|
// Already reported by Output activity logs and traces.
|
|
21
48
|
if ( OMITTED_MESSAGES.includes( entry.message ) ) {
|
|
22
49
|
return;
|
|
23
50
|
}
|
|
24
|
-
|
|
51
|
+
const forcedShutdown = isForcedShutdownEntry( entry );
|
|
52
|
+
if ( forcedShutdown && !isLogLevelEnabled( temporalLogLevel, TemporalLogLevel.WARN ) ) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const level = temporalToInternalLogLevel[forcedShutdown ? TemporalLogLevel.WARN : entry.level];
|
|
57
|
+
log.log( level, entry.message, serializeMetaErrors( entry.meta ) );
|
|
25
58
|
} ),
|
|
26
59
|
telemetryOptions: {
|
|
27
60
|
logging: {
|
|
28
61
|
forward: {},
|
|
29
|
-
filter:
|
|
62
|
+
filter: { core: temporalLogLevel, other: temporalLogLevel }
|
|
30
63
|
}
|
|
31
64
|
}
|
|
32
65
|
} );
|
|
@@ -10,8 +10,8 @@ const {
|
|
|
10
10
|
maxConcurrentActivityTaskPolls,
|
|
11
11
|
maxConcurrentWorkflowTaskPolls,
|
|
12
12
|
workflowThreadPoolSize,
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
shutdownForceTimeMs,
|
|
14
|
+
shutdownGraceTimeMs,
|
|
15
15
|
workerTuner
|
|
16
16
|
} = configs;
|
|
17
17
|
|
|
@@ -37,7 +37,7 @@ export const buildWorkerOptions = () => {
|
|
|
37
37
|
maxConcurrentWorkflowTaskPolls,
|
|
38
38
|
// Omitted when unset so @temporalio/worker applies its own default, which depends on reuseV8Context.
|
|
39
39
|
...( workflowThreadPoolSize !== undefined && { workflowThreadPoolSize } ),
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
shutdownForceTime: shutdownForceTimeMs,
|
|
41
|
+
shutdownGraceTime: shutdownGraceTimeMs
|
|
42
42
|
};
|
|
43
43
|
};
|