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

Agent-based monitoring causes _a.context is not a function error #17471

Closed
1 of 6 tasks
rodolfograve opened this issue Sep 6, 2021 · 11 comments
Closed
1 of 6 tasks

Agent-based monitoring causes _a.context is not a function error #17471

rodolfograve opened this issue Sep 6, 2021 · 11 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. Monitor Monitor, Monitor Ingestion, Monitor Query

Comments

@rodolfograve
Copy link

rodolfograve commented Sep 6, 2021

  • Package Name: @azure/identity, @azure/storage-blob
  • Package Version: 1.5.2, 12.7.0
  • Operating system: Linux (Azure App Service)
  • nodejs
    • version: 12-lts
  • browser
    • name/version: N/A
  • typescript
    • version: N/A
  • Is the bug related to documentation in

Describe the bug
Attempting an operation that requires a token will fail if Agent-based monitoring is enabled on the App Service.

The exact same code works OK on a local development environment.

To Reproduce
Steps to reproduce the behavior:

  1. Create an Azure App Service - Linux
  2. Enable Agent-based monitoring
  3. Deploy a simple application that includes the following code:
// The same behaviour occurs using the empty constructor or providing a valid tenantId below.
  const credential = new DefaultAzureCredential()

// I'm using storage here but any action that triggers a call to credential.getToken will do
  const blobServiceClient = new BlobServiceClient('https://irrelevant-for-repro.blob.core.windows.net', credential)
  await blobServiceClient.getProperties()

Expected behavior
The operation successfully obtains the token from the credential and fails or succeeds according to the permissions of the account.

Related issues
There seem to be several related issues (#13798, #16056) but the fixes there rely on upgrading the version of the appinsights and/or opentelemetry modules. However, when using the Agent-based monitoring option the developers have no control over the version of those packages.

Additional context
Stack trace of the error

"TypeError: _a.context is not a function\n at Object.getSpanContext (/agents/node/node_modules/@opentelemetry/api/build/src/context/context.js:70:76)\n at getParent (/agents/node/node_modules/@opentelemetry/tracing/build/src/Tracer.js:101:16)\n at Tracer.startSpan (/agents/node/node_modules/@opentelemetry/tracing/build/src/Tracer.js:49:31)\n at Tracer.tracer.startSpan (/agents/node/node_modules/diagnostic-channel-publishers/dist/src/azure-coretracing.pub.js:55:44)\n at /home/site/wwwroot/node_modules/@azure/core-tracing/dist/index.js:471:29\n at DefaultAzureCredential.<anonymous> (/home/site/wwwroot/node_modules/@azure/identity/dist/index.js:247:58)\n at Generator.next (<anonymous>)\n at /home/site/wwwroot/node_modules/@azure/identity/node_modules/tslib/tslib.js:117:75\n at new Promise (<anonymous>)\n at Object.__awaiter (/home/site/wwwroot/node_modules/@azure/identity/node_modules/tslib/tslib.js:113:16)\n at DefaultAzureCredential.getToken (/home/site/wwwroot/node_modules/@azure/identity/dist/index.js:244:22)\n at tryGetAccessToken (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:3800:56)\n at tryGetAccessToken (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:3730:38)\n at beginRefresh (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:3738:23)\n at refresh (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:3803:29)\n at /home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:3833:20\n at BearerTokenAuthenticationPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:3859:37)\n at DisableResponseDecompressionPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:4385:33)\n at ProxyPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:4086:33)\n at LogPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:2837:37)\n at DeserializationPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:3020:33)\n at StorageRetryPolicy.attemptSendRequest (/home/site/wwwroot/node_modules/@azure/storage-blob/dist/index.js:14657:47)\n at StorageRetryPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/storage-blob/dist/index.js:14629:21)\n at StorageBrowserPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/storage-blob/dist/index.js:14544:37)\n at GenerateClientRequestIdPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:3417:33)\n at TelemetryPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/storage-blob/dist/index.js:14893:33)\n at KeepAlivePolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:4230:33)\n at TracingPolicy.sendRequest (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:4257:37)"},"msg":"undefined","time":"2021-09-06T08:31:37.314Z","v":0}

Output of npm ls @opentelemetry/api
image

