DataDog / dd-trace-js

JavaScript APM Tracer
https://docs.datadoghq.com/tracing/
Other
654 stars 309 forks source link

fatal error openai #3337

Closed adoniscyp closed 1 year ago

adoniscyp commented 1 year ago

Expected behaviour

Actual behaviour

Started getting the following error and had to disable tracing. Error from Sentry

I think the issue is because it tries to contact the process on 8126 and for some reason is unable to find it. http http://172.16.131.95:8126/ [404] { http.method: POST }


TypeError: Cannot convert undefined or null to object
  File "<anonymous>", in Function.entries
  File "/app/server/node_modules/dd-trace/packages/datadog-plugin-openai/src/index.js", line 104, col 44, in OpenApiPlugin.start
    for (const [tokenId, bias] of Object.entries(payload.logit_bias)) {
  File "/app/server/node_modules/dd-trace/packages/dd-trace/src/plugins/tracing.js", line 17, col 12, in <anonymous>
    this.start(message)
  File "/app/server/node_modules/dd-trace/packages/dd-trace/src/plugins/plugin.js", line 14, col 9, in Subscription._handler
    handler(message, name)
  File "node:diagnostics_channel", line 56, col 9, in Channel.publish
  File "/app/server/node_modules/dd-trace/packages/datadog-instrumentations/src/openai.js", line 23, col 15, in OpenAIApi.createChatCompletion
    startCh.publish({
  File "/app/server/node_modules/langchain/dist/util/async_caller.js", line 54, col 50, in <anonymous>
    return this.queue.add(() => pRetry(() => callable(...args).catch((error) => {
  File "/app/server/node_modules/p-retry/index.js", line 50, col 18, in RetryOperation._fn
    resolve(await input(attemptNumber));
  File "/app/server/node_modules/p-retry/node_modules/retry/lib/retry_operation.js", line 116, col 8, in RetryOperation.attempt
    this._fn(this._attempts);
  File "/app/server/node_modules/p-retry/index.js", line 48, col 12, in <anonymous>
    operation.attempt(async attemptNumber => { 

Steps to reproduce

Environment Kustomize Version: v5.0.1 Server Version: version.Info{Major:"1", Minor:"24+", GitVersion:"v1.24.14-eks-c12679a", GitCommit:"05d192f0de17608d98e17761ad3cffa9a6407f2f", GitTreeState:"clean", BuildDate:"2023-05-22T23:41:27Z", GoVersion:"go1.19.9", Compiler:"gc", Platform:"linux/amd64"}

"dependencies": {
    "@formkit/auto-animate": "1.0.0-beta.6",
    "@frontegg/nextjs": "7.0.12",
    "@frontegg/react": "^5.0.43",
    "@headlessui/react": "^1.7.14",
    "@heroicons/react": "^2.0.17",
    "@nestjs/axios": "0.1.0",
    "@nestjs/cli": "^9.0.0",
    "@nestjs/common": "^9.0.0",
    "@nestjs/core": "^9.0.0",
    "@nestjs/platform-express": "^9.0.0",
    "@nestjs/schematics": "^9.0.0",
    "@nestjs/testing": "^9.0.0",
    "@prisma/client": "^4.15.0",
    "@prisma/nextjs-monorepo-workaround-plugin": "^4.15.0",
    "@sentry/nextjs": "^7.48.0",
    "@tanstack/react-query": "^4.28.0",
    "@temporalio/activity": "^1.7.4",
    "@temporalio/client": "^1.7.4",
    "@temporalio/common": "^1.7.4",
    "@temporalio/worker": "^1.7.4",
    "@temporalio/workflow": "^1.7.4",
    "@trpc/client": "^10.18.0",
    "@trpc/next": "^10.33.0",
    "@trpc/react-query": "^10.18.0",
    "@trpc/server": "^10.18.0",
    "@ts-rest/core": "^3.26.3",
    "@types/canvas-confetti": "^1.6.0",
    "@types/dagre": "^0.7.48",
    "@types/eslint": "^8.21.3",
    "@types/express": "^4.17.13",
    "@types/figlet": "^1.5.6",
    "@types/jest": "^29.5.1",
    "@types/jsonwebtoken": "^9.0.1",
    "@types/lodash": "^4.14.194",
    "@types/ms": "^0.7.31",
    "@types/node": "^18.15.5",
    "@types/node-rsa": "^1.1.1",
    "@types/prettier": "^2.7.2",
    "@types/react": "^18.0.28",
    "@types/react-dom": "^18.0.11",
    "@types/react-modal": "^3.13.1",
    "@types/recompose": "^0.30.10",
    "@types/supertest": "^2.0.11",
    "@types/swagger-ui-react": "^4.18.0",
    "@types/uuid": "^9.0.1",
    "@typescript-eslint/eslint-plugin": "^5.56.0",
    "@typescript-eslint/parser": "^5.56.0",
    "autoprefixer": "^10.4.14",
    "axios": "^1.3.5",
    "canvas-confetti": "^1.6.0",
    "cryptr": "^6.2.0",
    "dagre": "^0.8.5",
    "dayjs": "^1.11.7",
    "dayjs-plugin-utc": "^0.1.2",
    "emoji-picker-react": "^4.4.8",
    "eslint": "^8.36.0",
    "eslint-config-next": "^13.2.4",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-jest": "27.1.6",
    "eslint-plugin-prettier": "^4.0.0",
    "fast-sort": "^3.2.1",
    "figlet": "^1.6.0",
    "jest": "^29.5.0",
    "jsonwebtoken": "^9.0.0",
    "langchain": "^0.0.102",
    "lodash": "^4.17.21",
    "ms": "^2.1.3",
    "next": "13.4.4",
    "next-auth": "^4.22.1",
    "next-swagger-doc": "^0.3.6",
    "next-transpile-modules": "^10.0.0",
    "nextjs-cors": "^2.1.2",
    "node-rsa": "^1.1.1",
    "nodemon": "^2.0.12",
    "notistack": "^3.0.1",
    "npm-run-all": "^4.1.5",
    "pgvector": "^0.1.4",
    "php-serialize": "^4.1.1",
    "pino": "^8.14.1",
    "postcss": "^8.4.21",
    "posthog-js": "^1.54.0",
    "posthog-node": "^3.1.1",
    "prettier": "^2.8.6",
    "prettier-plugin-tailwindcss": "^0.2.6",
    "prisma": "^4.14.0",
    "react": "18.2.0",
    "react-detect-click-outside": "^1.1.7",
    "react-dom": "18.2.0",
    "react-hook-form": "^7.43.9",
    "react-router-dom": "^6.11.1",
    "react-spinners": "^0.13.8",
    "reactflow": "^11.7.0",
    "recompose": "^0.30.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^7.2.0",
    "shelljs": "^0.8.5",
    "source-map-support": "^0.5.20",
    "superjson": "1.12.2",
    "supertest": "^6.1.3",
    "swagger-ui-react": "^4.18.2",
    "tailwindcss": "^3.3.0",
    "tld-extract": "^2.1.0",
    "trpc-openapi": "^1.1.2",
    "ts-jest": "28.0.5",
    "ts-loader": "^9.2.3",
    "ts-node": "^10.0.0",
    "tsconfig-paths": "4.0.0",
    "uuid": "^9.0.0",
    "winston": "^3.9.0",
    "xmldom": "^0.6.0",
    "zod": "^3.21.4",
    "zustand": "^4.3.7"
  },
  "devDependencies": {
    "@types/canvas-confetti": "^1.6.0",
    "@types/dagre": "^0.7.48",
    "@types/eslint": "^8.21.3",
    "@types/express": "^4.17.13",
    "@types/figlet": "^1.5.6",
    "@types/jest": "^29.5.1",
    "@types/jsonwebtoken": "^9.0.1",
    "@types/lodash": "^4.14.194",
    "@types/ms": "^0.7.31",
    "@types/node": "^18.15.5",
    "@types/node-rsa": "^1.1.1",
    "@types/prettier": "^2.7.2",
    "@types/react": "^18.0.28",
    "@types/react-dom": "^18.0.11",
    "@types/react-modal": "^3.13.1",
    "@types/recompose": "^0.30.10",
    "@types/supertest": "^2.0.11",
    "@types/swagger-ui-react": "^4.18.0",
    "@types/uuid": "^9.0.1",
    "@typescript-eslint/eslint-plugin": "^5.56.0",
    "@typescript-eslint/parser": "^5.56.0",
    "autoprefixer": "^10.4.14",
    "eslint": "^8.36.0",
    "eslint-config-next": "^13.2.4",
    "postcss": "^8.4.21",
    "prettier": "^2.8.6",
    "prettier-plugin-tailwindcss": "^0.2.6",
    "prisma": "^4.14.0",
    "tailwindcss": "^3.3.0",
    "typescript": "^5.1.3",
    "userflow.js": "^2.7.0",
    "uuid": "^9.0.0",
    "zod": "^3.21.4",
    "zustand": "^4.3.7"
  },
tlhunter commented 1 year ago

Interesting... It looks like there is a logit_bias field inside of the request object however the field is not an array but is instead null or undefined.

Do you know which endpoint this is for? And do you know if you're app is constructing the request object or if the langchain plugin is constructing it?

mlnj commented 1 year ago

@tlhunter here Langchain JS is calling the open ai chat completion api. In the langchain js source code, thee logit_bias field is optional.

This suddenly started causing issues and we had to disable the tracing call for this context.

tlhunter commented 1 year ago

A fix for this should go out in the next release

adoniscyp commented 1 year ago

@tlhunter is there a previous release that we can use in the meantime? We can do without this feature. When is the next release expected?