@terreno/api 0.14.0 → 0.14.2
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/__tests__/versionCheckPlugin.test.js +119 -0
- package/dist/betterAuthSetup.js +13 -3
- package/dist/config.js +12 -3
- package/dist/errors.js +5 -2
- package/dist/example.js +3 -0
- package/dist/expressServer.test.js +231 -0
- package/dist/realtime/changeStreamWatcher.js +6 -2
- package/dist/realtime/realtime.test.js +1785 -0
- package/dist/requestContext.test.js +143 -0
- package/package.json +1 -1
- package/src/__tests__/versionCheckPlugin.test.ts +81 -0
- package/src/betterAuthSetup.ts +13 -3
- package/src/config.ts +13 -3
- package/src/errors.ts +24 -18
- package/src/example.ts +3 -0
- package/src/expressServer.test.ts +176 -0
- package/src/realtime/changeStreamWatcher.ts +6 -2
- package/src/realtime/realtime.test.ts +1415 -1
- package/src/requestContext.test.ts +125 -0
|
@@ -164,6 +164,131 @@ describe("request context job propagation", () => {
|
|
|
164
164
|
});
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
+
it("parses Google Cloud trace context header in middleware", async () => {
|
|
168
|
+
const app = express();
|
|
169
|
+
app.use(requestContextMiddleware);
|
|
170
|
+
app.get("/trace-gcloud", (_req, res) => {
|
|
171
|
+
const ctx = getCurrentRequestContext();
|
|
172
|
+
res.json({
|
|
173
|
+
spanId: ctx?.spanId,
|
|
174
|
+
traceId: ctx?.traceId,
|
|
175
|
+
traceSampled: ctx?.traceSampled,
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const res = await supertest(app)
|
|
180
|
+
.get("/trace-gcloud")
|
|
181
|
+
.set("X-Cloud-Trace-Context", "105445aa7843bc8bf206b12000100000/1;o=1")
|
|
182
|
+
.expect(200);
|
|
183
|
+
|
|
184
|
+
expect(res.body.traceId).toBe("105445aa7843bc8bf206b12000100000");
|
|
185
|
+
expect(res.body.spanId).toBe("1");
|
|
186
|
+
expect(res.body.traceSampled).toBe(true);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("parses Google Cloud trace context without trace sampling", async () => {
|
|
190
|
+
const app = express();
|
|
191
|
+
app.use(requestContextMiddleware);
|
|
192
|
+
app.get("/trace-gcloud-nosample", (_req, res) => {
|
|
193
|
+
const ctx = getCurrentRequestContext();
|
|
194
|
+
res.json({
|
|
195
|
+
spanId: ctx?.spanId,
|
|
196
|
+
traceId: ctx?.traceId,
|
|
197
|
+
traceSampled: ctx?.traceSampled,
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const res = await supertest(app)
|
|
202
|
+
.get("/trace-gcloud-nosample")
|
|
203
|
+
.set("X-Cloud-Trace-Context", "abc123/42;o=0")
|
|
204
|
+
.expect(200);
|
|
205
|
+
|
|
206
|
+
expect(res.body.traceId).toBe("abc123");
|
|
207
|
+
expect(res.body.spanId).toBe("42");
|
|
208
|
+
expect(res.body.traceSampled).toBe(false);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("falls back to traceparent when cloud trace context is absent", async () => {
|
|
212
|
+
const app = express();
|
|
213
|
+
app.use(requestContextMiddleware);
|
|
214
|
+
app.get("/trace-parent", (_req, res) => {
|
|
215
|
+
const ctx = getCurrentRequestContext();
|
|
216
|
+
res.json({
|
|
217
|
+
spanId: ctx?.spanId,
|
|
218
|
+
traceId: ctx?.traceId,
|
|
219
|
+
traceSampled: ctx?.traceSampled,
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
const res = await supertest(app)
|
|
224
|
+
.get("/trace-parent")
|
|
225
|
+
.set("traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01")
|
|
226
|
+
.expect(200);
|
|
227
|
+
|
|
228
|
+
expect(res.body.traceId).toBe("4bf92f3577b34da6a3ce929d0e0e4736");
|
|
229
|
+
expect(res.body.spanId).toBe("00f067aa0ba902b7");
|
|
230
|
+
expect(res.body.traceSampled).toBe(true);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("uses trace id as request id when no explicit request id header is set", async () => {
|
|
234
|
+
const app = express();
|
|
235
|
+
app.use(requestContextMiddleware);
|
|
236
|
+
app.get("/trace-request-id", (_req, res) => {
|
|
237
|
+
const ctx = getCurrentRequestContext();
|
|
238
|
+
res.json({requestId: ctx?.requestId});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
const res = await supertest(app)
|
|
242
|
+
.get("/trace-request-id")
|
|
243
|
+
.set("X-Cloud-Trace-Context", "trace-as-rid/99;o=1")
|
|
244
|
+
.expect(200);
|
|
245
|
+
|
|
246
|
+
expect(res.body.requestId).toBe("trace-as-rid");
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("handles traceSampled attribute values 'true', '1', 'false', '0'", () => {
|
|
250
|
+
const ctxTrue = getRequestContextFromAttributes({
|
|
251
|
+
"x-request-id": "r1",
|
|
252
|
+
"x-trace-sampled": "true",
|
|
253
|
+
});
|
|
254
|
+
expect(ctxTrue.traceSampled).toBe(true);
|
|
255
|
+
|
|
256
|
+
const ctx1 = getRequestContextFromAttributes({
|
|
257
|
+
"x-request-id": "r2",
|
|
258
|
+
"x-trace-sampled": "1",
|
|
259
|
+
});
|
|
260
|
+
expect(ctx1.traceSampled).toBe(true);
|
|
261
|
+
|
|
262
|
+
const ctxFalse = getRequestContextFromAttributes({
|
|
263
|
+
"x-request-id": "r3",
|
|
264
|
+
"x-trace-sampled": "false",
|
|
265
|
+
});
|
|
266
|
+
expect(ctxFalse.traceSampled).toBe(false);
|
|
267
|
+
|
|
268
|
+
const ctx0 = getRequestContextFromAttributes({
|
|
269
|
+
"x-request-id": "r4",
|
|
270
|
+
"x-trace-sampled": "0",
|
|
271
|
+
});
|
|
272
|
+
expect(ctx0.traceSampled).toBe(false);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("parses Google Cloud trace context with missing span id", () => {
|
|
276
|
+
const ctx = getRequestContextFromAttributes({
|
|
277
|
+
"x-cloud-trace-context": "only-trace-id",
|
|
278
|
+
"x-request-id": "r5",
|
|
279
|
+
});
|
|
280
|
+
expect(ctx.traceId).toBe("only-trace-id");
|
|
281
|
+
expect(ctx.spanId).toBeUndefined();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("returns undefined trace when traceparent has empty trace id", () => {
|
|
285
|
+
const ctx = getRequestContextFromAttributes({
|
|
286
|
+
traceparent: "00--span-01",
|
|
287
|
+
"x-request-id": "r6",
|
|
288
|
+
});
|
|
289
|
+
expect(ctx.traceId).toBeUndefined();
|
|
290
|
+
});
|
|
291
|
+
|
|
167
292
|
it("adds job id to logger context", () => {
|
|
168
293
|
let output = "";
|
|
169
294
|
const stream = new Writable({
|