Skip to content

Commit

Permalink
[pinpoint-apm#247] RemoteAddress UNKNOWN
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Dec 19, 2024
1 parent 2184464 commit 6f0e263
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/instrumentation/http/http-request-trace-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IncomingMessageHeaderReader {
}

getRemoteAddress() {
return this.getHeader('x-forwarded-for')?.split(',').trim().shift() ?? this.socket?.remoteAddress
return this.getHeader('x-forwarded-for')?.split(',').trim().shift() ?? this.request.socket?.remoteAddress?.replace?.('::ffff:', '')
}

getQuery() {
Expand Down
4 changes: 4 additions & 0 deletions test/instrumentation/context/nested-async-trace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ test(`nested mysql2 async query with express`, async (t) => {

agent.callbackTraceClose(async (trace) => {
t.equal(trace.spanBuilder.serviceType, ServiceType.node.getCode(), 'Span serviceType is node')
t.true(trace.spanBuilder.remoteAddress === '127.0.0.1' || trace.spanBuilder.remoteAddress === '::1', `remoteAddress is ${trace.spanBuilder.remoteAddress}`)
let actualBuilder = new MethodDescriptorBuilder(expected('get', 'app.get'))
.setClassName(expected('app', 'Function'))
.setLineNumber(319)
Expand Down Expand Up @@ -453,6 +454,9 @@ test(`nested mysql2 async query with express`, async (t) => {
t.equal(actualSpanChunk.spanEventList[0].serviceType, ServiceType.async.getCode(), 'serviceType is mysql')

spanMessageEndEventCallback = async () => {
const trace = agent.getTraces()[0]
t.true(trace.spanBuilder.remoteAddress === '127.0.0.1' || trace.spanBuilder.remoteAddress === '::1', `remoteAddress is ${trace.spanBuilder.remoteAddress}`)

connection.end()
t.equal(agent.getSendedApiMetaInfos().length, 0, 'agent.getSendedApiMetaInfos() is empty')
t.end()
Expand Down

0 comments on commit 6f0e263

Please sign in to comment.