Skip to content

Commit 7f2afaa

Browse files
authored
Add script file properties to function metadata (#646)
1 parent a090cc0 commit 7f2afaa

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/WorkerChannel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class WorkerChannel {
5050
functions: { [id: string]: RegisteredFunction } = {};
5151
workerIndexingLocked = false;
5252
isUsingWorkerIndexing = false;
53+
currentEntryPoint?: string;
5354

5455
constructor(workerId: string, eventStream: IEventStream, legacyFunctionLoader: ILegacyFunctionLoader) {
5556
this.workerId = workerId;

src/coreApi/registerFunction.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
import { FunctionCallback, FunctionMetadata } from '@azure/functions-core';
5+
import * as path from 'path';
56
import { AzureFunctionsRpcMessages as rpc } from '../../azure-functions-language-worker-protobuf/src/rpc';
67
import { Disposable } from '../Disposable';
78
import { AzFuncSystemError } from '../errors';
@@ -27,9 +28,16 @@ export function registerFunction(
2728
rpcMetadata.rawBindings = Object.entries(metadata.bindings).map(([name, binding]) => {
2829
return JSON.stringify({ ...binding, name });
2930
});
30-
// The host validates that the `scriptFile` property is defined even though neither the host nor the worker needs it
31-
// Long term we should adjust the host to remove that unnecessary validation, but for now we'll just set it to 'n/a'
32-
rpcMetadata.scriptFile = 'n/a';
31+
32+
// The host validates that the `scriptFile` property is defined. Neither the host nor the worker needs it, but tooling like the portal may use it so we'll make a best guess
33+
// (The real script file may be a separate file referenced from the entry point, or it may be coming from a different entry point entirely if there are some async shenanigans)
34+
if (channel.currentEntryPoint) {
35+
rpcMetadata.scriptFile = path.basename(channel.currentEntryPoint);
36+
rpcMetadata.directory = path.dirname(channel.currentEntryPoint);
37+
} else {
38+
rpcMetadata.scriptFile = 'unknown';
39+
}
40+
3341
channel.functions[functionId] = { metadata: rpcMetadata, callback };
3442

3543
return new Disposable(() => {

src/startApp.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ async function loadEntryPointFile(functionAppDirectory: string, channel: WorkerC
5555
level: LogLevel.Debug,
5656
logCategory: LogCategory.System,
5757
});
58-
await loadScriptFile(path.join(functionAppDirectory, file), channel.packageJson);
58+
try {
59+
const entryPointFilePath = path.join(functionAppDirectory, file);
60+
channel.currentEntryPoint = entryPointFilePath;
61+
await loadScriptFile(entryPointFilePath, channel.packageJson);
62+
} finally {
63+
channel.currentEntryPoint = undefined;
64+
}
5965
channel.log({
6066
message: `Loaded entry point file "${file}"`,
6167
level: LogLevel.Debug,

0 commit comments

Comments
 (0)