Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.1k stars 1.21k forks source link

[monitor] Type error when using a resource in AzureMonitorOpenTelemetryOptions #28433

Closed TheIceCreamTroll closed 7 months ago

TheIceCreamTroll commented 10 months ago

Describe the bug Using a custom resource in the AzureMonitorOpenTelemetryOptions is prevented due to a type error

To Reproduce

  1. Create a new resource using @opentelemetry/resources
    
    import { AzureMonitorOpenTelemetryOptions, useAzureMonitor } from '@azure/monitor-opentelemetry';
    import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
    import { Resource } from '@opentelemetry/resources';

const customResource = new Resource({

});

2. Initialize a new Azure Monitor instance using the custom resource

const config: AzureMonitorOpenTelemetryOptions = { azureMonitorExporterOptions: { connectionString: process.env.APPLICATIONINSIGHTS_CONNECTION_STRING, }, resource: customResource, };

useAzureMonitor(config);

3. An error will be shown either by the IDE or when trying to run the program

**Expected Behavior**
The resource should be able to be added without the error appearing

**Screenshots**
<img width="714" alt="Screenshot 2024-02-01 at 2 35 53 PM" src="https://github.com/Azure/azure-sdk-for-js/assets/33820904/df2ab1b8-ae60-493b-be4b-57fb486c72f5">

**Additional context**
The relevant packages in my `package.json` are

"@azure/monitor-opentelemetry": "^1.2.0", "@opentelemetry/resources": "^1.21.0", "@opentelemetry/semantic-conventions": "^1.21.0",



Using a resource also works if you use `import { Resource } from '@azure/monitor-opentelemetry-exporter/node_modules/@opentelemetry/resources';` instead of `import { Resource } from '@opentelemetry/resources';`, but I doubt this is the intended import method.
JacksonWeber commented 9 months ago

@TheIceCreamTroll I've tested your example in a sample app using the same dependencies, typescript version, and node version. Using the same code to initialize Azure Monitor I'm not seeing any type errors when ts compiling the project or running the generated js file. Can I take a look at your tsconfig.json and package.json to better recreate your environment?

TheIceCreamTroll commented 9 months ago

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "dist",
    "rootDir": ".",
    "sourceMap": true,
    "strict": false,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "skipLibCheck": true
  }
}

package.json

{
  "name": "",
  "version": "",
  "scripts": {
    "build": "tsc",
    "build:production": "npm run prestart && npm prune --production",
    "watch": "tsc --w",
    "prestart": "npm run build && func extensions install",
    "start:host": "func start",
    "start": "npm-run-all --parallel start:host watch",
    "test": "npx jest --watchAll=true",
    "gen": "graphql-codegen --config codegen.yml",
    "gen:watch": "graphql-codegen --config codegen.yml --watch  --silent=false"
  },
  "description": "",
  "devDependencies": {
    "@graphql-codegen/cli": "^3.3.0",
    "@graphql-codegen/introspection": "^3.0.1",
    "@graphql-codegen/typed-document-node": "^4.0.0",
    "@graphql-codegen/typescript": "^3.0.3",
    "@graphql-codegen/typescript-operations": "^3.0.3",
    "@graphql-codegen/typescript-resolvers": "^3.2.0",
    "@types/jest": "^27.4.0",
    "@types/node": "^18.16.0",
    "jest": "^27.5.1",
    "jest-html-reporter": "^3.6.0",
    "mongodb-memory-server": "^8.3.0",
    "npm-run-all": "^4.1.5",
    "typescript": "^5.1.3"
  },
  "dependencies": {
    "@apollo/cache-control-types": "^1.0.2",
    "@apollo/server": "^4.6.0",
    "@apollo/server-plugin-response-cache": "^4.1.2",
    "@apollo/utils.keyvaluecache": "^3.0.0",
    "@as-integrations/azure-functions": "^0.1.3",
    "@azure/arm-maps": "^3.1.0-beta.1",
    "@azure/cognitiveservices-contentmoderator": "^5.0.1",
    "@azure/functions": "^3.5.1",
    "@azure/identity": "^2.0.4",
    "@azure/monitor-opentelemetry": "^1.2.0",
    "@azure/monitor-opentelemetry-exporter": "^1.0.0-beta.17",
    "@azure/ms-rest-azure-js": "^2.1.0",
    "@azure/search-documents": "^11.2.1",
    "@azure/storage-blob": "^12.8.0",
    "@graphql-tools/graphql-file-loader": "^7.3.3",
    "@graphql-tools/load": "^7.5.1",
    "@graphql-tools/load-files": "^6.5.3",
    "@graphql-tools/schema": "^8.3.1",
    "@graphql-tools/stitch": "^8.4.3",
    "@lucaspaganini/value-objects": "^1.3.1",
    "@opentelemetry/api": "^1.7.0",
    "@opentelemetry/api-logs": "^0.48.0",
    "@opentelemetry/instrumentation": "^0.48.0",
    "@opentelemetry/instrumentation-bunyan": "^0.35.0",
    "@opentelemetry/instrumentation-dataloader": "^0.5.4",
    "@opentelemetry/instrumentation-graphql": "^0.36.1",
    "@opentelemetry/instrumentation-http": "^0.48.0",
    "@opentelemetry/instrumentation-mongodb": "^0.38.1",
    "@opentelemetry/resources": "^1.21.0",
    "@opentelemetry/sdk-logs": "^0.48.0",
    "@opentelemetry/sdk-trace-base": "^1.21.0",
    "@opentelemetry/semantic-conventions": "^1.21.0",
    "@types/archiver": "^5.3.1",
    "apollo-datasource-mongodb": "^0.6.0",
    "archiver": "^5.3.1",
    "async-retry": "^1.3.3",
    "axios": "^1.3.6",
    "bunyan": "^1.8.15",
    "dayjs": "^1.11.3",
    "graphql": "^16.6.0",
    "graphql-fields": "^2.0.3",
    "graphql-middleware": "^6.1.33",
    "graphql-mongo-fields": "^1.0.6",
    "graphql-scalars": "^1.14.1",
    "graphql-shield": "^7.6.5",
    "jose": "^4.5.0",
    "moment": "^2.29.1",
    "mongoose": "^6.2.1",
    "nanoid": "^3.3.2",
    "openid-client": "^5.1.3",
    "retry": "^0.13.1"
  }
}
JacksonWeber commented 9 months ago

@TheIceCreamTroll The types issue should be resolved by #28459 and will be available in the next Azure Monitor OpenTelemetry release. Thank you again for your issue report!

JacksonWeber commented 7 months ago

Closing as the fix has been released.