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

TypeError "aws_xray_sdk_mysql_1.captureMySQL is not a function" #450

Open
richardcornelissen opened this issue Jul 13, 2021 · 6 comments
Open
Assignees
Labels

Comments

@richardcornelissen
Copy link

We've recently updated aws-xray-sdk-mysql from version 3.2.0 to 3.3.3, but experienced issues with our Typescript projects.

Due to the changed Typescript definitions, we had to adjust the import from

import captureMySQL from 'aws-xray-sdk-mysql';

to

import {captureMySQL} from 'aws-xray-sdk-mysql';

However, this resulted in errors as such:

{
    "errorType": "TypeError",
    "errorMessage": "aws_xray_sdk_mysql_1.captureMySQL is not a function",
    "stack": [
        "TypeError: aws_xray_sdk_mysql_1.captureMySQL is not a function",
        "    at Object.exports.setup (/var/task/src/api.js:2:1851104)",
        "    at Object.<anonymous> (/var/task/src/api.js:2:1848725)",
        "    at __webpack_require__ (/var/task/src/api.js:2:295)",
        "    at Object.<anonymous> (/var/task/src/api.js:2:1847607)",
        "    at __webpack_require__ (/var/task/src/api.js:2:295)",
        "    at /var/task/src/api.js:2:1594",
        "    at Object.<anonymous> (/var/task/src/api.js:2:1641)",
        "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
        "    at Module.load (internal/modules/cjs/loader.js:863:32)"
    ]
}

Workaround

As a temporary workaround, replace

import {captureMySQL} from 'aws-xray-sdk-mysql';

With

// eslint-disable-next-line @typescript-eslint/no-var-requires
const captureMySQL = require('aws-xray-sdk-mysql');
@willarmiros
Copy link
Contributor

Hi @richardcornelissen,

I wasn't able to reproduce this with a normal TypeScript app importing captureMySQL normally. I noticed you're using webpack, so I think it's likely related to some of the magic that does under the hood. Thank you for providing the workaround, there are some known issues with this SDK and webpack so I will label this as a bug within that category for now.

@beanaroo
Copy link

Can confirm that we are getting the same issue:

capturePostgres is not a function

@willarmiros
Copy link
Contributor

Apologies, we have not been able to prioritize this investigation yet. @beanaroo were you able to apply the workaround suggested in the initial post?

@Irvel
Copy link

Irvel commented Nov 5, 2021

Hi @willarmiros, we're encountering the same issue when importing 'aws-xray-sdk-postgres'. The proposed workaround in the initial post worked for us.

For context, we are not using webpack. We stumbled upon the issue while replacing the 'aws-xray-sdk' package with 'aws-xray-sdk-core' + 'aws-xray-sdk-postgres'

@willarmiros
Copy link
Contributor

Hi @Irvel thanks for reporting as well. We've documented this issue and will investigate a fix when we have bandwidth. For what it's worth here is where we define the capturePostgres function type:

export function capturePostgres(pg: typeof PG): capturePostgres.PatchedPostgres;

I wasn't able to reproduce initially so this will require a longer look. As a side note, the AWS Distro for OpenTelemetry JavaScript has support for instrumenting MySQL and Postgres functions and is written in native TypeScript for much more robust typings. It also has first-class support for tracing with X-Ray, so feel free to check that out.

@paya-cz
Copy link

paya-cz commented Dec 13, 2021

I have the same issue with capturePostgres function. I believe this should fix the issue in the typings file:

export default function captureMySQL(mysql: typeof MySQL): captureMySQL.PatchedMySQL;

instead of the current:

export function captureMySQL(mysql: typeof MySQL): captureMySQL.PatchedMySQL;

Same fix should apply to the postgres version.


Until this is fixed, you can use this as a workaround:

import originalCapturePostgres from 'aws-xray-sdk-postgres';
import originalPg from 'pg';

// Workaround for busted typings
// @ts-ignore
const capturePostgres: typeof originalCapturePostgres.capturePostgres = originalCapturePostgres;

export const pg = capturePostgres(originalPg);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants