From 2f026f7921d737705b9c217991e94145221efdd1 Mon Sep 17 00:00:00 2001 From: User Date: Tue, 29 Sep 2026 11:13:58 +0200 Subject: [PATCH 1/2] #477 - Preserve structured properties from logging arguments --- README.md | 8 ++ src/InvocationModel.ts | 24 +++- src/hooks/LogHookContext.ts | 8 ++ src/hooks/registerHook.ts | 21 ++- src/setup.ts | 8 ++ src/utils/extractLogAttributes.ts | 63 +++++++++ test/structuredLogging.test.ts | 216 ++++++++++++++++++++++++++++++ test/types/index.test.ts | 17 +++ types-core/index.d.ts | 22 ++- types/hooks/logHooks.d.ts | 10 ++ types/hooks/registerHook.d.ts | 4 +- types/setup.d.ts | 3 + 12 files changed, 391 insertions(+), 13 deletions(-) create mode 100644 src/utils/extractLogAttributes.ts create mode 100644 test/structuredLogging.test.ts diff --git a/README.md b/README.md index 84f4da0..cedb742 100644 --- a/README.md +++ b/README.md @@ -65,3 +65,11 @@ app.http('httpTrigger1', { } }); ``` + +## Opt-in structured log properties + +Enable extraction during application startup with `app.setup({ structuredLogProperties: 'lastPlainObject' })`. Existing calls such as `context.error('Job submission failed', { model: 'olive', errorCode: 'COMPONENT_NOT_FOUND' })` keep their original formatted message and additionally expose the final plain object's own enumerable string, boolean and finite-number properties as `LogHookContext.attributes`. The option is disabled by default. Earlier arguments, arrays, Error instances and nested objects are not sources of structured properties. + +A log exporter registers with `app.hook.log(handler, { structuredLogProperties: true })` once it can export the attributes. This requires a worker advertising `supportsStructuredLogProperties` and a compatible exporter; enabling the library option alone does not make fields queryable in Application Insights. Unsupported workers keep the original text and issue a system warning once per invocation. Invalid or reserved properties are omitted with bounded diagnostics that do not include their values; getters are not invoked by extraction. The original text is unchanged, so omitting a property from attributes does not redact it from the message. + +Reserved keys include `CategoryName`, `__proto__`, `prototype`, `constructor`, and names beginning with `exception.`, `_MS`, `microsoft` or `ai.` (case-insensitive). These prevent application properties from changing exporter routing or correlation. Diagnostics and buffering remain subject to the configured logging pipeline; this option does not guarantee delivery after process or network failure. diff --git a/src/InvocationModel.ts b/src/InvocationModel.ts index 55337a6..b2bc4bf 100644 --- a/src/InvocationModel.ts +++ b/src/InvocationModel.ts @@ -26,12 +26,15 @@ import { waitForProxyRequest } from './http/httpProxy'; import { createStreamRequest } from './http/HttpRequest'; import { InvocationContext } from './InvocationContext'; import { PromptInvocationContext } from './mcp/PromptInvocationContext'; -import { enableHttpStream } from './setup'; +import { enableHttpStream, structuredLogProperties } from './setup'; +import { extractLogAttributes } from './utils/extractLogAttributes'; import { isHttpTrigger, isMcpPromptTrigger, isMcpToolTrigger, isTimerTrigger, isTrigger } from './utils/isTrigger'; import { isDefined, nonNullProp, nonNullValue } from './utils/nonNull'; +import { tryGetCoreApiLazy } from './utils/tryGetCoreApiLazy'; export class InvocationModel implements coreTypes.InvocationModel { #isDone = false; + #structuredLogWarnings = new Set(); #coreCtx: CoreInvocationContext; #functionName: string; #bindings: Record; @@ -195,6 +198,25 @@ export class InvocationModel implements coreTypes.InvocationModel { badAsyncMsg += `Function name: ${this.#functionName}. Invocation Id: ${this.#coreCtx.invocationId}.`; this.#systemLog('warning', badAsyncMsg); } + if (structuredLogProperties === 'lastPlainObject') { + const extracted = extractLogAttributes(args[args.length - 1]); + if (extracted.reason) { + this.#structuredLogWarning(extracted.reason, extracted.rejectedCount); + } + if (extracted.attributes) { + if (tryGetCoreApiLazy()?.supportsStructuredLogProperties) { + this.#coreCtx.log(level, 'user', format(...args), { attributes: extracted.attributes }); + return; + } + this.#structuredLogWarning('structured_log_worker_unavailable', 0); + } + } this.#log(level, 'user', ...args); } + #structuredLogWarning(reason: string, rejectedCount: number): void { + if (!this.#structuredLogWarnings.has(reason)) { + this.#structuredLogWarnings.add(reason); + this.#systemLog('warning', `${reason}: rejectedProperties=${rejectedCount}`); + } + } } diff --git a/src/hooks/LogHookContext.ts b/src/hooks/LogHookContext.ts index 1f5e2ef..205191d 100644 --- a/src/hooks/LogHookContext.ts +++ b/src/hooks/LogHookContext.ts @@ -41,6 +41,14 @@ export class LogHookContext extends HookContext implements types.LogHookContext throw new ReadOnlyError('category'); } + get attributes(): Readonly> | undefined { + return this.#init.attributes; + } + + set attributes(_value: Readonly> | undefined) { + throw new ReadOnlyError('attributes'); + } + get invocationContext(): types.InvocationContext | undefined { return this.#init.invocationContext; } diff --git a/src/hooks/registerHook.ts b/src/hooks/registerHook.ts index 944ef61..fa4ed4f 100644 --- a/src/hooks/registerHook.ts +++ b/src/hooks/registerHook.ts @@ -5,6 +5,7 @@ import { AppStartHandler, AppTerminateHandler, LogHookHandler, + LogHookOptions, PostInvocationHandler, PreInvocationHandler, } from '@azure/functions'; @@ -18,7 +19,11 @@ import { LogHookContext } from './LogHookContext'; import { PostInvocationContext } from './PostInvocationContext'; import { PreInvocationContext } from './PreInvocationContext'; -function registerHook(hookName: string, callback: coreTypes.HookCallback): coreTypes.Disposable { +function registerHook( + hookName: string, + callback: coreTypes.HookCallback, + options?: LogHookOptions +): coreTypes.Disposable { const coreApi = tryGetCoreApiLazy(); if (!coreApi) { console.warn( @@ -30,7 +35,7 @@ function registerHook(hookName: string, callback: coreTypes.HookCallback): coreT ); }); } else { - return coreApi.registerHook(hookName, callback); + return options ? coreApi.registerHook(hookName, callback, options) : coreApi.registerHook(hookName, callback); } } @@ -58,11 +63,15 @@ export function postInvocation(handler: PostInvocationHandler): Disposable { }); } -export function log(handler: LogHookHandler): Disposable { +export function log(handler: LogHookHandler, options?: LogHookOptions): Disposable { try { - return registerHook('log', (coreContext) => { - return handler(new LogHookContext(coreContext)); - }); + return registerHook( + 'log', + (coreContext) => { + return handler(new LogHookContext(coreContext)); + }, + options + ); } catch (err) { const error = ensureErrorType(err); if (error.name === 'RangeError' && error.isAzureFunctionsSystemError) { diff --git a/src/setup.ts b/src/setup.ts index d6b54c3..e99669c 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -12,6 +12,7 @@ export function lockSetup(): void { setupLocked = true; } +export let structuredLogProperties: SetupOptions['structuredLogProperties']; export let enableHttpStream = false; export const capabilities: Record = {}; @@ -20,6 +21,13 @@ export function setup(opts: SetupOptions): void { throw new AzFuncSystemError("Setup options can't be changed after app startup has finished."); } + if (isDefined(opts.structuredLogProperties)) { + if (opts.structuredLogProperties !== 'lastPlainObject') { + throw new AzFuncSystemError('Unsupported structuredLogProperties option.'); + } + structuredLogProperties = opts.structuredLogProperties; + } + if (opts.enableHttpStream) { // NOTE: coreApi.log was coincidentally added the same time as http streaming, // so we can use that to validate the host version instead of messing with semver parsing diff --git a/src/utils/extractLogAttributes.ts b/src/utils/extractLogAttributes.ts new file mode 100644 index 0000000..3a65cc9 --- /dev/null +++ b/src/utils/extractLogAttributes.ts @@ -0,0 +1,63 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +export function extractLogAttributes(argument: unknown): ExtractedLogAttributes { + if (typeof argument !== 'object' || argument === null) { + return { rejectedCount: 0 }; + } + try { + const prototype: unknown = Object.getPrototypeOf(argument); + if (prototype !== Object.prototype && prototype !== null) { + return { rejectedCount: 0 }; + } + const attributes: Record = Object.create(null) as Record< + string, + string | number | boolean + >; + let rejectedCount = 0; + for (const propertyName of Object.getOwnPropertyNames(argument)) { + const descriptor = Object.getOwnPropertyDescriptor(argument, propertyName); + if (!descriptor?.enumerable) { + continue; + } + const propertyValue: unknown = descriptor.value; + if (!('value' in descriptor) || isReservedLogProperty(propertyName) || !isLogPropertyValue(propertyValue)) { + rejectedCount++; + } else { + attributes[propertyName] = propertyValue; + } + } + return { + attributes: Object.freeze(attributes), + rejectedCount, + reason: rejectedCount ? 'structured_log_invalid_properties' : undefined, + }; + } catch { + return { rejectedCount: 0, reason: 'structured_log_inspection_failed' }; + } +} + +function isReservedLogProperty(propertyName: string): boolean { + const name = propertyName.toLowerCase(); + return ( + name === 'categoryname' || + name === '__proto__' || + name === 'prototype' || + name === 'constructor' || + ['exception.', '_ms', 'microsoft', 'ai.'].some((prefix) => name.startsWith(prefix)) + ); +} + +function isLogPropertyValue(propertyValue: unknown): propertyValue is string | number | boolean { + return ( + typeof propertyValue === 'string' || + typeof propertyValue === 'boolean' || + (typeof propertyValue === 'number' && Number.isFinite(propertyValue)) + ); +} + +interface ExtractedLogAttributes { + attributes?: Readonly>; + rejectedCount: number; + reason?: 'structured_log_invalid_properties' | 'structured_log_inspection_failed'; +} diff --git a/test/structuredLogging.test.ts b/test/structuredLogging.test.ts new file mode 100644 index 0000000..335186b --- /dev/null +++ b/test/structuredLogging.test.ts @@ -0,0 +1,216 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. + +import 'mocha'; +import { CoreInvocationContext, RpcLogCategory, RpcLogLevel } from '@azure/functions-core'; +import { expect } from 'chai'; +import * as sinon from 'sinon'; +import { format } from 'util'; +import * as app from '../src/app'; +import { InvocationModel } from '../src/InvocationModel'; +import * as setupModule from '../src/setup'; +import { extractLogAttributes } from '../src/utils/extractLogAttributes'; +import * as coreModule from '../src/utils/tryGetCoreApiLazy'; +import { InvocationContext, LogHookContext } from '../types'; + +describe('structured logging', () => { + afterEach(() => sinon.restore()); + + function configure(enabled = true, supported = true) { + sinon.stub(setupModule, 'structuredLogProperties').value(undefined); + if (enabled) app.setup({ structuredLogProperties: 'lastPlainObject' }); + sinon.stub(coreModule, 'tryGetCoreApiLazy').returns({ + supportsStructuredLogProperties: supported, + } as unknown as ReturnType); + } + + async function invocation() { + const calls: { level: RpcLogLevel; category: RpcLogCategory; message: string; metadata?: unknown }[] = []; + const core: CoreInvocationContext = { + invocationId: 'test-invocation', + metadata: { name: 'logging', bindings: { trigger: { type: 'timerTrigger', direction: 'in' } } }, + request: {}, + log: (level, category, message, metadata) => calls.push({ level, category, message, metadata }), + }; + const model = new InvocationModel(core); + const { context } = await model.getArguments(); + return { context: context as InvocationContext, calls, model, core }; + } + + it('keeps default text-only logging and does not inspect the final argument', async () => { + configure(false); + const { context, calls } = await invocation(); + const properties = { model: 'olive' }; + const inspectPrototype = sinon.spy(); + const proxy = new Proxy(properties, { + getPrototypeOf: () => { + inspectPrototype(); + throw new Error('not inspected'); + }, + }); + context.log('result', proxy); + expect(inspectPrototype.called).to.equal(false); + expect(calls).to.deep.equal([ + { level: 'information', category: 'user', message: format('result', proxy), metadata: undefined }, + ]); + }); + + it('keeps formatting for every level while separately copying the final object', async () => { + configure(); + const { context, calls } = await invocation(); + const properties = Object.freeze({ model: 'olive', attempts: 0, enabled: false }); + for (const method of ['log', 'info', 'warn', 'error', 'debug', 'trace'] as const) { + context[method]('result %s %d %j', 'value', 3, properties); + } + expect(calls.map((call) => call.level)).to.deep.equal([ + 'information', + 'information', + 'warning', + 'error', + 'debug', + 'trace', + ]); + for (const call of calls) { + expect(call.message).to.equal(format('result %s %d %j', 'value', 3, properties)); + expect(call.metadata).to.deep.equal({ attributes: properties }); + expect((call.metadata as { attributes: unknown }).attributes).not.to.equal(properties); + } + }); + + it('only extracts the final argument and accepts a single null-prototype object', async () => { + configure(); + const { context, calls } = await invocation(); + const properties = Object.assign(Object.create(null) as Record, { model: 'olive' }); + context.log(properties); + context.log({ first: 'text' }, { last: 'attribute' }); + context.log({ first: 'text' }, 'last'); + context.error(new Error('failure')); + context.log(['array']); + expect(calls[0]?.metadata).to.deep.equal({ attributes: { model: 'olive' } }); + expect(calls[1]?.metadata).to.deep.equal({ attributes: { last: 'attribute' } }); + expect(calls.slice(2).every((call) => call.metadata === undefined)).to.equal(true); + }); + + it('filters invalid and reserved fields without getters, mutation or unbounded warnings', async () => { + configure(); + const { context, calls } = await invocation(); + const getter = sinon.spy(() => { + throw new Error('getter secret'); + }); + const properties: Record = { + model: 'olive', + nan: NaN, + infinity: Infinity, + missing: undefined, + nil: null, + big: BigInt(2), + nested: { secret: 'not exported' }, + array: [], + error: new Error('private'), + CategoryName: 'secret-category', + 'ExCePtIoN.type': 'secret-type', + '_MS.foo': 'secret', + 'microsoft.foo': 'secret', + 'AI.operation.name': 'secret', + constructor: 'secret', + }; + Object.defineProperty(properties, 'getter', { enumerable: true, get: getter }); + Object.defineProperty(properties, 'hidden', { enumerable: false, value: 'hidden' }); + Object.freeze(properties); + context.error('failure', properties); + context.error('failure', properties); + expect(getter.called).to.equal(false); + const userCalls = calls.filter((call) => call.category === 'user'); + expect(userCalls).to.have.length(2); + expect(userCalls[0]?.metadata).to.deep.equal({ attributes: { model: 'olive' } }); + expect(userCalls[0]?.message).to.equal(format('failure', properties)); + const warnings = calls.filter((call) => call.category === 'system'); + expect(warnings).to.have.length(1); + expect(warnings[0]?.level).to.equal('warning'); + expect(warnings[0]?.message).not.to.contain('secret'); + }); + + it('preserves text with one warning per invocation when the worker lacks support', async () => { + configure(true, false); + const first = await invocation(); + const second = await invocation(); + for (const current of [first, second]) { + current.context.error('failure', { model: 'olive' }); + current.context.error('failure', { model: 'olive' }); + expect(current.calls.filter((call) => call.category === 'system')).to.have.length(1); + const userCalls = current.calls.filter((call) => call.category === 'user'); + expect(userCalls).to.have.length(2); + expect(userCalls[0]?.message).to.equal(format('failure', { model: 'olive' })); + expect(userCalls[0]?.metadata).to.equal(undefined); + } + }); + + it('contains proxy inspection failures and retains the existing formatted message', async () => { + configure(); + const { context, calls } = await invocation(); + const proxy = new Proxy( + { model: 'olive' }, + { + getPrototypeOf: () => { + throw new Error('private'); + }, + } + ); + const originalMessage = format('result', proxy); + expect(() => context.log('result', proxy)).not.to.throw(); + expect(calls.find((call) => call.category === 'user')?.message).to.equal(originalMessage); + expect(calls.find((call) => call.category === 'system')?.message).to.contain( + 'structured_log_inspection_failed' + ); + }); + + it('passes hook metadata and consumer options through the public API', () => { + const registerHook = sinon.stub().returns({ dispose() {} }); + sinon + .stub(coreModule, 'tryGetCoreApiLazy') + .returns({ registerHook } as unknown as ReturnType); + let observed: LogHookContext | undefined; + app.hook.log( + (context) => { + observed = context; + }, + { structuredLogProperties: true } + ); + expect(registerHook.firstCall.args[2]).to.deep.equal({ structuredLogProperties: true }); + const handler = registerHook.firstCall.args[1] as (context: object) => void; + const attributes = Object.freeze({ model: 'olive' }); + handler({ message: 'failure', level: 'error', category: 'user', attributes }); + expect(observed?.attributes).to.equal(attributes); + const observedHook = observed; + if (!observedHook) throw new Error('Expected the log hook to run'); + expect(() => { + Reflect.set(observedHook, 'attributes', {}); + }).to.throw(); + }); + + it('keeps setup opt-in on unrelated setup calls and rejects invalid configuration', () => { + sinon.stub(setupModule, 'structuredLogProperties').value(undefined); + expect(setupModule.structuredLogProperties).to.equal(undefined); + app.setup({ structuredLogProperties: 'lastPlainObject' }); + app.setup({}); + expect(setupModule.structuredLogProperties).to.equal('lastPlainObject'); + expect(() => + app.setup({ structuredLogProperties: 'invalid' } as unknown as Parameters[0]) + ).to.throw(); + }); + + it('rejects hostile descriptor enumeration without leaking partial attributes', () => { + const proxy = new Proxy( + {}, + { + ownKeys: () => { + throw new Error('private'); + }, + } + ); + expect(extractLogAttributes(proxy)).to.deep.equal({ + rejectedCount: 0, + reason: 'structured_log_inspection_failed', + }); + }); +}); diff --git a/test/types/index.test.ts b/test/types/index.test.ts index 94ea8f7..c205145 100644 --- a/test/types/index.test.ts +++ b/test/types/index.test.ts @@ -101,3 +101,20 @@ void invalidServiceBusTopicTriggerOptions; void registerServiceBusTopic; void validHandlerAssignableToAvad; void invalidHandlerAssignableToAvad; + +const structuredLogSetup: import('../../types').SetupOptions = { structuredLogProperties: 'lastPlainObject' }; +const structuredLogHook: import('../../types').LogHookOptions = { structuredLogProperties: true }; +const structuredAttributes: import('../../types').LogHookContextInit = { + attributes: { model: 'olive', attempts: 2, enabled: true }, +}; +void structuredLogSetup; +void structuredLogHook; +void structuredAttributes; +// @ts-expect-error Only the explicit final-object mode is supported. +const invalidStructuredSetup: import('../../types').SetupOptions = { structuredLogProperties: 'allObjects' }; +const invalidStructuredAttributes: import('../../types').LogHookContextInit = { + // @ts-expect-error Structured attributes are flat scalar values. + attributes: { nested: { model: 'olive' } }, +}; +void invalidStructuredSetup; +void invalidStructuredAttributes; diff --git a/types-core/index.d.ts b/types-core/index.d.ts index 7bc1d92..6c7a3b6 100644 --- a/types-core/index.d.ts +++ b/types-core/index.d.ts @@ -10,6 +10,8 @@ declare module '@azure/functions-core' { */ const version: string; + const supportsStructuredLogProperties: boolean | undefined; + /** * The version of the Functions Host */ @@ -58,8 +60,18 @@ declare module '@azure/functions-core' { function registerHook(hookName: 'postInvocation', callback: PostInvocationCallback): Disposable; function registerHook(hookName: 'appStart', callback: AppStartCallback): Disposable; function registerHook(hookName: 'appTerminate', callback: AppTerminateCallback): Disposable; - function registerHook(hookName: 'log', callback: LogHookCallback): Disposable; - function registerHook(hookName: string, callback: HookCallback): Disposable; + function registerHook(hookName: 'log', callback: LogHookCallback, options?: LogHookOptions): Disposable; + function registerHook(hookName: string, callback: HookCallback, options?: LogHookOptions): Disposable; + + interface LogHookOptions { + structuredLogProperties?: boolean; + } + + type LogAttributes = Readonly>; + + interface LogMetadata { + readonly attributes: LogAttributes; + } type HookCallback = (context: HookContext) => unknown; type PreInvocationCallback = (context: PreInvocationContext) => void | Promise; @@ -149,6 +161,8 @@ declare module '@azure/functions-core' { type AppTerminateContext = HookContext; interface LogHookContext extends HookContext { + readonly attributes?: LogAttributes; + /** * If the log occurs during a function execution, the context object passed to the function handler. * Otherwise, undefined. @@ -214,7 +228,7 @@ declare module '@azure/functions-core' { * The recommended way to log information outside the context of an invocation * During an invocation, use `CoreInvocationContext.log` instead */ - function log(level: RpcLogLevel, category: RpcLogCategory, message: string): void; + function log(level: RpcLogLevel, category: RpcLogCategory, message: string, metadata?: LogMetadata): void; /** * A set of information and methods that describe the model for handling a Node.js function app @@ -271,7 +285,7 @@ declare module '@azure/functions-core' { /** * The recommended way to log information */ - log(level: RpcLogLevel, category: RpcLogCategory, message: string): void; + log(level: RpcLogLevel, category: RpcLogCategory, message: string, metadata?: LogMetadata): void; } type InvocationState = 'preInvocationHooks' | 'postInvocationHooks' | 'invocation'; diff --git a/types/hooks/logHooks.d.ts b/types/hooks/logHooks.d.ts index a223c59..6321393 100644 --- a/types/hooks/logHooks.d.ts +++ b/types/hooks/logHooks.d.ts @@ -30,6 +30,9 @@ export declare class LogHookContext extends HookContext { */ readonly category: LogCategory; + /** Flat properties supplied by an invocation with structured logging enabled. */ + readonly attributes?: Readonly>; + /** * Changes to this value _will_ affect the resulting log, but only for user-generated logs. */ @@ -53,6 +56,13 @@ export interface LogHookContextInit extends HookContextInit { category?: LogCategory; message?: string; + + attributes?: Readonly>; } export type LogCategory = 'user' | 'system' | 'customMetric'; + +export interface LogHookOptions { + /** Declare that this hook exports structured attributes using a configured exporter. */ + structuredLogProperties?: boolean; +} diff --git a/types/hooks/registerHook.d.ts b/types/hooks/registerHook.d.ts index c736687..5d6ef52 100644 --- a/types/hooks/registerHook.d.ts +++ b/types/hooks/registerHook.d.ts @@ -4,7 +4,7 @@ import { Disposable } from '../index'; import { AppStartHandler, AppTerminateHandler } from './appHooks'; import { PostInvocationHandler, PreInvocationHandler } from './invocationHooks'; -import { LogHookHandler } from './logHooks'; +import { LogHookHandler, LogHookOptions } from './logHooks'; /** * Register a hook to be run at the start of your application @@ -47,4 +47,4 @@ export function postInvocation(handler: PostInvocationHandler): Disposable; * @param handler the handler for the hook * @returns a `Disposable` object that can be used to unregister the hook */ -export function log(handler: LogHookHandler): Disposable; +export function log(handler: LogHookHandler, options?: LogHookOptions): Disposable; diff --git a/types/setup.d.ts b/types/setup.d.ts index 92af251..25c0996 100644 --- a/types/setup.d.ts +++ b/types/setup.d.ts @@ -2,6 +2,9 @@ // Licensed under the MIT License. export interface SetupOptions { + /** Copy flat properties from the final plain-object log argument into log hook attributes. Disabled by default. */ + structuredLogProperties?: 'lastPlainObject'; + /** * Stream http requests and responses instead of loading entire body in memory. * [Learn more here](https://aka.ms/AzFuncNodeHttpStreams) From 1dca976132c124cd0e35807143acde896ef7eeb5 Mon Sep 17 00:00:00 2001 From: User Date: Tue, 29 Sep 2026 11:41:55 +0200 Subject: [PATCH 2/2] #477 - Restrict structured options to log hook registration --- src/hooks/registerHook.ts | 4 +++- types-core/index.d.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hooks/registerHook.ts b/src/hooks/registerHook.ts index fa4ed4f..6e88c4a 100644 --- a/src/hooks/registerHook.ts +++ b/src/hooks/registerHook.ts @@ -35,7 +35,9 @@ function registerHook( ); }); } else { - return options ? coreApi.registerHook(hookName, callback, options) : coreApi.registerHook(hookName, callback); + return hookName === 'log' && options + ? coreApi.registerHook(hookName, callback, options) + : coreApi.registerHook(hookName, callback); } } diff --git a/types-core/index.d.ts b/types-core/index.d.ts index 6c7a3b6..97fa17e 100644 --- a/types-core/index.d.ts +++ b/types-core/index.d.ts @@ -61,7 +61,7 @@ declare module '@azure/functions-core' { function registerHook(hookName: 'appStart', callback: AppStartCallback): Disposable; function registerHook(hookName: 'appTerminate', callback: AppTerminateCallback): Disposable; function registerHook(hookName: 'log', callback: LogHookCallback, options?: LogHookOptions): Disposable; - function registerHook(hookName: string, callback: HookCallback, options?: LogHookOptions): Disposable; + function registerHook(hookName: string, callback: HookCallback): Disposable; interface LogHookOptions { structuredLogProperties?: boolean;