Skip to content

Commit ea93cce

Browse files
committed
[#319] Add custom error status code configuration support
1 parent 9e904b9 commit ea93cce

23 files changed

+223
-434
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22
All notable changes to Pinpoint Node.js agent will be documented in this file.
33

4+
## [1.0.1] - 2025-05-23
5+
### Added
6+
- [[#319](https://github.com/pinpoint-apm/pinpoint-node-agent/issues/319)] Add support for custom error status code configuration
7+
8+
### ⚠️ Breaking Changes
9+
In unsupported web frameworks such as Next.js App Router, HTTP responses with status code 500 may not appear in scatter charts. You can customizing HTTP error status code.
10+
411
## [1.0.0] - 2025-05-22
512
### Added
613
- [[#214](https://github.com/pinpoint-apm/pinpoint-node-agent/issues/214)] Support Active Request

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ PINPOINT_TRACE_EXCLUSION_URL_PATTERN | | comma-separated string. ex) `/health_c
112112
PINPOINT_TRACE_EXCLUSION_URL_CACHE_SIZE | | If the app is designed so that the pathname of the URL is fixed, if the cache size is set, the pathname of the frequently used URL does not match with patterns. In case of using query for pathname like `/user/1000`, cache is unnecessarily. [Unit tests](https://github.com/pinpoint-apm/pinpoint-node-agent/blob/01fcbdefe5a0ffba9c957bee0da3fb7397638182/test/utils/ant-path-matcher.test.js#L447)
113113
PINPOINT_PROFILER_SQL_STAT | false | SQL uid
114114
PINPOINT_TRACE_LOCATION_AND_FILENAME_OF_CALL_SITE | false | CallSite line number and filename
115+
PINPOINT_HTTP_STATUS_CODE_ERRORS | 5xx,401,403 | Comma-separated list of HTTP status codes that should be treated as errors. When a response matches one of these codes, the agent will record the request as an error in Pinpoint. You can customize this list to include any status codes relevant to your application's error.
115116

116117
### Agent ID
117118
The agent ID is used as the identifier per the server or node. You need to set the hostname or node identifier(The maximum length is 24) on the server.

demo/express/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
"morgan": "~1.9.1",
1919
"mysql": "^2.18.1",
2020
"mysql2": "^3.9.1",
21-
"pinpoint-node-agent": "^0.9.0"
21+
"pinpoint-node-agent": "^1.0.0"
2222
}
2323
}

lib/config.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const ENV_MAP = {
6262
traceLocationAndFileNameOfCallSite: valueOfBoolean('PINPOINT_TRACE_LOCATION_AND_FILENAME_OF_CALL_SITE'),
6363
profilerSqlStat: valueOfBoolean('PINPOINT_PROFILER_SQL_STAT'),
6464
logError: valueOfBoolean('PINPOINT_LOG_ERROR'),
65+
httpStatusCodeErrors: valueOfString('PINPOINT_HTTP_STATUS_CODE_ERRORS'),
6566
}
6667

6768
const CONFIG_FILE_MAP = {
@@ -75,7 +76,7 @@ const CONFIG_FILE_MAP = {
7576
collectorSpanPort: 'collector.span-port',
7677
sampling: 'sampling.enable',
7778
sampleRate: 'sampling.rate',
78-
httpStatusCodeErrors: 'http-status-code-errors',
79+
httpStatusCodeErrors: 'http-status-code.errors',
7980
logLevel: 'log-level',
8081
enabledDataSending: 'enabled-data-sending',
8182
enabledStatsMonitor: 'enabled-stats-monitor-sending',
@@ -261,6 +262,13 @@ const getConfig = (initOptions) => {
261262
const initializeConfig = (initOptions) => {
262263
clear()
263264
init(initOptions)
265+
loadedConfigCallbacks.forEach(callback => {
266+
try {
267+
callback.callback(agentConfig[callback.propertyName])
268+
} catch (e) {
269+
log.error('Error in loadedConfig callback', e)
270+
}
271+
})
264272
}
265273

266274
const clear = () => agentConfig && (agentConfig = null)
@@ -289,6 +297,15 @@ function hasDockerCGroup() {
289297

290298
let agentConfig = readConfigJson(defaultConfig)
291299

300+
const loadedConfigCallbacks = []
301+
function registerLoadedConfig(propertyName, callback) {
302+
if (typeof propertyName !== 'string' || typeof callback !== 'function') {
303+
return
304+
}
305+
306+
loadedConfigCallbacks.push({ propertyName, callback })
307+
}
308+
292309
module.exports = {
293310
getConfig,
294311
clear,
@@ -297,4 +314,5 @@ module.exports = {
297314
getMainModulePath,
298315
isContainerEnvironment,
299316
initializeConfig,
317+
registerLoadedConfig,
300318
}

lib/context/async-trace.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

lib/context/buffered-storage.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

lib/context/disable-async-trace.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

lib/context/span-recorder.js

Lines changed: 0 additions & 82 deletions
This file was deleted.

lib/context/trace-context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const TraceSampler = require('./trace/trace-sampler')
1414
const SpanBuilder = require('./span-builder')
1515
const SpanChunkBuilder = require('./span-chunk-builder')
1616
const SpanRepository = require('./trace/span-repository')
17-
const Trace2 = require('./trace/trace2')
17+
const Trace = require('./trace/trace')
1818
const AsyncSpanChunkBuilder = require('./trace/async-span-chunk-builder')
1919
const ChildTraceBuilder = require('./trace/child-trace-builder')
2020
const DisableChildTrace = require('./trace/disable-child-trace')
@@ -82,7 +82,7 @@ class TraceContext {
8282
const spanChunkBuilder = new SpanChunkBuilder(traceRoot)
8383
const repository = new SpanRepository(spanChunkBuilder, this.dataSender, this.agentInfo)
8484
activeRequestRepository.register(traceRoot)
85-
return new Trace2(spanBuilder, repository)
85+
return new Trace(spanBuilder, repository)
8686
}
8787

8888
// DefaultAsyncContext.java: newAsyncContextTrace

0 commit comments

Comments
 (0)