package.json

  "dependencies": {
    "@azure/identity": "^1.5.1",
    "@azure/storage-blob": "^12.7.0",
    "@koa/cors": "^2.2.1",
    "axios": "^0.21.1",
    "camelcase-keys": "^5.0.0",
    "config": "^3.3.6",
    "exceljs": "^3.8.0",
    "jsonwebtoken": "^8.3.0",
    "koa": "^2.5.1",
    "koa-compress": "^3.0.0",
    "koa-joi-router": "^5.1.0",
    "koa-joi-router-docs": "^0.1.9",
    "koa-logger": "^3.2.0",
    "koa-respond": "^1.0.1",
    "lodash": "^4.17.21",
    "moment": "^2.29.1",
    "snakecase-keys": "^2.1.0",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "eslint": "^7.25.0",
    "eslint-config-prettier": "^8.3.0",
    "faker": "^4.1.0",
    "jest": "^26.6.3",
    "jest-junit": "^12.0.0",
    "lint-staged": "^10.5.4",
    "nodemon": "^2.0.2",
    "rosie": "^2.0.1",
    "supertest": "^3.3.0"
  },

@rodolfograve rodolfograve changed the title Agent-based monitoring causes [@azure/storage-blob] _a.context is not a function error Agent-based monitoring causes _a.context is not a function error Sep 6, 2021
@maorleger
Copy link
Member

@rodolfograve thanks for reaching out! If I understand correctly things are working as expected locally and in deployment until you turn on Agent based Application Insights monitoring - correct?

If so, I'm not too familiar with how Agent Based monitoring works - @hectorhdzg do you know who would be a good contact to look at this from the Application Insights team? It does sound like there's some dependency mismatch when using no-code monitoring but I wouldn't know where to begin.

@maorleger maorleger assigned maorleger and hectorhdzg and unassigned maorleger Sep 6, 2021
@rodolfograve
Copy link
Author

Thanks @maorleger. That is correct.

Let me know if more information is needed. I'm looking forward to some solution to this issue :-)

@maorleger maorleger added Client This issue points to a problem in the data-plane of the library. Monitor Monitor, Monitor Ingestion, Monitor Query labels Sep 7, 2021
@rodolfograve
Copy link
Author

Any updates on this? At the very least I would expect some modifications need to be made to the documentation of Agent-based monitoring.

If this is not the right place to ask, do you think you can point me in the right direction?

Cheers

@spawnrider
Copy link

Same issue too on Azure App Services with App Insights turned on :
**
image
**

Disabling App Insights seems to solve the issue.

@rodolfograve
Copy link
Author

I can confirm that disabling Agent-based monitoring fixes the issue.

@hectorhdzg
Copy link
Member

Issue is caused by Application Insights node.js SDK version loaded in the agent, to keep getting telemetry you can turn off Azure SDK automatic instrumentation using an App Setting like this one APPLICATION_INSIGHTS_NO_PATCH_MODULES=azuresdk https://github.com/microsoft/ApplicationInsights-node.js#automatic-third-party-instrumentation, we are working on updating Agent code to use latest version of the SDK where this already fixed but we don't have an ETA yet.

@arc9693
Copy link

arc9693 commented Sep 20, 2021

We faced the same issue.

  • Package Name and versions:
    "@azure/identity": "^1.2.2",
    "@azure/storage-blob": "^12.1.2"
  • Operating system: Linux (Azure App Service)
  • nodejs version: 12-lts

@fwang0
Copy link

fwang0 commented Sep 20, 2021

Same issue for us:

  • package name and versions.
    "@azure/identity": "^1.3.0",
    "@azure/storage-blob": "^12.5.0",
  • OS: linux (Azure App Service), docker based deployment
  • nodejs version 12-lts

The issue started on Aug 21 ( or later Aug 20), app service deployed in EastUS2 region.
Disabling App Insight solved this issue.

@hectorhdzg
Copy link
Member

@arc9693, @fwang0 please disable Azure SDK auto instrumentation with instructions provided here adding that will allow you to still get Application Insights telemetry, we are working on pushing newer version of the SDK to Azure App Services but this usually takes several weeks. Manually instrumenting the App with Application Insights latest version also will solve the issue but I understand is not always an option.

@fwang0
Copy link

fwang0 commented Sep 21, 2021

@hectorhdzg Thanks! The instruction works for us. Please let us know when the new version of SDK is pushed to Azure App Services.

@hectorhdzg
Copy link
Member

Azure App Services should have version of the SDK with the fix

@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. Monitor Monitor, Monitor Ingestion, Monitor Query
Projects
None yet
Development

No branches or pull requests

6 participants