-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): Allow to pass instrumentation config to
httpIntegration
- Loading branch information
Showing
7 changed files
with
201 additions
and
29 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
dev-packages/node-integration-tests/suites/express/tracing/test.ts
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
38 changes: 38 additions & 0 deletions
38
dev-packages/node-integration-tests/suites/tracing/httpIntegration/server-experimental.js
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,38 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
// disable attaching headers to /test/* endpoints | ||
tracePropagationTargets: [/^(?!.*test).*$/], | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
|
||
integrations: [ | ||
Sentry.httpIntegration({ | ||
instrumentation: { | ||
_experimentalConfig: { | ||
serverName: 'sentry-test-server-name', | ||
}, | ||
}, | ||
}), | ||
], | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const { startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/test', (_req, res) => { | ||
res.send({ response: 'response 1' }); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
58 changes: 58 additions & 0 deletions
58
dev-packages/node-integration-tests/suites/tracing/httpIntegration/server.js
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,58 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
// disable attaching headers to /test/* endpoints | ||
tracePropagationTargets: [/^(?!.*test).*$/], | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
|
||
integrations: [ | ||
Sentry.httpIntegration({ | ||
instrumentation: { | ||
requestHook: (span, req) => { | ||
span.setAttribute('attr1', 'yes'); | ||
Sentry.setExtra('requestHookCalled', { | ||
url: req.url, | ||
method: req.method, | ||
}); | ||
}, | ||
responseHook: (span, res) => { | ||
span.setAttribute('attr2', 'yes'); | ||
Sentry.setExtra('responseHookCalled', { | ||
url: res.req.url, | ||
method: res.req.method, | ||
}); | ||
}, | ||
applyCustomAttributesOnSpan: (span, req, res) => { | ||
span.setAttribute('attr3', 'yes'); | ||
Sentry.setExtra('applyCustomAttributesOnSpanCalled', { | ||
reqUrl: req.url, | ||
reqMethod: req.method, | ||
resUrl: res.req.url, | ||
resMethod: res.req.method, | ||
}); | ||
}, | ||
}, | ||
}), | ||
], | ||
}); | ||
|
||
// express must be required after Sentry is initialized | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
const { startExpressServerAndSendPortToRunner } = require('@sentry-internal/node-integration-tests'); | ||
|
||
const app = express(); | ||
|
||
app.use(cors()); | ||
|
||
app.get('/test', (_req, res) => { | ||
res.send({ response: 'response 1' }); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
startExpressServerAndSendPortToRunner(app); |
73 changes: 73 additions & 0 deletions
73
dev-packages/node-integration-tests/suites/tracing/httpIntegration/test.ts
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,73 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
describe('httpIntegration', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('allows to pass instrumentation options to integration', done => { | ||
createRunner(__dirname, 'server.js') | ||
.ignore('session', 'sessions') | ||
.expect({ | ||
transaction: { | ||
contexts: { | ||
trace: { | ||
span_id: expect.any(String), | ||
trace_id: expect.any(String), | ||
data: { | ||
url: expect.stringMatching(/\/test$/), | ||
'http.response.status_code': 200, | ||
attr1: 'yes', | ||
attr2: 'yes', | ||
attr3: 'yes', | ||
}, | ||
op: 'http.server', | ||
status: 'ok', | ||
}, | ||
}, | ||
extra: { | ||
requestHookCalled: { | ||
url: expect.stringMatching(/\/test$/), | ||
method: 'GET', | ||
}, | ||
responseHookCalled: { | ||
url: expect.stringMatching(/\/test$/), | ||
method: 'GET', | ||
}, | ||
applyCustomAttributesOnSpanCalled: { | ||
reqUrl: expect.stringMatching(/\/test$/), | ||
reqMethod: 'GET', | ||
resUrl: expect.stringMatching(/\/test$/), | ||
resMethod: 'GET', | ||
}, | ||
}, | ||
}, | ||
}) | ||
.start(done) | ||
.makeRequest('get', '/test'); | ||
}); | ||
|
||
test('allows to pass experimental config through to integration', done => { | ||
createRunner(__dirname, 'server-experimental.js') | ||
.ignore('session', 'sessions') | ||
.expect({ | ||
transaction: { | ||
contexts: { | ||
trace: { | ||
span_id: expect.any(String), | ||
trace_id: expect.any(String), | ||
data: { | ||
url: expect.stringMatching(/\/test$/), | ||
'http.response.status_code': 200, | ||
'http.server_name': 'sentry-test-server-name', | ||
}, | ||
op: 'http.server', | ||
status: 'ok', | ||
}, | ||
}, | ||
}, | ||
}) | ||
.start(done) | ||
.makeRequest('get', '/test'); | ||
}); | ||
}); |
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
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