Transitioning Azure Function from version 3 to version 4

Looking to transition from v3 to v4 with the help of this documentation: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=python-v2%2Cisolated-process%2Cnodejs-v3%2Cfunctionsv2&pivots=programming-language-typescript

My goal is to update the code below to match v4 specifications.

In v3:

import { AzureFunction, Context, HttpRequest } from "@azure/functions"

const cgHttpTrigger: AzureFunction = async (
  context: any,
  req: any,
  httpTrigger: AzureFunction
) => {
  return appInsights.wContext(async () => {
    const startTime = Date.now() // Start trackRequest timer

    // Execute the Function
    await httpTrigger(context, req)

    // Track Request upon completion
    a.d.trackRequest({
      name: context.req.method + " " + context.req.url,
      resultCode: context.res.status,
  }, correlationContext ?? undefined)()
}

Attempting to incorporate version 4 functions and wrapping the above function accordingly.

In v4:

import { app} from '@azure/functions';

app.http('appIn', {
  methods: ['GET', 'POST'],
  handler: cgHttpTrigger(httpTrigger),
});

Is there a way to wrap this in a format like:

handler:  async (req, context) => {return cgHttpTrigger(req, context, (req, context) => {....})} 

Additional Resources:

https://www.npmjs.com/package/applicationinsights/v/2.0.0-beta.200831.1

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=python-v2%2Cisolated-process%2Cnodejs-v3%2Cfunctionsv2&pivots=programming-language-typescript using this documentation

Answer №1

It has been recommended that we transition to @azure/monitor-opentelemetry. The rationale behind this decision is outlined in a Github issue at github.com/microsoft/ApplicationInsights-node.js/issues/…, which states that the applicationinsights package currently only accommodates v3 and work on supporting v4 is still in progress.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you show me the steps for linking the next method of an EventEmitter?

After emitting an event, I am looking to run some additional code. Is there a method to chain the .next() function in this way? @Output() myEvent = new EventEmitter<string>(); this.myEvent.next({‘test string’}).onComplete(console.log('done& ...

Invoking a function within an Angular component

I am facing a problem - is there a way to invoke a function from the name.component.html file without using a button click, and without needing to go through the .ts file or service? ...

OnPush strategy and template updates: Propagating modifications to the parent component

I am currently facing an issue with a parent component that consists of two templates. The first template simply displays data-bound text, while the second template contains a child component responsible for updating the data model. Both the parent and chi ...

Typescript's spellbinding courses

I'm encountering some issues with Typescript and the "@botstan/Magic" library in nodejs. Before we proceed, please take a look at the "Magic" documentation. Follow these lines: import Magic from "@botstan/magic"; import * as _ from "lodash"; @ ...

Troubleshooting Axios errors when using createAsyncThunk function

Can someone help me with handling errors in createAsyncThunk using TypeScript? I attempted to declare the returned type and params type with generics, but when it came to error handling typing, I found myself resorting to just using 'any'. Let& ...

Modifying Array Values in Angular 7

I am currently dealing with a complex array where questions and their corresponding answers are retrieved from a service. Upon receiving the array, I aim to set the 'IsChecked' attribute of the answers to false. The snippet of code I have written ...

Link the ngModel input to an object within an ngFor iteration

Looking to create a dynamic form using an array that includes FieldLabel and DataModel references. I want to use the DataModel as an object reference, so when the user updates an input field, the referenced model is updated. I have searched extensively bu ...

Filtering rows in angular based on the current data's id

currData = { id: "iStyle1", status: "PENDING" }; data = [ { id: "splitStyle1", rows: [ { id: "1cUMlNRSapc5T", row: 2, sequence: 2, status: ...

Utilize TypeScript to access a function from a different module

Currently in the process of migrating a Nodejs project from JavaScript to TypeScript, I encountered an error that was not present when using JavaScript. The issue arises when attempting to access functions defined in a separate module from another module, ...

How come the information transferred from Firebase to Google Sheets is displaying only in the initial row of the spreadsheet?

Currently, I am facing an issue while attempting to transfer data from Firebase to Google Sheets. I have utilized the push() method to insert the data into a variable and referenced it in "resource {values: duplicitiesWithJudicialCharges}". Despite knowin ...

Constructing a hierarchical tree structure using an array of objects that are initially flat

My goal is to create a hierarchical tree structure from a flat array: The original flat array looks like this: nodes = [ {id: 1, pid: 0, name: "kpittu"}, {id: 2, pid: 0, name: "news"}, {id: 3, pid: 0, name: "menu"}, {id: 4, pid: 3, name: ...

The Microsoft EDGE browser is encountering a XHR HTTP404 error when trying to access a TypeScript

While debugging a Typescript web application in Visual Studio 2015 and using the Microsoft EDGE browser, an error is reported as follows: HTTP404: NOT FOUND - The server cannot locate anything that matches the requested URI (Uniform Resource Identifier). ...

Inoperative due to disability

Issue with Disabling Inputs: [disabled] = true [disabled] = "isDisabled" -----ts > ( isDisabled=true) Standard HTML disabler disable also not functioning properly [attr.disabled] = true [attr.disabled] = "isDisabled" -----ts > ( isDisabled=true) ...

struggling to access the value of [(ngModel)] within Angular 6 component

When working in an HTML file, I am using ngModel to retrieve a value that I want to utilize in my component. edit-customer.component.html <input id="userInfoEmail" type="text" class="form-control" value="{{userInfo.email}}" [(ngModel)]="userInfo.email ...

Ways to extract information from an Object and save it into an array

In my Angular2 project, I am working on retrieving JSON data to get all the rooms and store them in an array. Below is the code for the RoomlistService that helps me fetch the correct JSON file: @Injectable() export class RoomlistService { constructor( ...

Encountering issues following the integration of @angular/flex-layout into an Angular project

After careful consideration, I opted to utilize the responsive grid system provided by @angular/flex-layout instead of Bootstrap. By simply installing the npm package and adding it to my AppModule, I was able to integrate it seamlessly: import { NgModule ...

Please click twice in order to log in to Angular 16

Whenever I attempt to log in, I face the issue of having to click twice. The first click does not work, but the second one does. Additionally, an error message pops up: TypeError: Cannot read properties of undefined (reading 'name'). I am unsure ...

Can I implement react-router's useHistory() or React's useState method alongside withFormik?

Utilizing withFormik in my registration form. const RegistrationContainer = compose<InnerProps, OuterProps>( withFormik<InnerProps, RegistrationValues>({ mapPropsToValues: () => RegistrationSchema.cast(), validationSchema: Registra ...

What is the best way to assign the result of a promise to a variable?

My code includes an async function that retrieves a value async fetchUserName(environment: string, itemName: string, authToken: string): Promise<any> { let result = await this.obtainDeviceName(environment, itemName, authToken); return ...

Building a React application using TypeScript has the benefit of more robust type checking and error prevention

Exploring the world of React with TypeScript has been quite engaging I can't help but ponder if it's feasible to create a separate file solely for compiler options, similar to tsconfig.json in Angular. For example, how would one configure "str ...