Enable Application Insights With Open Telemetry in Azure Functions

I am trying to create an Azure Function with typescript. I am fairly new to both. I followed the docs and create one Azure function using the steps mentioned in the Azure Docs.

Docs:
AppInsight-Typescript
HOST.json
Azure function With Typecript

When I created the function using Httptrigger template it worked just fine. I was able to access httptrigger and got the Hello World! in response. I am using programming model v4, host.json v2, Runtime worker: node, worker runtime version is ~4 and node version 20.

My current directory structure is as follows:

az-createquote-functionapp/
├── .vscode/
├── dist/
├── node_modules/
├── src/
│   ├── functions/
│   │   └── createQuoteHttp.ts
│   ├── index.ts
│   └── telemetry.ts
├── .gitignore
├── .funcignore
├── eslint.config.js
├── host.json
├── local-settings.json
├── package-lock.json
├── package.json
└── tsconfig.json
My tsconfig.json:
{
  "compilerOptions": {
    "module": "ESNext",
    "target": "ESNext",
    "moduleResolution": "Node",
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "forceConsistentCasingInFileNames": true,
  },
  "include": [
    "./**/*.ts",
  ],
  "exclude": [
    "node_modules",
    "dist"
  ]
}
My package.json
{
  "name": "az-createquote-functionapp",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "build": "tsc",
    "watch": "tsc -w",
    "clean": "rimraf dist",
    "prestart": "npm run clean && npm run build",
    "start": "func start  --verbose",
    "lint": "eslint '**/*.{js,mjs,cjs,ts}'",
    "lint:fix": "eslint '**/*.{js,mjs,cjs,ts}' --fix",
    "test": "echo "No tests yet...""
  },
  "dependencies": {
    "@azure/functions": "^4.5.0",
    "@azure/functions-opentelemetry-instrumentation": "^0.1.0",
    "@azure/monitor-opentelemetry-exporter": "^1.0.0-beta.24",
    "@azure/openapi": "^3.0.104",
    "@opentelemetry/api": "^1.9.0",
    "@opentelemetry/auto-instrumentations-node": "^0.49.1",
    "@opentelemetry/exporter-trace-otlp-http": "^0.52.1",
    "@opentelemetry/sdk-node": "^0.52.1"
  },
  "devDependencies": {
    "@eslint/js": "^9.8.0",
    "@types/node": "^20.x",
    "eslint": "^9.8.0",
    "globals": "^15.9.0",
    "rimraf": "^5.0.0",
    "typescript": "^4.0.0",
    "typescript-eslint": "^8.0.0"
  },
  "overrides": {
    "eslint": "^9.8.0"
  },
  "type": "module",
  "main": "dist/src/{index.js,functions/*.js}"
}
//index.ts
import "./telemetry";
import { app } from '@azure/functions';

app.setup({
    enableHttpStream: true,
});
//telemetry.ts
import { AzureFunctionsInstrumentation } from '@azure/functions-opentelemetry-instrumentation';
import { AzureMonitorLogExporter, AzureMonitorTraceExporter } from '@azure/monitor-opentelemetry-exporter';
import { getNodeAutoInstrumentations, getResourceDetectors } from '@opentelemetry/auto-instrumentations-node';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { detectResourcesSync } from '@opentelemetry/resources';
import { LoggerProvider, SimpleLogRecordProcessor } from '@opentelemetry/sdk-logs';
import { NodeTracerProvider, SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';

const resource = detectResourcesSync({ detectors: getResourceDetectors() });

const tracerProvider = new NodeTracerProvider({ resource });
tracerProvider.addSpanProcessor(new SimpleSpanProcessor(new AzureMonitorTraceExporter()));
tracerProvider.register();

const loggerProvider = new LoggerProvider({ resource });
loggerProvider.addLogRecordProcessor(new SimpleLogRecordProcessor(new AzureMonitorLogExporter()));

registerInstrumentations({
    tracerProvider,
    loggerProvider,
    instrumentations: [getNodeAutoInstrumentations(), new AzureFunctionsInstrumentation()],
});
// my http trigger
import { app, HttpRequest, HttpResponseInit, InvocationContext } from "@azure/functions";

export async function createQuoteHttp(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
    context.log(`Http function processed request for url "${request.url}"`);

    const name = request.query.get('name') || await request.text() || 'world';

    return { body: `Hello, ${name}!` };
};

app.http('createQuoteHttp', {
    route: 'V1/createQuote',
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    handler: createQuoteHttp
});

As soon as I added telemetry, I started getting error

Error [ERR_MODULE_NOT_FOUND]: Worker was unable to load entry point "dist/src/index.js": Cannot find module '/x/y/projects/az-createquote-functionapp/dist/src/telemetry'. 

However, files are present in the correct location in the dist folder. Trigger with default template works but as soon as I try to create any directory or other files and import it either in the index.ts or in my trigger.ts. I start getting this error. I need to build lot of files and directories to seggregate logics but I am not why it is failing.

Here is the exact error:

I am trying to build an API using Azure function with typescript. I tried changing Node versions. I tried changing model to “CommonJS”. I tried adding telemetry code in index.ts itself but not sure if I even know the right cause. I am fairly new to both Azure and Typescript so I am trying to implement this using official documentation.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật