# CallSite method getFileName expects CallSite as receiver

**URL:** <https://discuss.elastic.co/t/callsite-method-getfilename-expects-callsite-as-receiver/335350>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [June 6, 2023, 1:07pm UTC](https://discuss.elastic.co/t/callsite-method-getfilename-expects-callsite-as-receiver/335350 "2023-06-06T13:07:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hardik\_Kaushik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hardik_kaushik/32/121899_2.png) [@Hardik\_Kaushik](https://discuss.elastic.co/u/Hardik_Kaushik)\
**Post date:** [June 6, 2023, 1:07pm UTC](https://discuss.elastic.co/t/callsite-method-getfilename-expects-callsite-as-receiver/335350/1 "2023-06-06T13:07:40Z")

</div>

```auto
uncaughtException: CallSite method getFileName expects CallSite as receiver
TypeError: CallSite method getFileName expects CallSite as receiver
    at CallSite.getFileName (<anonymous>)
    at frameFromCallSite (/usr/src/app/.yarn/cache/elastic-apm-node-npm-3.36.0-8762a46181-1e86195425.zip/node_modules/elastic-apm-node/lib/stacktraces.js:258:29)
    at gatherStackTrace (/usr/src/app/.yarn/cache/elastic-apm-node-npm-3.36.0-8762a46181-1e86195425.zip/node_modules/elastic-apm-node/lib/stacktraces.js:429:7)
    at Object.createAPMError (/usr/src/app/.yarn/cache/elastic-apm-node-npm-3.36.0-8762a46181-1e86195425.zip/node_modules/elastic-apm-node/lib/errors.js:196:5)

```

```
- This error is thrown after this got logged.

```

`error thrown is getaddrinfo ENOTFOUND some.addresss`

Any work around to fix this? don't want this error to go unhandled next time.

Yarn 3.5.1  
Node 14  
elastic-apm-node 3.34.0  
using require('elastic-apm-node').start(...)

---

<div class="post-metadata">

**Author:** ![trentm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trentm/32/77647_2.png) [@trentm](https://discuss.elastic.co/u/trentm)\
**Post date:** [June 6, 2023, 7:01pm UTC](https://discuss.elastic.co/t/callsite-method-getfilename-expects-callsite-as-receiver/335350/2 "2023-06-06T19:01:58Z")

</div>

@Hardik_Kaushik Thanks for reporting this.

As best I can tell, this is what is happening:

1. Something is calling the APM agent's `agent.captureError(...)` API -- that will be either your code directly calling that API, or the default handler that the APM agent sets up for an `uncaughtException` thrown by some JavaScript code.
2. The APM agent's internal code that uses the `CallSite` objects returned by v8's stack trace API ([Stack trace API · V8](https://v8.dev/docs/stack-trace-api)) is failing.

The only ideas I have on how that error -- `TypeError: CallSite method getFileName expects CallSite as receiver` -- could happen:

1. There is some other module or code in your application that is setting `Error.prepareStackTrace` to customize stack traces and this is competing with the `Error.prepareStackTrace` that the APM agent is using to collect stack trace information. (The APM agent uses the [GitHub - watson/error-callsites: Extract callsite objects from Error objects](https://github.com/watson/error-callsites) module to collect stack trace information.)
2. _Possibly_ something is resulting in there being multiple `CallSite` classes in play. This could be something different about how yarn works compared to an `npm install` that I am more familiar with. It could possibly be related to bundler usage -- but I don't think so.

Can you provide some more details on your application?

- Can you show your full "dependencies" and "devDependencies" from your "package.json"?
- Do you know if anything is setting `Error.prepareStackTrace` in your application or in its dependencies?
- Are you using a bundler? (Like webpack, or esbuild, etc.)

Your comment says you are using elastic-apm-node 3.34.0, but the stack trace suggests your are using version 3.36.0. It _might_ be worth updating to the latest to see if that fixes anything, but I'm not hopeful.

Ideally, if you are able, a small reproduction case would help me debug this.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 4, 2023, 7:02pm UTC](https://discuss.elastic.co/t/callsite-method-getfilename-expects-callsite-as-receiver/335350/3 "2023-07-04T19:02:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
