UNPKG

@temporalio/worker

Version:
54 lines 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ActivityInboundLogInterceptor = void 0; const common_1 = require("@temporalio/common"); const activity_1 = require("./activity"); const runtime_1 = require("./runtime"); /** * This interceptor was previously used to log Activity execution starts and their completions. It is now deprecated * and behaves as a noop in most cases. It is only kept arround to avoid breaking code out there that was previously * refering to it. * * @deprecated `ActivityInboundLogInterceptor` is deprecated. Activity lifecycle events are now automatically logged * by the SDK. To customize activity log attributes, register a custom {@link ActivityOutboundCallsInterceptor} * that intercepts the `getLogAttributes()` method. To customize where log messages are sent, set the * {@link Runtime.logger} property. */ class ActivityInboundLogInterceptor { ctx; logger; constructor(ctx, logger) { this.ctx = ctx; const runtimeLogger = runtime_1.Runtime.instance().logger; this.logger = logger ?? runtimeLogger; // In the very common case where `ActivityInboundLogInterceptor` is intantiated without a custom logger and without // extending it (ie. to inject custom log attributes), then just be a noop. This is just to avoid bothering users // that followed something that used to be a recommended pattern. The "default" behavior that used to be provided by // this class is now handled elsewhere. if (this.logger === runtimeLogger && Object.getPrototypeOf(this) === ActivityInboundLogInterceptor.prototype // eslint-disable-line deprecation/deprecation ) return; this.ctx.log = Object.fromEntries(['trace', 'debug', 'info', 'warn', 'error'].map((level) => { return [ level, (message, attrs) => { return this.logger[level](message, { sdkComponent: common_1.SdkComponent.activity, ...this.logAttributes(), ...attrs, }); }, ]; })); } logAttributes() { return (0, activity_1.activityLogAttributes)(this.ctx.info); } async execute(input, next) { // Logging of activity's lifecycle events is now handled in `worker/src/activity.ts` return next(input); } } exports.ActivityInboundLogInterceptor = ActivityInboundLogInterceptor; //# sourceMappingURL=activity-log-interceptor.js.map