-
-
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(v8/node): Add
openTelemetrySpanProcessors
option (#14853)
- Loading branch information
Showing
14 changed files
with
420 additions
and
5 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 @@ | ||
dist |
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,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
31 changes: 31 additions & 0 deletions
31
dev-packages/e2e-tests/test-applications/node-otel/package.json
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,31 @@ | ||
{ | ||
"name": "node-otel", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc", | ||
"start": "node dist/app.js", | ||
"test": "playwright test", | ||
"clean": "npx rimraf node_modules pnpm-lock.yaml", | ||
"test:build": "pnpm install && pnpm build", | ||
"test:assert": "pnpm test" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/sdk-node": "0.52.1", | ||
"@opentelemetry/exporter-trace-otlp-http": "0.52.1", | ||
"@sentry/core": "latest || *", | ||
"@sentry/node": "latest || *", | ||
"@sentry/opentelemetry": "latest || *", | ||
"@types/express": "4.17.17", | ||
"@types/node": "^18.19.1", | ||
"express": "4.19.2", | ||
"typescript": "~5.0.0" | ||
}, | ||
"devDependencies": { | ||
"@playwright/test": "^1.44.1", | ||
"@sentry-internal/test-utils": "link:../../../test-utils" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
dev-packages/e2e-tests/test-applications/node-otel/playwright.config.mjs
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,34 @@ | ||
import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
||
const config = getPlaywrightConfig( | ||
{ | ||
startCommand: `pnpm start`, | ||
}, | ||
{ | ||
webServer: [ | ||
{ | ||
command: `node ./start-event-proxy.mjs`, | ||
port: 3031, | ||
stdout: 'pipe', | ||
stderr: 'pipe', | ||
}, | ||
{ | ||
command: `node ./start-otel-proxy.mjs`, | ||
port: 3032, | ||
stdout: 'pipe', | ||
stderr: 'pipe', | ||
}, | ||
{ | ||
command: 'pnpm start', | ||
port: 3030, | ||
stdout: 'pipe', | ||
stderr: 'pipe', | ||
env: { | ||
PORT: 3030, | ||
}, | ||
}, | ||
], | ||
}, | ||
); | ||
|
||
export default config; |
53 changes: 53 additions & 0 deletions
53
dev-packages/e2e-tests/test-applications/node-otel/src/app.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,53 @@ | ||
import './instrument'; | ||
|
||
// Other imports below | ||
import * as Sentry from '@sentry/node'; | ||
import express from 'express'; | ||
|
||
const app = express(); | ||
const port = 3030; | ||
|
||
app.get('/test-success', function (req, res) { | ||
res.send({ version: 'v1' }); | ||
}); | ||
|
||
app.get('/test-param/:param', function (req, res) { | ||
res.send({ paramWas: req.params.param }); | ||
}); | ||
|
||
app.get('/test-transaction', function (req, res) { | ||
Sentry.withActiveSpan(null, async () => { | ||
Sentry.startSpan({ name: 'test-transaction', op: 'e2e-test' }, () => { | ||
Sentry.startSpan({ name: 'test-span' }, () => undefined); | ||
}); | ||
|
||
await Sentry.flush(); | ||
|
||
res.send({}); | ||
}); | ||
}); | ||
|
||
app.get('/test-error', async function (req, res) { | ||
const exceptionId = Sentry.captureException(new Error('This is an error')); | ||
|
||
await Sentry.flush(2000); | ||
|
||
res.send({ exceptionId }); | ||
}); | ||
|
||
app.get('/test-exception/:id', function (req, _res) { | ||
throw new Error(`This is an exception with id ${req.params.id}`); | ||
}); | ||
|
||
Sentry.setupExpressErrorHandler(app); | ||
|
||
app.use(function onError(err: unknown, req: any, res: any, next: any) { | ||
// The error id is attached to `res.sentry` to be returned | ||
// and optionally displayed to the user for support. | ||
res.statusCode = 500; | ||
res.end(res.sentry + '\n'); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Example app listening on port ${port}`); | ||
}); |
22 changes: 22 additions & 0 deletions
22
dev-packages/e2e-tests/test-applications/node-otel/src/instrument.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,22 @@ | ||
const opentelemetry = require('@opentelemetry/sdk-node'); | ||
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
const sentryClient = Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: | ||
process.env.E2E_TEST_DSN || | ||
'https://3b6c388182fb435097f41d181be2b2ba@o4504321058471936.ingest.sentry.io/4504321066008576', | ||
debug: !!process.env.DEBUG, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1, | ||
|
||
// Additional OTEL options | ||
openTelemetrySpanProcessors: [ | ||
new opentelemetry.node.BatchSpanProcessor( | ||
new OTLPTraceExporter({ | ||
url: 'http://localhost:3032/', | ||
}), | ||
), | ||
], | ||
}); |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/node-otel/start-event-proxy.mjs
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,6 @@ | ||
import { startEventProxyServer } from '@sentry-internal/test-utils'; | ||
|
||
startEventProxyServer({ | ||
port: 3031, | ||
proxyServerName: 'node-otel', | ||
}); |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/node-otel/start-otel-proxy.mjs
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,6 @@ | ||
import { startProxyServer } from '@sentry-internal/test-utils'; | ||
|
||
startProxyServer({ | ||
port: 3032, | ||
proxyServerName: 'node-otel-otel', | ||
}); |
29 changes: 29 additions & 0 deletions
29
dev-packages/e2e-tests/test-applications/node-otel/tests/errors.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,29 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForError } from '@sentry-internal/test-utils'; | ||
|
||
test('Sends correct error event', async ({ baseURL }) => { | ||
const errorEventPromise = waitForError('node-otel', event => { | ||
return !event.type && event.exception?.values?.[0]?.value === 'This is an exception with id 123'; | ||
}); | ||
|
||
await fetch(`${baseURL}/test-exception/123`); | ||
|
||
const errorEvent = await errorEventPromise; | ||
|
||
expect(errorEvent.exception?.values).toHaveLength(1); | ||
expect(errorEvent.exception?.values?.[0]?.value).toBe('This is an exception with id 123'); | ||
|
||
expect(errorEvent.request).toEqual({ | ||
method: 'GET', | ||
cookies: {}, | ||
headers: expect.any(Object), | ||
url: 'http://localhost:3030/test-exception/123', | ||
}); | ||
|
||
expect(errorEvent.transaction).toEqual('GET /test-exception/:id'); | ||
|
||
expect(errorEvent.contexts?.trace).toEqual({ | ||
trace_id: expect.stringMatching(/[a-f0-9]{32}/), | ||
span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
}); | ||
}); |
Oops, something went wrong.