@contember/engine-http 2.2.0-alpha.14 → 2.2.0-alpha.16

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.
Files changed (27) hide show
  1. package/dist/development/src/application/application.cjs +3 -2
  2. package/dist/development/src/application/application.cjs.map +1 -1
  3. package/dist/development/src/application/application.js +3 -2
  4. package/dist/development/src/application/application.js.map +1 -1
  5. package/dist/development/src/utils/sentry.cjs +1 -0
  6. package/dist/development/src/utils/sentry.cjs.map +1 -1
  7. package/dist/development/src/utils/sentry.js +1 -0
  8. package/dist/development/src/utils/sentry.js.map +1 -1
  9. package/dist/production/src/application/application.cjs +3 -2
  10. package/dist/production/src/application/application.cjs.map +1 -1
  11. package/dist/production/src/application/application.js +3 -2
  12. package/dist/production/src/application/application.js.map +1 -1
  13. package/dist/production/src/utils/sentry.cjs +1 -0
  14. package/dist/production/src/utils/sentry.cjs.map +1 -1
  15. package/dist/production/src/utils/sentry.js +1 -0
  16. package/dist/production/src/utils/sentry.js.map +1 -1
  17. package/dist/tests/cases/unit/sentryLoggerHandler.test.d.ts +2 -0
  18. package/dist/tests/cases/unit/sentryLoggerHandler.test.d.ts.map +1 -0
  19. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  20. package/dist/types/application/application.d.ts.map +1 -1
  21. package/dist/types/tsconfig.tsbuildinfo +1 -1
  22. package/dist/types/utils/sentry.d.ts.map +1 -1
  23. package/package.json +16 -16
  24. package/src/application/application.ts +2 -1
  25. package/src/utils/sentry.ts +1 -0
  26. package/tests/cases/unit/requestTracing.test.ts +19 -2
  27. package/tests/cases/unit/sentryLoggerHandler.test.ts +31 -0
@@ -1 +1 @@
1
- {"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../../src/utils/sentry.ts"],"names":[],"mappings":"AACA,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,QA6BrB;IAED,KAAK,IAAI,IAAI,CACZ;CACD;AAED,eAAO,MAAM,yBAAyB,SAAU,MAAM,KAAG,IAAI,GAAG,aAW/D,CAAA"}
1
+ {"version":3,"file":"sentry.d.ts","sourceRoot":"","sources":["../../../src/utils/sentry.ts"],"names":[],"mappings":"AACA,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,eAAO,MAAM,yBAAyB,SAAU,MAAM,KAAG,IAAI,GAAG,aAW/D,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/engine-http",
3
- "version": "2.2.0-alpha.14",
3
+ "version": "2.2.0-alpha.16",
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.14",
30
- "@contember/database": "2.2.0-alpha.14",
31
- "@contember/database-migrations": "2.2.0-alpha.14",
32
- "@contember/dic": "2.2.0-alpha.14",
33
- "@contember/engine-common": "2.2.0-alpha.14",
34
- "@contember/engine-content-api": "2.2.0-alpha.14",
35
- "@contember/engine-system-api": "2.2.0-alpha.14",
36
- "@contember/engine-tenant-api": "2.2.0-alpha.14",
37
- "@contember/graphql-utils": "2.2.0-alpha.14",
38
- "@contember/logger": "2.2.0-alpha.14",
39
- "@contember/schema": "2.2.0-alpha.14",
40
- "@contember/schema-migrations": "2.2.0-alpha.14",
41
- "@contember/schema-utils": "2.2.0-alpha.14",
42
- "@contember/telemetry": "2.2.0-alpha.14",
43
- "@contember/typesafe": "2.2.0-alpha.14",
29
+ "@contember/config-loader": "2.2.0-alpha.16",
30
+ "@contember/database": "2.2.0-alpha.16",
31
+ "@contember/database-migrations": "2.2.0-alpha.16",
32
+ "@contember/dic": "2.2.0-alpha.16",
33
+ "@contember/engine-common": "2.2.0-alpha.16",
34
+ "@contember/engine-content-api": "2.2.0-alpha.16",
35
+ "@contember/engine-system-api": "2.2.0-alpha.16",
36
+ "@contember/engine-tenant-api": "2.2.0-alpha.16",
37
+ "@contember/graphql-utils": "2.2.0-alpha.16",
38
+ "@contember/logger": "2.2.0-alpha.16",
39
+ "@contember/schema": "2.2.0-alpha.16",
40
+ "@contember/schema-migrations": "2.2.0-alpha.16",
41
+ "@contember/schema-utils": "2.2.0-alpha.16",
42
+ "@contember/telemetry": "2.2.0-alpha.16",
43
+ "@contember/typesafe": "2.2.0-alpha.16",
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
@@ -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({
@@ -28,7 +28,8 @@ const createTestApplication = () => {
28
28
  shutdown: async () => {},
29
29
  }
30
30
  const tracer = createTracer({ processor })
31
- const logger = createLogger(new TestLoggerHandler())
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,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
+ })