-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(node): Add tests for current DSC transaction name updating behavior #13961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
dev-packages/node-integration-tests/suites/tracing/dsc-txn-name-update/scenario-events.ts
This file contains hidden or 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,29 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan( | ||
{ name: 'initial-name', attributes: { [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url' } }, | ||
async span => { | ||
Sentry.captureMessage('message-1'); | ||
|
||
span.updateName('updated-name-1'); | ||
span.setAttribute(Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route'); | ||
|
||
Sentry.captureMessage('message-2'); | ||
|
||
span.updateName('updated-name-2'); | ||
span.setAttribute(Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'custom'); | ||
|
||
Sentry.captureMessage('message-3'); | ||
|
||
span.end(); | ||
}, | ||
); |
45 changes: 45 additions & 0 deletions
45
dev-packages/node-integration-tests/suites/tracing/dsc-txn-name-update/scenario-headers.ts
This file contains hidden or 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,45 @@ | ||
import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
}); | ||
|
||
import * as http from 'http'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
Sentry.startSpan( | ||
{ name: 'initial-name', attributes: { [Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url' } }, | ||
async span => { | ||
await makeHttpRequest(`${process.env.SERVER_URL}/api/v0`); | ||
|
||
span.updateName('updated-name-1'); | ||
span.setAttribute(Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route'); | ||
|
||
await makeHttpRequest(`${process.env.SERVER_URL}/api/v1`); | ||
|
||
span.updateName('updated-name-2'); | ||
span.setAttribute(Sentry.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'custom'); | ||
await makeHttpRequest(`${process.env.SERVER_URL}/api/v2`); | ||
|
||
span.end(); | ||
}, | ||
); | ||
|
||
function makeHttpRequest(url: string): Promise<void> { | ||
return new Promise<void>(resolve => { | ||
http | ||
.request(url, httpRes => { | ||
httpRes.on('data', () => { | ||
// we don't care about data | ||
}); | ||
httpRes.on('end', () => { | ||
resolve(); | ||
}); | ||
}) | ||
.end(); | ||
}); | ||
} |
123 changes: 123 additions & 0 deletions
123
dev-packages/node-integration-tests/suites/tracing/dsc-txn-name-update/test.ts
This file contains hidden or 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,123 @@ | ||
import { createRunner } from '../../../utils/runner'; | ||
import { createTestServer } from '../../../utils/server'; | ||
|
||
test('adds current transaction name to baggage when the txn name is high-quality', done => { | ||
expect.assertions(5); | ||
|
||
let traceId: string | undefined; | ||
|
||
createTestServer(done) | ||
.get('/api/v0', headers => { | ||
const baggageItems = getBaggageHeaderItems(headers); | ||
traceId = baggageItems.find(item => item.startsWith('sentry-trace_id='))?.split('=')[1] as string; | ||
|
||
expect(traceId).toMatch(/^[0-9a-f]{32}$/); | ||
|
||
expect(baggageItems).toEqual([ | ||
'sentry-environment=production', | ||
'sentry-public_key=public', | ||
'sentry-release=1.0', | ||
'sentry-sample_rate=1', | ||
'sentry-sampled=true', | ||
`sentry-trace_id=${traceId}`, | ||
]); | ||
}) | ||
.get('/api/v1', headers => { | ||
expect(getBaggageHeaderItems(headers)).toEqual([ | ||
'sentry-environment=production', | ||
'sentry-public_key=public', | ||
'sentry-release=1.0', | ||
'sentry-sample_rate=1', | ||
'sentry-sampled=true', | ||
`sentry-trace_id=${traceId}`, | ||
'sentry-transaction=updated-name-1', | ||
]); | ||
}) | ||
.get('/api/v2', headers => { | ||
expect(getBaggageHeaderItems(headers)).toEqual([ | ||
'sentry-environment=production', | ||
'sentry-public_key=public', | ||
'sentry-release=1.0', | ||
'sentry-sample_rate=1', | ||
'sentry-sampled=true', | ||
`sentry-trace_id=${traceId}`, | ||
'sentry-transaction=updated-name-2', | ||
]); | ||
}) | ||
.start() | ||
.then(([SERVER_URL, closeTestServer]) => { | ||
createRunner(__dirname, 'scenario-headers.ts') | ||
.withEnv({ SERVER_URL }) | ||
.expect({ | ||
transaction: {}, | ||
}) | ||
.start(closeTestServer); | ||
}); | ||
}); | ||
|
||
test('adds current transaction name to trace envelope header when the txn name is high-quality', done => { | ||
expect.assertions(4); | ||
|
||
createRunner(__dirname, 'scenario-events.ts') | ||
.expectHeader({ | ||
event: { | ||
trace: { | ||
environment: 'production', | ||
public_key: 'public', | ||
release: '1.0', | ||
sample_rate: '1', | ||
sampled: 'true', | ||
trace_id: expect.any(String), | ||
}, | ||
}, | ||
}) | ||
.expectHeader({ | ||
event: { | ||
trace: { | ||
environment: 'production', | ||
public_key: 'public', | ||
release: '1.0', | ||
sample_rate: '1', | ||
sampled: 'true', | ||
trace_id: expect.any(String), | ||
transaction: 'updated-name-1', | ||
}, | ||
}, | ||
}) | ||
.expectHeader({ | ||
event: { | ||
trace: { | ||
environment: 'production', | ||
public_key: 'public', | ||
release: '1.0', | ||
sample_rate: '1', | ||
sampled: 'true', | ||
trace_id: expect.any(String), | ||
transaction: 'updated-name-2', | ||
}, | ||
}, | ||
}) | ||
.expectHeader({ | ||
transaction: { | ||
trace: { | ||
environment: 'production', | ||
public_key: 'public', | ||
release: '1.0', | ||
sample_rate: '1', | ||
sampled: 'true', | ||
trace_id: expect.any(String), | ||
transaction: 'updated-name-2', | ||
}, | ||
}, | ||
}) | ||
.start(done); | ||
}); | ||
|
||
function getBaggageHeaderItems(headers: Record<string, string | string[] | undefined>) { | ||
const baggage = headers['baggage'] as string; | ||
const baggageItems = baggage | ||
.split(',') | ||
.map(b => b.trim()) | ||
.sort(); | ||
return baggageItems; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fought multiple hours with our test runner to get these tests working. Very frustrating.
Turns out, you can't assert on headers in the test server as well as on events in the same test. It will appear as if it's working but it won't fail if an assertion actually fails :/
moreover, there#s also super weird inter operation between
expect
andecpectHeaders
when you want to check on an event and its headers. After trying to make everything work in one test, I eventually gave up and made one forbaggage
and one for thetrace
envelope header.I think part of the problem is that there is some race condition with the test server and the test runners both calling
done
which completely fucks up the assertion count.