# Issue with APM integration with Meteor application

**URL:** <https://discuss.elastic.co/t/issue-with-apm-integration-with-meteor-application/338860>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [July 20, 2023, 8:46am UTC](https://discuss.elastic.co/t/issue-with-apm-integration-with-meteor-application/338860 "2023-07-20T08:46:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kesha\_Shah](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kesha_shah/32/122625_2.png) [@Kesha\_Shah](https://discuss.elastic.co/u/Kesha_Shah)\
**Post date:** [July 20, 2023, 8:46am UTC](https://discuss.elastic.co/t/issue-with-apm-integration-with-meteor-application/338860/1 "2023-07-20T08:46:26Z")

</div>

**Kibana version** : 8.8.1

**Elasticsearch version** : 8.8.1

**APM Server version** : 8.8.1

**APM Agent language and version** : Using NodeJS agent for Meteor App

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

We are trying to integrate elastic-apm with meteor app but seems like there are multiple issues with it.  
I have already checked [previous discussion on meteor](https://discuss.elastic.co/t/elastic-apm-for-meteor-js/186669/2) with plugin [meteor-elastic-apm](https://github.com/kschingiz/meteor-elastic-apm/) but I dont think its compatible with Meteor 2.8 version.

I have removed plugin from my application and just added nodeJs elastic agent, but when I try to create transaction manually inside Meteor Method, it creates traceId but eventually it crashes. Below are few debug and crash logs

```auto
I20230720-13:03:11.007(5.5)? {"log.level":"debug","@timestamp":"2023-07-20T07:33:11.006Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"start trace {\"trans\":\"0e9a29d467ccc26a\",\"trace\":\"e462aae1e19d9d573dff2ed8b295d093\",\"name\":\"unnamed\",\"type\":\"internal\",\"subtype\":null,\"action\":null}"}
I20230720-13:03:11.007(5.5)? {"log.level":"debug","@timestamp":"2023-07-20T07:33:11.007Z","log":{"logger":"elastic-apm-node"},"ctxmgr":"AsyncLocalStorageRunContextManager( RunContext<Transaction(0e9a29, 'forecast-get')> )","ecs":{"version":"1.6.0"},"message":"supersedeWithTransRunContext(<Trans 0e9a29d467ccc26a>)"}
I20230720-13:03:11.068(5.5)? {"log.level":"debug","@timestamp":"2023-07-20T07:33:11.068Z","log":{"logger":"elastic-apm-node"},"ctxmgr":"AsyncLocalStorageRunContextManager( RunContext<> )","ecs":{"version":"1.6.0"},"message":"addEndedTransaction(forecast-get)"}
I20230720-13:03:11.069(5.5)? {"log.level":"debug","@timestamp":"2023-07-20T07:33:11.068Z","log":{"logger":"elastic-apm-node"},"ecs":{"version":"1.6.0"},"message":"sending transaction {\"trans\":\"0e9a29d467ccc26a\",\"trace\":\"e462aae1e19d9d573dff2ed8b295d093\"}"}
I20230720-13:03:11.069(5.5)? {"log.level":"debug","@timestamp":"2023-07-20T07:33:11.068Z","log":{"logger":"elastic-apm-node"},"trans":"0e9a29d467ccc26a","name":"forecast-get","trace":"e462aae1e19d9d573dff2ed8b295d093","type":"internal","result":"success","duration":61.813,"ecs":{"version":"1.6.0"},"message":"ended transaction"}
W20230720-13:03:11.117(5.5)? (STDERR) TypeError: Cannot read property 'Symbol(kResourceStore)' of undefined
W20230720-13:03:11.119(5.5)? (STDERR) at AsyncLocalStorage._propagate (async_hooks.js:288:34)
W20230720-13:03:11.119(5.5)? (STDERR) at AsyncHook.init (async_hooks.js:255:22)
W20230720-13:03:11.120(5.5)? (STDERR) at emitInitNative (internal/async_hooks.js:203:43)
W20230720-13:03:11.120(5.5)? (STDERR) at emitInitScript (internal/async_hooks.js:493:3)
W20230720-13:03:11.120(5.5)? (STDERR) at initAsyncResource (internal/timers.js:160:5)
W20230720-13:03:11.120(5.5)? (STDERR) at new Timeout (internal/timers.js:194:3)
W20230720-13:03:11.121(5.5)? (STDERR) at setUnrefTimeout (internal/timers.js:376:17)
W20230720-13:03:11.121(5.5)? (STDERR) at Socket.setStreamTimeout [as setTimeout] (internal/stream_base_commons.js:263:22)
W20230720-13:03:11.121(5.5)? (STDERR) at IncomingMessage.setTimeout (_http_incoming.js:99:15)
W20230720-13:03:11.121(5.5)? (STDERR) at Server.WebApp._timeoutAdjustmentRequestCallback (packages/webapp/webapp_server.js:273:7)
W20230720-13:03:11.121(5.5)? (STDERR) at packages/ddp-server/stream_server.js:184:23
W20230720-13:03:11.121(5.5)? (STDERR) at Array.forEach (<anonymous>)
W20230720-13:03:11.122(5.5)? (STDERR) at Function._.each._.forEach (packages/underscore.js:139:11)
W20230720-13:03:11.122(5.5)? (STDERR) at Server.newListener (packages/ddp-server/stream_server.js:183:11)
W20230720-13:03:11.124(5.5)? (STDERR) at Server.emit (events.js:400:28)
W20230720-13:03:11.125(5.5)? (STDERR) at Server.emit (domain.js:475:12)
W20230720-13:03:11.125(5.5)? (STDERR) at parserOnIncoming (_http_server.js:900:12)
W20230720-13:03:11.125(5.5)? (STDERR) at HTTPParser.parserOnHeadersComplete (_http_common.js:127:17)
W20230720-13:03:11.125(5.5)? (STDERR) TypeError: Cannot read property 'Symbol(kResourceStore)' of undefined
W20230720-13:03:11.126(5.5)? (STDERR) at AsyncLocalStorage._propagate (async_hooks.js:288:34)
W20230720-13:03:11.126(5.5)? (STDERR) at AsyncHook.init (async_hooks.js:255:22)
W20230720-13:03:11.126(5.5)? (STDERR) at emitInitNative (internal/async_hooks.js:203:43)
W20230720-13:03:11.127(5.5)? (STDERR) at emitInitScript (internal/async_hooks.js:493:3)
W20230720-13:03:11.127(5.5)? (STDERR) at promiseInitHook (internal/async_hooks.js:323:3)
W20230720-13:03:11.127(5.5)? (STDERR) at Function.reject (<anonymous>)
W20230720-13:03:11.127(5.5)? (STDERR) at process.<anonymous> (packages/inter-process-messaging.js:227:47)
W20230720-13:03:11.127(5.5)? (STDERR) at process.emit (events.js:412:35)
W20230720-13:03:11.127(5.5)? (STDERR) at process.emit (domain.js:475:12)
W20230720-13:03:11.127(5.5)? (STDERR) at process.exit (internal/process/per_thread.js:179:15)
W20230720-13:03:11.127(5.5)? (STDERR) at fatalError (internal/async_hooks.js:176:11)
W20230720-13:03:11.127(5.5)? (STDERR) at emitInitNative (internal/async_hooks.js:210:5)
W20230720-13:03:11.127(5.5)? (STDERR) at emitInitScript (internal/async_hooks.js:493:3)
W20230720-13:03:11.127(5.5)? (STDERR) at initAsyncResource (internal/timers.js:160:5)
W20230720-13:03:11.127(5.5)? (STDERR) at new Timeout (internal/timers.js:194:3)
W20230720-13:03:11.127(5.5)? (STDERR) at setUnrefTimeout (internal/timers.js:376:17)
W20230720-13:03:11.127(5.5)? (STDERR) at Socket.setStreamTimeout [as setTimeout] (internal/stream_base_commons.js:263:22)
W20230720-13:03:11.127(5.5)? (STDERR) at IncomingMessage.setTimeout (_http_incoming.js:99:15)
W20230720-13:03:11.127(5.5)? (STDERR) at Server.WebApp._timeoutAdjustmentRequestCallback (packages/webapp/webapp_server.js:273:7)
W20230720-13:03:11.127(5.5)? (STDERR) at packages/ddp-server/stream_server.js:184:23
W20230720-13:03:11.127(5.5)? (STDERR) at Array.forEach (<anonymous>)
W20230720-13:03:11.127(5.5)? (STDERR) at Function._.each._.forEach (packages/underscore.js:139:11)
W20230720-13:03:11.128(5.5)? (STDERR) at Server.newListener (packages/ddp-server/stream_server.js:183:11)
W20230720-13:03:11.128(5.5)? (STDERR) at Server.emit (events.js:400:28)
W20230720-13:03:11.128(5.5)? (STDERR) at Server.emit (domain.js:475:12)
W20230720-13:03:11.128(5.5)? (STDERR) at parserOnIncoming (_http_server.js:900:12)
W20230720-13:03:11.128(5.5)? (STDERR) at HTTPParser.parserOnHeadersComplete (_http_common.js:127:17)
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.

```

This is my code to start transaction

```auto
Meteor.methods({
  getAllFarm() {
      this.unblock();
      const trans = apm.startTransaction(`Get-farm`, 'internal');
      console.log(`get all farms`);
      console.log(`current transaction is ${apm.currentTransaction}`);
      const user = Meteor.user();
      // Some code 
      if (trans) trans.end();
    }
})

```

Please note by default there is no transaction created as its not HTTP call and it works via pub/sub mechanism.  
Also with [meteor-elastic-apm](https://github.com/kschingiz/meteor-elastic-apm/) plugin it was giving me same error.

Any help is appreciated to fix this issue 🙂

---

<div class="post-metadata">

**Author:** ![David\_Luna\_Bistuer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_luna_bistuer/32/122147_2.png) [@David\_Luna\_Bistuer](https://discuss.elastic.co/u/David_Luna_Bistuer)\
**Post date:** [July 20, 2023, 4:31pm UTC](https://discuss.elastic.co/t/issue-with-apm-integration-with-meteor-application/338860/2 "2023-07-20T16:31:05Z")

</div>

Hi @Kesha_Shah

That missing symbol is not from the nodejs agent so probably the instrumentation is involved. Thanks for the log and the code snippet but I'm not familiar with the framework and I need some extra info:

- which method did you use for instrumentation. Take a look at [this page](https://www.elastic.co/guide/en/apm/agent/nodejs/3.x/starting-the-agent.html) for reference
- could you provide a small repro of the issue? You can create a PR to [this todo App](https://github.com/david-luna/elastic-nodejs-agent-meteor) to add the changes that lead to this error.

Cheers!

---

<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:** [August 10, 2023, 6:58pm UTC](https://discuss.elastic.co/t/issue-with-apm-integration-with-meteor-application/338860/3 "2023-08-10T18:58:04Z")

</div>

@Kesha_Shah If you are still hitting this, what version of Node.js are you using?

Your stack trace looks like this core Node.js issue:

> <https://github.com/nodejs/node/issues/34556>
>
> \<!--
> Thank you for reporting an issue.
> 
> This issue tracker is for bugs and is…sues found within Node.js core.
> If you require more general support please file an issue on our help
> repo. https://github.com/nodejs/help
> 
> 
> Please fill in as much of the template below as you're able.
> 
> Version: output of \`node -v\`
> Platform: output of \`uname -a\` (UNIX), or version and 32 or 64-bit (Windows)
> Subsystem: if known, please specify affected core module name
> \--\>
> 
> \* \*\*Version\*\*: v14.6.0 (works on v14.5.0)
> \* \*\*Platform\*\*: Unix
> \* \*\*Subsystem\*\*: async\_hooks
> 
> \### What steps will reproduce the bug?
> 
> \<!--
> Enter details about your bug, preferably a simple code snippet that can be
> run using \`node\` directly without installing third-party dependencies.
> \--\>
> I'm not entirely sure yet, but will continue investigating. Any pointers would be appreciated. 
> 
> Sadly the code itself is private, but I'll try to extract a reproduction.
> 
> \### How often does it reproduce? Is there a required condition?
> 
> I only see this crash reliably on every test run on one of our services, all the others seem to work fine.
> 
> The service works on v14.4.0 and v14.5.0, so this seems to be a regression introduced in v14.6.0.
> 
> \### What is the expected behavior?
> 
> Working AsyncLocalStorage.
> 
> \### What do you see instead?
> 
> An exception
> 
> \`\`\`
> TypeError: Cannot read property 'Symbol(kResourceStore)' of undefined
> at AsyncLocalStorage.\_propagate (async\_hooks.js:246:34)
> at AsyncHook.init (async\_hooks.js:222:22)
> at emitInitNative (internal/async\_hooks.js:198:43)
> at emitInitScript (internal/async\_hooks.js:466:3)
> at initAsyncResource (internal/timers.js:155:5)
> at new Timeout (internal/timers.js:188:3)
> at setUnrefTimeout (internal/timers.js:370:17)
> at cache (internal/http.js:27:3)
> at utcDate (internal/http.js:19:18)
> at ServerResponse.\_storeHeader (\_http\_outgoing.js:391:26)
> at ServerResponse.writeHead (\_http\_server.js:313:8)
> at ServerResponse.\_implicitHeader (\_http\_server.js:240:8)
> at write\_ (\_http\_outgoing.js:663:9)
> at ServerResponse.end (\_http\_outgoing.js:776:5)
> at /app/node\_modules/@opentelemetry/plugin-http/build/src/http.js:213:87
> at HttpPlugin.\_safeExecute (/app/node\_modules/@opentelemetry/plugin-http/build/src/http.js:303:20)
> at ServerResponse.response.end (/app/node\_modules/@opentelemetry/plugin-http/build/src/http.js:213:49)
> \`\`\`
> 
> Likely the result of \`executionAsyncResource()\` returning \`undefined\` here:
> https://github.com/nodejs/node/blob/13c5a1629cd025ba560f34f6d3190b2f38d184d4/lib/async\_hooks.js#L219
> 
> \### Additional information
> 
> AsyncLocalStorage is used using https://github.com/open-telemetry/opentelemetry-js/tree/v0.10.1 and via the \`AsyncLocalStorageContextManager\` https://github.com/open-telemetry/opentelemetry-js/blob/v0.10.1/packages/opentelemetry-context-async-hooks/src/AsyncLocalStorageContextManager.ts
> 
> \<!--
> Tell us anything else you think we should know.
> \--\>

I believe that was resolved in Node.js 14.8.0.

---

<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:** [September 7, 2023, 6:59pm UTC](https://discuss.elastic.co/t/issue-with-apm-integration-with-meteor-application/338860/4 "2023-09-07T18:59:01Z")

</div>

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