forked from pinpoint-apm/pinpoint-node-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pinpoint-apm#140] Support nested async trace
- Loading branch information
Showing
3 changed files
with
93 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Pinpoint Node.js Agent | ||
* Copyright 2020-present NAVER Corp. | ||
* Apache License v2.0 | ||
*/ | ||
|
||
const test = require('tape') | ||
const agent = require('../../support/agent-singleton-mock') | ||
const express = require('express') | ||
const axios = require('axios') | ||
const MethodDescriptorBuilder = require('../../../lib/context/method-descriptor-builder') | ||
const apiMetaService = require('../../../lib/context/api-meta-service') | ||
const { expected } = require('../../fixtures/instrument-support') | ||
const mysql = require('mysql') | ||
const path = require('path') | ||
const fixtures = path.resolve(__dirname, '..', '..', 'fixtures', 'db') | ||
const { MySqlContainer } = require('testcontainers') | ||
|
||
test(`nested mysql async query with express`, async (t) => { | ||
agent.bindHttpWithCallSite() | ||
const source = path.resolve(fixtures, 'mysql.sql') | ||
const container = await new MySqlContainer() | ||
.withCommand(['--default-authentication-plugin=mysql_native_password']) | ||
.withEnvironment({ | ||
'MYSQL_DATABASE': 'test', | ||
'TZ': 'Asia/Seoul', | ||
}) | ||
.withCopyFilesToContainer([{ | ||
source: source, | ||
target: '/docker-entrypoint-initdb.d/mysql.sql' | ||
}]) | ||
.start() | ||
|
||
const app = new express() | ||
app.get('/test1', (req, res) => { | ||
res.send('ok get') | ||
|
||
agent.callbackTraceClose(async (trace) => { | ||
const actualBuilder = new MethodDescriptorBuilder(expected('get', 'app.get')) | ||
.setClassName(expected('app', 'Function')) | ||
.setLineNumber(35) | ||
.setFileName('nested-async-trace.test.js') | ||
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) | ||
const actualSpanEvent = trace.span.spanEventList[0] | ||
t.equal(actualMethodDescriptor.apiId, actualSpanEvent.apiId, 'apiId is equal') | ||
t.equal(actualMethodDescriptor.apiDescriptor, expected('app.get', 'Function.app.get'), 'apiDescriptor is equal') | ||
t.equal(actualMethodDescriptor.className, expected('app', 'Function'), 'className is equal') | ||
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName is equal') | ||
t.equal(actualSpanEvent.sequence, 0, 'sequence is 0') | ||
t.equal(actualSpanEvent.depth, 1, 'depth is 0') | ||
await container.stop() | ||
}) | ||
}) | ||
|
||
const server = app.listen(5006, async () => { | ||
const result = await axios.get('http://localhost:5006/test1') | ||
t.equal(result.status, 200, 'status is 200') | ||
|
||
t.end() | ||
server.close() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters