@contember/engine-http 2.2.0-alpha.15 → 2.2.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/index.cjs +1 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +2 -1
- package/dist/development/src/application/application.cjs +3 -2
- package/dist/development/src/application/application.cjs.map +1 -1
- package/dist/development/src/application/application.js +3 -2
- package/dist/development/src/application/application.js.map +1 -1
- package/dist/development/src/utils/sentry.cjs +4 -3
- package/dist/development/src/utils/sentry.cjs.map +1 -1
- package/dist/development/src/utils/sentry.js +5 -4
- package/dist/development/src/utils/sentry.js.map +1 -1
- package/dist/production/index.cjs +1 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +2 -1
- package/dist/production/src/application/application.cjs +3 -2
- package/dist/production/src/application/application.cjs.map +1 -1
- package/dist/production/src/application/application.js +3 -2
- package/dist/production/src/application/application.js.map +1 -1
- package/dist/production/src/utils/sentry.cjs +4 -3
- package/dist/production/src/utils/sentry.cjs.map +1 -1
- package/dist/production/src/utils/sentry.js +5 -4
- package/dist/production/src/utils/sentry.js.map +1 -1
- package/dist/tests/cases/unit/sentryIntegrations.test.d.ts +2 -0
- package/dist/tests/cases/unit/sentryIntegrations.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/sentryLoggerHandler.test.d.ts +2 -0
- package/dist/tests/cases/unit/sentryLoggerHandler.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/application/application.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/sentry.d.ts +4 -0
- package/dist/types/utils/sentry.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/application/application.ts +2 -1
- package/src/utils/sentry.ts +9 -3
- package/tests/cases/unit/requestTracing.test.ts +19 -2
- package/tests/cases/unit/sentryIntegrations.test.ts +15 -0
- package/tests/cases/unit/sentryLoggerHandler.test.ts +31 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as Sentry from '@sentry/node';
|
|
1
2
|
import { LogEntry, LoggerHandler, LogLevel } from '@contember/logger';
|
|
2
3
|
export declare class SentryLoggerHandler implements LoggerHandler {
|
|
3
4
|
private readonly logLevel;
|
|
@@ -6,5 +7,8 @@ export declare class SentryLoggerHandler implements LoggerHandler {
|
|
|
6
7
|
handle(entry: LogEntry): void;
|
|
7
8
|
close(): void;
|
|
8
9
|
}
|
|
10
|
+
type SentryIntegration = ReturnType<typeof Sentry.getDefaultIntegrations>[number];
|
|
11
|
+
export declare const filterSentryIntegrations: (integrations: SentryIntegration[]) => SentryIntegration[];
|
|
9
12
|
export declare const createSentryLoggerHandler: (dsn?: string) => null | LoggerHandler;
|
|
13
|
+
export {};
|
|
10
14
|
//# sourceMappingURL=sentry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../../src/utils/sentry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../../src/utils/sentry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAA2B,MAAM,mBAAmB,CAAA;AAW9F,qBAAa,mBAAoB,YAAW,aAAa;IAEvD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAD1B,YACkB,QAAQ,EAAE,QAAQ,EAEnC;IAED,WAAW,IAAI,MAAM,CAEpB;IAED,MAAM,CAAC,KAAK,EAAE,QAAQ,QA8BrB;IAED,KAAK,IAAI,IAAI,CACZ;CACD;AAED,KAAK,iBAAiB,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;AAIjF,eAAO,MAAM,wBAAwB,iBAAkB,iBAAiB,EAAE,KAAG,iBAAiB,EACA,CAAA;AAE9F,eAAO,MAAM,yBAAyB,SAAU,MAAM,KAAG,IAAI,GAAG,aAS/D,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-http",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
3
|
+
"version": "2.2.0-alpha.17",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -26,21 +26,21 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contember/config-loader": "2.2.0-alpha.
|
|
30
|
-
"@contember/database": "2.2.0-alpha.
|
|
31
|
-
"@contember/database-migrations": "2.2.0-alpha.
|
|
32
|
-
"@contember/dic": "2.2.0-alpha.
|
|
33
|
-
"@contember/engine-common": "2.2.0-alpha.
|
|
34
|
-
"@contember/engine-content-api": "2.2.0-alpha.
|
|
35
|
-
"@contember/engine-system-api": "2.2.0-alpha.
|
|
36
|
-
"@contember/engine-tenant-api": "2.2.0-alpha.
|
|
37
|
-
"@contember/graphql-utils": "2.2.0-alpha.
|
|
38
|
-
"@contember/logger": "2.2.0-alpha.
|
|
39
|
-
"@contember/schema": "2.2.0-alpha.
|
|
40
|
-
"@contember/schema-migrations": "2.2.0-alpha.
|
|
41
|
-
"@contember/schema-utils": "2.2.0-alpha.
|
|
42
|
-
"@contember/telemetry": "2.2.0-alpha.
|
|
43
|
-
"@contember/typesafe": "2.2.0-alpha.
|
|
29
|
+
"@contember/config-loader": "2.2.0-alpha.17",
|
|
30
|
+
"@contember/database": "2.2.0-alpha.17",
|
|
31
|
+
"@contember/database-migrations": "2.2.0-alpha.17",
|
|
32
|
+
"@contember/dic": "2.2.0-alpha.17",
|
|
33
|
+
"@contember/engine-common": "2.2.0-alpha.17",
|
|
34
|
+
"@contember/engine-content-api": "2.2.0-alpha.17",
|
|
35
|
+
"@contember/engine-system-api": "2.2.0-alpha.17",
|
|
36
|
+
"@contember/engine-tenant-api": "2.2.0-alpha.17",
|
|
37
|
+
"@contember/graphql-utils": "2.2.0-alpha.17",
|
|
38
|
+
"@contember/logger": "2.2.0-alpha.17",
|
|
39
|
+
"@contember/schema": "2.2.0-alpha.17",
|
|
40
|
+
"@contember/schema-migrations": "2.2.0-alpha.17",
|
|
41
|
+
"@contember/schema-utils": "2.2.0-alpha.17",
|
|
42
|
+
"@contember/telemetry": "2.2.0-alpha.17",
|
|
43
|
+
"@contember/typesafe": "2.2.0-alpha.17",
|
|
44
44
|
"@graphql-tools/merge": "^9.1.7",
|
|
45
45
|
"@graphql-tools/schema": "^10.0.31",
|
|
46
46
|
"@koa/cors": "^5.0.0",
|
|
@@ -205,7 +205,7 @@ export class Application {
|
|
|
205
205
|
try {
|
|
206
206
|
requestLogger = this.createRequestLogger(req, undefined, matchedRequest.module, clientIp, span.context)
|
|
207
207
|
const groupContainer = await this.projectGroupResolver.resolveContainer({ request: req })
|
|
208
|
-
requestLogger = requestLogger.child({ projectGroup: groupContainer.slug })
|
|
208
|
+
requestLogger = requestLogger.child({ projectGroup: groupContainer.slug, project: matchedRequest.params.projectSlug })
|
|
209
209
|
span.setAttribute('contember.project_group', groupContainer.slug ?? 'unknown')
|
|
210
210
|
if (matchedRequest.params.projectSlug !== undefined) {
|
|
211
211
|
span.setAttribute('contember.project', matchedRequest.params.projectSlug)
|
|
@@ -373,6 +373,7 @@ export class Application {
|
|
|
373
373
|
const groupContainer = await this.projectGroupResolver.resolveContainer({ request: ctx.req })
|
|
374
374
|
requestLogger = requestLogger.child({
|
|
375
375
|
projectGroup: groupContainer.slug,
|
|
376
|
+
project: matchedRequest.params.projectSlug,
|
|
376
377
|
})
|
|
377
378
|
ctx.state.projectGroup = groupContainer.slug
|
|
378
379
|
ctx.state.project = matchedRequest.params.projectSlug
|
package/src/utils/sentry.ts
CHANGED
|
@@ -26,6 +26,7 @@ export class SentryLoggerHandler implements LoggerHandler {
|
|
|
26
26
|
}
|
|
27
27
|
Sentry.captureException(entry.error, scope => {
|
|
28
28
|
scope.setTag('project', entry.loggerAttributes.project ?? entry.ownAttributes.project)
|
|
29
|
+
scope.setTag('projectGroup', entry.loggerAttributes.projectGroup ?? entry.ownAttributes.projectGroup)
|
|
29
30
|
scope.setTag('module', entry.loggerAttributes.module ?? entry.ownAttributes.module)
|
|
30
31
|
scope.setLevel(logLevelMapping[entry.level.name])
|
|
31
32
|
scope.setUser({
|
|
@@ -55,15 +56,20 @@ export class SentryLoggerHandler implements LoggerHandler {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
type SentryIntegration = ReturnType<typeof Sentry.getDefaultIntegrations>[number]
|
|
60
|
+
|
|
61
|
+
// Undici (fetch) would record outgoing request URLs, which may carry a webhook credential in the path or query,
|
|
62
|
+
// in breadcrumbs and spans, and add Sentry trace headers to every webhook request.
|
|
63
|
+
export const filterSentryIntegrations = (integrations: SentryIntegration[]): SentryIntegration[] =>
|
|
64
|
+
integrations.filter(integration => !['Console', 'Http', 'Undici'].includes(integration.name))
|
|
65
|
+
|
|
58
66
|
export const createSentryLoggerHandler = (dsn?: string): null | LoggerHandler => {
|
|
59
67
|
if (!dsn) {
|
|
60
68
|
return null
|
|
61
69
|
}
|
|
62
70
|
Sentry.init({
|
|
63
71
|
dsn: dsn,
|
|
64
|
-
integrations:
|
|
65
|
-
return integrations.filter(integration => integration.name !== 'Console' && integration.name !== 'Http')
|
|
66
|
-
},
|
|
72
|
+
integrations: filterSentryIntegrations,
|
|
67
73
|
})
|
|
68
74
|
return new SentryLoggerHandler(LogLevels.warn)
|
|
69
75
|
}
|
|
@@ -28,7 +28,8 @@ const createTestApplication = () => {
|
|
|
28
28
|
shutdown: async () => {},
|
|
29
29
|
}
|
|
30
30
|
const tracer = createTracer({ processor })
|
|
31
|
-
const
|
|
31
|
+
const loggerHandler = new TestLoggerHandler()
|
|
32
|
+
const logger = createLogger(loggerHandler)
|
|
32
33
|
const authenticator = createMock<Authenticator>({
|
|
33
34
|
authenticate: async ({ timer }) => await timer('Auth', async () => new VerifyResult('identity', 'api-key', ['member'], null)),
|
|
34
35
|
})
|
|
@@ -68,7 +69,7 @@ const createTestApplication = () => {
|
|
|
68
69
|
port: 0,
|
|
69
70
|
telemetry: { traces: { acceptIncoming: 'all', traceIdResponseHeader: true } },
|
|
70
71
|
})
|
|
71
|
-
return { application: new Application(projectGroupResolver, config, false, undefined, logger, tracer), spans }
|
|
72
|
+
return { application: new Application(projectGroupResolver, config, false, undefined, logger, tracer), spans, loggerHandler }
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
const listen = async (application: Application): Promise<{ running: RunningApplication; httpUrl: string; wsUrl: string }> => {
|
|
@@ -125,6 +126,22 @@ test('records a matched HTTP request with its context and excludes an unmatched
|
|
|
125
126
|
}
|
|
126
127
|
})
|
|
127
128
|
|
|
129
|
+
test('the request logger names the project group and the project, so error reporting can tag both', async () => {
|
|
130
|
+
const { application, loggerHandler } = createTestApplication()
|
|
131
|
+
application.addRoute('actions', '/actions/:projectSlug', ({ logger }) => {
|
|
132
|
+
logger.warn('from the controller')
|
|
133
|
+
return new HttpResponse(200, 'ok')
|
|
134
|
+
})
|
|
135
|
+
const { running, httpUrl } = await listen(application)
|
|
136
|
+
try {
|
|
137
|
+
expect((await fetch(`${httpUrl}/actions/article`)).status).toBe(200)
|
|
138
|
+
const entry = loggerHandler.messages.find(it => it.message === 'from the controller')
|
|
139
|
+
expect(entry?.loggerAttributes).toMatchObject({ projectGroup: 'group', project: 'article' })
|
|
140
|
+
} finally {
|
|
141
|
+
await running.close()
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
|
|
128
145
|
test('marks handled server errors as failed without exporting multiline details', async () => {
|
|
129
146
|
const { application, spans } = createTestApplication()
|
|
130
147
|
application.addRoute('content', '/handled', () => new HttpErrorResponse(503, 'Unavailable'))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
|
+
import * as Sentry from '@sentry/node'
|
|
3
|
+
import { filterSentryIntegrations } from '../../../src/utils/sentry.js'
|
|
4
|
+
|
|
5
|
+
test('outgoing requests are not instrumented, so their URLs stay out of breadcrumbs and spans', () => {
|
|
6
|
+
const defaults = Sentry.getDefaultIntegrations({}).map(it => it.name)
|
|
7
|
+
expect(defaults).toContain('Undici')
|
|
8
|
+
|
|
9
|
+
const kept = filterSentryIntegrations(Sentry.getDefaultIntegrations({})).map(it => it.name)
|
|
10
|
+
|
|
11
|
+
expect(kept).toContain('LinkedErrors')
|
|
12
|
+
for (const name of ['Undici', 'Http', 'Console']) {
|
|
13
|
+
expect(kept).not.toContain(name)
|
|
14
|
+
}
|
|
15
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { afterAll, beforeAll, expect, test } from 'bun:test'
|
|
2
|
+
import * as Sentry from '@sentry/node'
|
|
3
|
+
import { createLogger, LogLevels } from '@contember/logger'
|
|
4
|
+
import { SentryLoggerHandler } from '../../../src/utils/sentry.js'
|
|
5
|
+
|
|
6
|
+
const captured: Sentry.Event[] = []
|
|
7
|
+
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
Sentry.init({
|
|
10
|
+
dsn: 'https://public@sentry.invalid/1',
|
|
11
|
+
defaultIntegrations: false,
|
|
12
|
+
beforeSend: event => {
|
|
13
|
+
captured.push(event)
|
|
14
|
+
return null
|
|
15
|
+
},
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
afterAll(async () => {
|
|
20
|
+
await Sentry.close()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('tags an event with both the project group and the project', async () => {
|
|
24
|
+
const logger = createLogger(new SentryLoggerHandler(LogLevels.warn)).child({ projectGroup: 'group', project: 'blog' })
|
|
25
|
+
|
|
26
|
+
logger.warn(new Error('Webhook request failed'))
|
|
27
|
+
await Sentry.flush(1_000)
|
|
28
|
+
|
|
29
|
+
expect(captured).toHaveLength(1)
|
|
30
|
+
expect(captured[0].tags).toMatchObject({ projectGroup: 'group', project: 'blog' })
|
|
31
|
+
})
|