typescriptazure-functionsazure-functions-runtimeoctokit-js

How to problem-solve Octokit crashing Azure Typescript Function App


I have an Azure Function App:

host.json bundle version:

"extensionBundle": {
  "id": "Microsoft.Azure.Functions.ExtensionBundle",
  "version": "[4.0.0, 5.0.0)"
}

Node version: 20 with Bicep setting correct extension and node version:

{
  name: 'FUNCTIONS_EXTENSION_VERSION'
  value: '~4'
}
{
  name: 'WEBSITE_NODE_DEFAULT_VERSION'
  value: '~20'
}

Cloud Runtime version: 4.1039.400.25216

Package.json dependancies:

"dependencies": {
  "@apidevtools/swagger-parser": "^10.1.0",
  "@azure/communication-email": "^1.0.0",
  "@azure/event-hubs": "^5.12.0",
  "@azure/functions": "^4.0.0-alpha.7",
  "@azure/identity": "^3.2.3",
  "@azure/keyvault-secrets": "^4.7.0",
  "@azure/storage-blob": "^12.24.0",
  "@azure/web-pubsub": "^1.1.1",
  "@octokit/rest": "^21.1.1",
  "@types/node-fetch": "^2.6.2",
  "@types/tedious": "^4.0.9",
  "applicationinsights": "^2.7.0",
  "jsonwebtoken": "^9.0.2",
  "lodash": "^4.17.21",
  "moment": "^2.29.4",
  "node-fetch": "^2.6.8",
  "octokit": "^4.1.3",
  "sequelize": "^6.32.1",
  "superagent": "^8.1.2",
  "swagger-jsdoc": "^6.2.8",
  "tedious": "^16.1.0",
  "tsconfig-paths": "^4.2.0",
  "uuid": "^9.0.0"
},
"devDependencies": {
  "@types/lodash": "^4.14.195",
  "@types/node": "^20.17.30",
  "@types/sequelize": "^4.28.15",
  "@types/uuid": "^9.0.2",
  "license-check-and-add": "^4.0.5",
  "typescript": "~5.1.3"
},

The function runs locally in VS Code perfectly fine, but when I deploy it to Azure, the instantiation of Octokit makes all functions fail to start.

Is there a way I can get lower level log information to see what kind of conflict might be going on?

The function:

import { app, HttpResponseInit, InvocationContext } from '@azure/functions';
import { Log, IRequest } from '@cashikoi/viewdu-fxa-lib';

export async function featurePublish(request: IRequest, context: InvocationContext): Promise<HttpResponseInit> {
    
    // so we need to setup Log manually.
    context.log(`>>> Http function processed request for url "${request.url}"`);
    
    try {
        
        // const octokit = new Octokit({ auth: githubPat });

        return {
            status: 200,
            jsonBody: {
            success: true,
            message: `Test.`,
            },
        };
        
    } catch (error: any) {
        context.error("Error in GitHub integration:", error.message || error);
        return {
            status: 500,
            jsonBody: {
            success: false,
            error: error.message || error.toString(),
            },
        };
    }

};

app.http('feature-publish', {
    methods: ['POST'],
    authLevel: 'function',
    handler: featurePublish
});

If I uncomment the following line then all functions in the function app fail to load (and be listed on the Function App resource within the Azure portal:

// const octokit = new Octokit({ auth: githubPat });

If I re-comment the line out again and re-deploy to Azure, then all of the functions list as expected in the portal.

As mentioned, the function works correctly when run locally in VS Code.

I welcome any insight into how to solve this please.


Solution

  • I upgraded the version of octokit and seems to have resolved the problem:

    "@octokit/rest": "^22.0.0"