Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 functions are not being found in portal, local works #297

Closed
Venipa opened this issue Aug 30, 2024 · 4 comments
Closed

v4 functions are not being found in portal, local works #297

Venipa opened this issue Aug 30, 2024 · 4 comments

Comments

@Venipa
Copy link

Venipa commented Aug 30, 2024

After deploying through azure devops pipeline with zip deploy and run there were no functions to be found on our productive and beta function app but somehow our dev function app is able to find them?

also locally the functions are loaded and working well

Investigative information

Please provide the following:
unable to get function invocation, no logs

Repro steps

package.json
{
...
"main": "dist/src/functions/*/index.js",
...
}
tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true,
    "strict": false,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "baseUrl": "./",
    "paths": {
      "@shared": [
        "./src/shared"
      ],
      "@shared/*": [
        "./src/shared/*"
      ],
      "@src": [
        "./src"
      ],
      "@src/*": [
        "./src/*"
      ],
      "@models": [
        "./src/models"
      ],
      "@models/*": [
        "./src/models/*"
      ],
      "@func": [
        "./src/functions"
      ],
      "@func/*": [
        "./src/functions/*"
      ]
    }
  },
  "include": [
    "src/**/*.ts"
  ]
}
build.cjs
const esbuild = require("esbuild");
const { globSync } = require('glob');
const path = require("path");
const entryPoints = new Map(globSync(["src/functions/*/index.ts"]).map((p) => [path.join(path.dirname(p), "index"), p]));
console.log("entryPoints:", entryPoints);
esbuild.buildSync({
  entryPoints: Object.fromEntries(entryPoints),
  outdir: "dist",
  target: "es6",
  format: "esm",
  platform: "node",
  bundle: true,
  splitting: true,
  external: ["@azure/functions-core", "os", "fs", "crypto", "path"],
  chunkNames: "chunks/[name]-[hash]",
  banner: {
    js: `
/**
 * Top level helpers and replacements to dynamic require and node const 
 */
import { fileURLToPath } from 'url';
import { createRequire as topLevelCreateRequire } from 'module';
import { dirname as ddirname } from 'path';
const require = topLevelCreateRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = ddirname(__filename);
/**
 * Top level helpers end 
 */
    `
  }
})

functions are placed like this in dist
src/functions/[function name]/index.ts => dist/src/functions/[function name]/index.js

Expected behavior

expected my functions to be found

Actual behavior

dev azure functions app found all functions, pre production & production environment are unable to find the function

Known workarounds

none

Related information

  • Programming language used: node 18, typescript
  • Example Function
src/functions/health/index.ts
import environment from "@shared/environment";
import pkg from "../../../package.json";

export default createRawFunction("health", async function (ctx) {
  return response().json({
    functionVersion: {
      clientSdk: pkg.dependencies["@azure/functions"],
      runtime: environment.FUNCTIONS_EXTENSION_VERSION
    },
    enabled_i18n: environment.I18N_ENABLED_LANGKEYS,
  });
});
// createRawFunction from our helper file
export function createRawFunction(pathOrFunctionName: string, azureFn: AzureFunction, config?: Omit<HttpFunctionOptions, "handler">) {
  const functionRunner = async function createFunctionInner(ctx: Context, ...args: any[]) {
    try {
      const data = await azureFn(ctx, ...args);
      if (data instanceof TResponse) {
        if (!data.headers) data.headers = {};
        if (data.requestCharge > 0) data.headers.requestCharge = data.requestCharge;
        if (data.data instanceof Writable) {
          return responseRaw(data.data, data.status, data.headers);
        }
        return responseJson(data.data, data.status, data.headers);
      } else {
        return responseJson(data);
      }
    } catch (e) {
      await SentryInit.captureException(e);
    }
  }; try {
    app.http(pathOrFunctionName, {
      handler: async (req, ctx, ...args) => functionRunner(ctx, req, ...args),
      ...Object.assign({ authLevel: "anonymous", methods: ["GET", "POST"] } as HttpFunctionOptions, config ?? {}),
    });
  } catch (ex) {
    if (ex instanceof Error && ex.message.indexOf("has already been registered") !== -1) return;
    throw ex;
  }
}
@ejizba
Copy link
Contributor

ejizba commented Aug 30, 2024

Hi @Venipa can you please share your function app name? Here are instructions on how to do it privately if you don't want to post it publicly: https://github.com/Azure/azure-functions-host/wiki/Sharing-Your-Function-App-name-privately

@Venipa
Copy link
Author

Venipa commented Aug 30, 2024

Hi @Venipa can you please share your function app name? Here are instructions on how to do it privately if you don't want to post it publicly: https://github.com/Azure/azure-functions-host/wiki/Sharing-Your-Function-App-name-privately

@ejizba
<redacted>.azurewebsites.net

@ejizba
Copy link
Contributor

ejizba commented Aug 30, 2024

Hi I'm seeing this error when starting up your app:

E_INVALID_APP_KEY: Invalid App Secret

I would double check all your app settings and make sure they're valid.

In addition, if you query your app insights logs, I believe this error should be visible:

let myAppName = "api-timeghost-beta";
let startTime = ago(1d);
let endTime = now();
union traces,requests,exceptions
| where cloud_RoleName =~ myAppName
| where timestamp between (startTime .. endTime)
| where severityLevel > 2

@Venipa
Copy link
Author

Venipa commented Aug 30, 2024

thanks, since my log stream was not working i was unable to get any logs about the startup, i was missing a env variable providing a app secret for encrypting payloads

functions are being listed now, thanks 👍

@Venipa Venipa closed this as completed Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants