elastic / elastic/apm-agent-nodejs

TypeError: Cannot read properties of null (reading 'encrypted')

Open
#4,466 8 comments 0 reactions 0 assignees View on GitHub
community triage
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

**Describe the bug**

I have dozens of these errors in Elastic APM and they seem to originate from this agent. The stacktrace is always

```
TypeError: Cannot read properties of null (reading 'encrypted')

at protocol (node_modules/express/lib/request.js:307)
at secure (node_modules/express/lib/request.js:336)
at module.exports (node_modules/original-url/index.js:10)
at getContextFromRequest (node_modules/elastic-apm-node/lib/parsers.js:58)
at Transaction.toJSON (node_modules/elastic-apm-node/lib/instrumentation/transaction.js:310)
at Transaction._encode (node_modules/elastic-apm-node/lib/instrumentation/transaction.js:358)
at Instrumentation.addEndedTransaction (node_modules/elastic-apm-node/lib/instrumentation/index.js:760)
at Transaction.end (node_modules/elastic-apm-node/lib/instrumentation/transaction.js:422)
at ServerResponse. (node_modules/elastic-apm-node/lib/instrumentation/http-shared.js:133)
at f (node_modules/once/once.js:25)
at onfinish (node_modules/end-of-stream/index.js:31)
at (node_modules/elastic-apm-node/lib/instrumentation/run-context/AbstractRunContextManager.js:96)
at run (node:internal/async_local_storage/async_hooks:80)
at with (node_modules/elastic-apm-node/lib/instrumentation/run-context/AsyncLocalStorageRunContextManager.js:57)
at wrapper (node_modules/elastic-apm-node/lib/instrumentation/run-context/AbstractRunContextManager.js:96)
at emit (node:events:530)
at onFinish (node:_http_outgoing:1077)
at callback (node:internal/streams/writable:766)
at afterWrite (node:internal/streams/writable:710)
at afterWriteTick (node:internal/streams/writable:696)
at processTicksAndRejections (node:internal/process/task_queues:89)
```

**To Reproduce**

I don't know exactly. I have thousands of APM transactions, and only a few of them exhibit this behavior. I'm willing to help reproduce but I really don't know where to start...

**Expected behavior**

No exception in APM.

**Environment (please complete the following information)**

- OS: Linux Mint 22
- Node.js version: 22
- APM Server version: 8.15.3
- Agent version: Latest (4.11.0 as the time of writing)

**How are you starting the agent? (please tick one of the boxes)**

- [X] Calling `agent.start()` directly (e.g. `require('elastic-apm-node').start(...)`)
- [ ] Requiring `elastic-apm-node/start` from within the source code
- [ ] Starting node with `-r elastic-apm-node/start`

**Additional context**

Agent config options:

Click to expand

```
No config options
```

`package.json` dependencies:

Click to expand

```
replace this line with your dependencies section from package.json
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.