@replit/river 0.23.6 → 0.23.7

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 (65) hide show
  1. package/README.md +10 -3
  2. package/dist/{chunk-ZFN6I2GJ.js → chunk-2KC75LS4.js} +2 -2
  3. package/dist/{chunk-GX2YS7BY.js → chunk-6LCL2ZZF.js} +17 -31
  4. package/dist/chunk-6LCL2ZZF.js.map +1 -0
  5. package/dist/{chunk-7E53HHNS.js → chunk-M3TGXFWT.js} +33 -31
  6. package/dist/chunk-M3TGXFWT.js.map +1 -0
  7. package/dist/{chunk-2PSMEETT.js → chunk-MFF6IPBA.js} +24 -11
  8. package/dist/{chunk-2PSMEETT.js.map → chunk-MFF6IPBA.js.map} +1 -1
  9. package/dist/{chunk-NJJYBNYM.js → chunk-RLVU5DRX.js} +2 -2
  10. package/dist/{chunk-NB3OHLXB.js → chunk-XYFXRL7Q.js} +165 -101
  11. package/dist/chunk-XYFXRL7Q.js.map +1 -0
  12. package/dist/{connection-e257f6b7.d.ts → connection-6ce35bd5.d.ts} +1 -1
  13. package/dist/{connection-5331d77f.d.ts → connection-a3fdfa3a.d.ts} +1 -1
  14. package/dist/{index-926aea33.d.ts → index-60f03cb7.d.ts} +5 -2
  15. package/dist/logging/index.cjs +6 -73
  16. package/dist/logging/index.cjs.map +1 -1
  17. package/dist/logging/index.d.cts +1 -1
  18. package/dist/logging/index.d.ts +1 -1
  19. package/dist/logging/index.js +1 -3
  20. package/dist/router/index.cjs +47 -33
  21. package/dist/router/index.cjs.map +1 -1
  22. package/dist/router/index.d.cts +6 -6
  23. package/dist/router/index.d.ts +6 -6
  24. package/dist/router/index.js +2 -3
  25. package/dist/{services-3f99f5d2.d.ts → services-fd8a9894.d.ts} +2 -2
  26. package/dist/transport/impls/uds/client.cjs +195 -81
  27. package/dist/transport/impls/uds/client.cjs.map +1 -1
  28. package/dist/transport/impls/uds/client.d.cts +3 -3
  29. package/dist/transport/impls/uds/client.d.ts +3 -3
  30. package/dist/transport/impls/uds/client.js +5 -7
  31. package/dist/transport/impls/uds/client.js.map +1 -1
  32. package/dist/transport/impls/uds/server.cjs +170 -73
  33. package/dist/transport/impls/uds/server.cjs.map +1 -1
  34. package/dist/transport/impls/uds/server.d.cts +3 -3
  35. package/dist/transport/impls/uds/server.d.ts +3 -3
  36. package/dist/transport/impls/uds/server.js +4 -4
  37. package/dist/transport/impls/ws/client.cjs +194 -80
  38. package/dist/transport/impls/ws/client.cjs.map +1 -1
  39. package/dist/transport/impls/ws/client.d.cts +3 -3
  40. package/dist/transport/impls/ws/client.d.ts +3 -3
  41. package/dist/transport/impls/ws/client.js +6 -8
  42. package/dist/transport/impls/ws/client.js.map +1 -1
  43. package/dist/transport/impls/ws/server.cjs +170 -73
  44. package/dist/transport/impls/ws/server.cjs.map +1 -1
  45. package/dist/transport/impls/ws/server.d.cts +3 -3
  46. package/dist/transport/impls/ws/server.d.ts +3 -3
  47. package/dist/transport/impls/ws/server.js +4 -4
  48. package/dist/transport/index.cjs +219 -105
  49. package/dist/transport/index.cjs.map +1 -1
  50. package/dist/transport/index.d.cts +2 -2
  51. package/dist/transport/index.d.ts +2 -2
  52. package/dist/transport/index.js +3 -3
  53. package/dist/{transport-cbe70659.d.ts → transport-3d34f714.d.ts} +11 -6
  54. package/dist/util/testHelpers.cjs +27 -18
  55. package/dist/util/testHelpers.cjs.map +1 -1
  56. package/dist/util/testHelpers.d.cts +5 -4
  57. package/dist/util/testHelpers.d.ts +5 -4
  58. package/dist/util/testHelpers.js +5 -4
  59. package/dist/util/testHelpers.js.map +1 -1
  60. package/package.json +5 -3
  61. package/dist/chunk-7E53HHNS.js.map +0 -1
  62. package/dist/chunk-GX2YS7BY.js.map +0 -1
  63. package/dist/chunk-NB3OHLXB.js.map +0 -1
  64. /package/dist/{chunk-ZFN6I2GJ.js.map → chunk-2KC75LS4.js.map} +0 -0
  65. /package/dist/{chunk-NJJYBNYM.js.map → chunk-RLVU5DRX.js.map} +0 -0
@@ -103,7 +103,57 @@ function isAck(controlFlag) {
103
103
  }
104
104
 
105
105
  // logging/log.ts
106
- var log = void 0;
106
+ var LoggingLevels = {
107
+ debug: -1,
108
+ info: 0,
109
+ warn: 1,
110
+ error: 2
111
+ };
112
+ var cleanedLogFn = (log) => {
113
+ return (msg, metadata) => {
114
+ if (!metadata?.transportMessage) {
115
+ log(msg, metadata);
116
+ return;
117
+ }
118
+ const { payload, ...rest } = metadata.transportMessage;
119
+ metadata.transportMessage = rest;
120
+ log(msg, metadata);
121
+ };
122
+ };
123
+ var BaseLogger = class {
124
+ minLevel;
125
+ output;
126
+ constructor(output, minLevel = "info") {
127
+ this.minLevel = minLevel;
128
+ this.output = output;
129
+ }
130
+ debug(msg, metadata) {
131
+ if (LoggingLevels[this.minLevel] <= LoggingLevels.debug) {
132
+ this.output(msg, metadata ?? {}, "debug");
133
+ }
134
+ }
135
+ info(msg, metadata) {
136
+ if (LoggingLevels[this.minLevel] <= LoggingLevels.info) {
137
+ this.output(msg, metadata ?? {}, "info");
138
+ }
139
+ }
140
+ warn(msg, metadata) {
141
+ if (LoggingLevels[this.minLevel] <= LoggingLevels.warn) {
142
+ this.output(msg, metadata ?? {}, "warn");
143
+ }
144
+ }
145
+ error(msg, metadata) {
146
+ if (LoggingLevels[this.minLevel] <= LoggingLevels.error) {
147
+ this.output(msg, metadata ?? {}, "error");
148
+ }
149
+ }
150
+ };
151
+ var createLogProxy = (log) => ({
152
+ debug: cleanedLogFn(log.debug.bind(log)),
153
+ info: cleanedLogFn(log.info.bind(log)),
154
+ warn: cleanedLogFn(log.warn.bind(log)),
155
+ error: cleanedLogFn(log.error.bind(log))
156
+ });
107
157
 
108
158
  // transport/events.ts
109
159
  var ProtocolError = {
@@ -146,11 +196,11 @@ var import_nanoid2 = require("nanoid");
146
196
  var import_api = require("@opentelemetry/api");
147
197
 
148
198
  // package.json
149
- var version = "0.23.6";
199
+ var version = "0.23.7";
150
200
 
151
201
  // tracing/index.ts
152
202
  function createSessionTelemetryInfo(session, propagationCtx) {
153
- const ctx = propagationCtx ? import_api.propagation.extract(import_api.context.active(), propagationCtx) : import_api.context.active();
203
+ const parentCtx = propagationCtx ? import_api.propagation.extract(import_api.context.active(), propagationCtx) : import_api.context.active();
154
204
  const span = tracer.startSpan(
155
205
  `session ${session.id}`,
156
206
  {
@@ -161,12 +211,12 @@ function createSessionTelemetryInfo(session, propagationCtx) {
161
211
  "river.session.from": session.from
162
212
  }
163
213
  },
164
- ctx
214
+ parentCtx
165
215
  );
216
+ const ctx = import_api.trace.setSpan(parentCtx, span);
166
217
  return { span, ctx };
167
218
  }
168
- function createConnectionTelemetryInfo(connection, sessionSpan) {
169
- const ctx = import_api.trace.setSpan(import_api.context.active(), sessionSpan);
219
+ function createConnectionTelemetryInfo(connection, info) {
170
220
  const span = tracer.startSpan(
171
221
  `connection ${connection.id}`,
172
222
  {
@@ -174,10 +224,11 @@ function createConnectionTelemetryInfo(connection, sessionSpan) {
174
224
  component: "river",
175
225
  "river.connection.id": connection.id
176
226
  },
177
- links: [{ context: sessionSpan.spanContext() }]
227
+ links: [{ context: info.span.spanContext() }]
178
228
  },
179
- ctx
229
+ info.ctx
180
230
  );
231
+ const ctx = import_api.trace.setSpan(info.ctx, span);
181
232
  return { span, ctx };
182
233
  }
183
234
  var tracer = import_api.trace.getTracer("river", version);
@@ -192,6 +243,17 @@ var Connection = class {
192
243
  constructor() {
193
244
  this.id = `conn-${nanoid2(12)}`;
194
245
  }
246
+ get loggingMetadata() {
247
+ const metadata = { connId: this.id };
248
+ const spanContext = this.telemetry?.span.spanContext();
249
+ if (spanContext) {
250
+ metadata.telemetry = {
251
+ traceId: spanContext.traceId,
252
+ spanId: spanContext.spanId
253
+ };
254
+ }
255
+ return metadata;
256
+ }
195
257
  };
196
258
  var Session = class {
197
259
  codec;
@@ -237,6 +299,7 @@ var Session = class {
237
299
  * The interval for sending heartbeats.
238
300
  */
239
301
  heartbeat;
302
+ log;
240
303
  constructor(conn, from, to, options, propagationCtx) {
241
304
  this.id = `session-${nanoid2(12)}`;
242
305
  this.options = options;
@@ -251,12 +314,20 @@ var Session = class {
251
314
  );
252
315
  this.telemetry = createSessionTelemetryInfo(this, propagationCtx);
253
316
  }
317
+ bindLogger(log) {
318
+ this.log = log;
319
+ }
254
320
  get loggingMetadata() {
321
+ const spanContext = this.telemetry.span.spanContext();
255
322
  return {
256
323
  clientId: this.from,
257
324
  connectedTo: this.to,
258
325
  sessionId: this.id,
259
- connId: this.connection?.id
326
+ connId: this.connection?.id,
327
+ telemetry: {
328
+ traceId: spanContext.traceId,
329
+ spanId: spanContext.spanId
330
+ }
260
331
  };
261
332
  }
262
333
  /**
@@ -269,7 +340,7 @@ var Session = class {
269
340
  */
270
341
  send(msg) {
271
342
  const fullMsg = this.constructMsg(msg);
272
- log?.debug(`sending msg`, {
343
+ this.log?.debug(`sending msg`, {
273
344
  ...this.loggingMetadata,
274
345
  transportMessage: fullMsg
275
346
  });
@@ -277,7 +348,7 @@ var Session = class {
277
348
  const ok = this.connection.send(this.codec.toBuffer(fullMsg));
278
349
  if (ok)
279
350
  return fullMsg.id;
280
- log?.info(
351
+ this.log?.info(
281
352
  `failed to send msg to ${fullMsg.to}, connection is probably dead`,
282
353
  {
283
354
  ...this.loggingMetadata,
@@ -285,8 +356,8 @@ var Session = class {
285
356
  }
286
357
  );
287
358
  } else {
288
- log?.info(
289
- `failed to send msg to ${fullMsg.to}, connection not ready yet`,
359
+ this.log?.debug(
360
+ `buffering msg to ${fullMsg.to}, connection not ready yet`,
290
361
  { ...this.loggingMetadata, transportMessage: fullMsg }
291
362
  );
292
363
  }
@@ -297,7 +368,7 @@ var Session = class {
297
368
  const missDuration = misses * this.options.heartbeatIntervalMs;
298
369
  if (misses > this.options.heartbeatsUntilDead) {
299
370
  if (this.connection) {
300
- log?.info(
371
+ this.log?.info(
301
372
  `closing connection to ${this.to} due to inactivity (missed ${misses} heartbeats which is ${missDuration}ms)`,
302
373
  this.loggingMetadata
303
374
  );
@@ -321,12 +392,12 @@ var Session = class {
321
392
  this.ack = 0;
322
393
  }
323
394
  sendBufferedMessages(conn) {
324
- log?.info(`resending ${this.sendBuffer.length} buffered messages`, {
395
+ this.log?.info(`resending ${this.sendBuffer.length} buffered messages`, {
325
396
  ...this.loggingMetadata,
326
397
  connId: conn.id
327
398
  });
328
399
  for (const msg of this.sendBuffer) {
329
- log?.debug(`resending msg`, {
400
+ this.log?.debug(`resending msg`, {
330
401
  ...this.loggingMetadata,
331
402
  transportMessage: msg,
332
403
  connId: conn.id
@@ -338,7 +409,7 @@ var Session = class {
338
409
  code: import_api2.SpanStatusCode.ERROR,
339
410
  message: errMsg
340
411
  });
341
- log?.error(errMsg, {
412
+ this.log?.error(errMsg, {
342
413
  ...this.loggingMetadata,
343
414
  transportMessage: msg,
344
415
  connId: conn.id,
@@ -351,7 +422,7 @@ var Session = class {
351
422
  }
352
423
  updateBookkeeping(ack, seq) {
353
424
  if (seq + 1 < this.ack) {
354
- log?.error(`received stale seq ${seq} + 1 < ${this.ack}`, {
425
+ this.log?.error(`received stale seq ${seq} + 1 < ${this.ack}`, {
355
426
  ...this.loggingMetadata,
356
427
  tags: ["invariant-violation"]
357
428
  });
@@ -363,7 +434,7 @@ var Session = class {
363
434
  closeStaleConnection(conn) {
364
435
  if (this.connection === void 0 || this.connection === conn)
365
436
  return;
366
- log?.info(
437
+ this.log?.info(
367
438
  `closing old inner connection from session to ${this.to}`,
368
439
  this.loggingMetadata
369
440
  );
@@ -377,7 +448,7 @@ var Session = class {
377
448
  this.connection = newConn;
378
449
  }
379
450
  beginGrace(cb) {
380
- log?.info(
451
+ this.log?.info(
381
452
  `starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
382
453
  this.loggingMetadata
383
454
  );
@@ -540,6 +611,7 @@ var Transport = class {
540
611
  * The options for this transport.
541
612
  */
542
613
  options;
614
+ log;
543
615
  /**
544
616
  * Creates a new Transport instance.
545
617
  * This should also set up {@link onConnect}, and {@link onDisconnect} listeners.
@@ -554,6 +626,13 @@ var Transport = class {
554
626
  this.clientId = clientId;
555
627
  this.state = "open";
556
628
  }
629
+ bindLogger(fn, level) {
630
+ if (typeof fn === "function") {
631
+ this.log = createLogProxy(new BaseLogger(fn, level));
632
+ return;
633
+ }
634
+ this.log = createLogProxy(fn);
635
+ }
557
636
  /**
558
637
  * Called when a new connection is established
559
638
  * and we know the identity of the connected client.
@@ -564,13 +643,15 @@ var Transport = class {
564
643
  status: "connect",
565
644
  conn
566
645
  });
567
- conn.telemetry = createConnectionTelemetryInfo(
568
- conn,
569
- session.telemetry.span
570
- );
646
+ conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
571
647
  if (isReconnect) {
572
648
  session.replaceWithNewConnection(conn);
573
- log?.info(`reconnected to ${connectedTo}`, session.loggingMetadata);
649
+ this.log?.info(`reconnected to ${connectedTo}`, {
650
+ ...conn.loggingMetadata,
651
+ ...session.loggingMetadata,
652
+ clientId: this.clientId,
653
+ connectedTo
654
+ });
574
655
  }
575
656
  }
576
657
  createSession(to, conn, propagationCtx) {
@@ -581,6 +662,9 @@ var Transport = class {
581
662
  this.options,
582
663
  propagationCtx
583
664
  );
665
+ if (this.log) {
666
+ session.bindLogger(this.log);
667
+ }
584
668
  this.sessions.set(session.to, session);
585
669
  this.eventDispatcher.dispatchEvent("sessionStatus", {
586
670
  status: "connect",
@@ -592,7 +676,7 @@ var Transport = class {
592
676
  let session = this.sessions.get(to);
593
677
  let isReconnect = session !== void 0;
594
678
  if (session?.advertisedSessionId !== void 0 && sessionId !== void 0 && session.advertisedSessionId !== sessionId) {
595
- log?.info(
679
+ this.log?.info(
596
680
  `session for ${to} already exists but has a different session id (expected: ${session.advertisedSessionId}, got: ${sessionId}), creating a new one`,
597
681
  session.loggingMetadata
598
682
  );
@@ -602,7 +686,7 @@ var Transport = class {
602
686
  }
603
687
  if (!session) {
604
688
  session = this.createSession(to, conn, propagationCtx);
605
- log?.info(
689
+ this.log?.info(
606
690
  `no session for ${to}, created a new one`,
607
691
  session.loggingMetadata
608
692
  );
@@ -616,7 +700,7 @@ var Transport = class {
616
700
  session.close();
617
701
  session.telemetry.span.end();
618
702
  this.sessions.delete(session.to);
619
- log?.info(
703
+ this.log?.info(
620
704
  `session ${session.id} disconnect from ${session.to}`,
621
705
  session.loggingMetadata
622
706
  );
@@ -647,18 +731,23 @@ var Transport = class {
647
731
  * @param msg The message to parse.
648
732
  * @returns The parsed message, or null if the message is malformed or invalid.
649
733
  */
650
- parseMsg(msg) {
734
+ parseMsg(msg, conn) {
651
735
  const parsedMsg = this.codec.fromBuffer(msg);
652
736
  if (parsedMsg === null) {
653
737
  const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
654
- log?.error(`received malformed msg, killing conn: ${decodedBuffer}`, {
655
- clientId: this.clientId
656
- });
738
+ this.log?.error(
739
+ `received malformed msg, killing conn: ${decodedBuffer}`,
740
+ {
741
+ clientId: this.clientId,
742
+ ...conn.loggingMetadata
743
+ }
744
+ );
657
745
  return null;
658
746
  }
659
747
  if (!import_value.Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
660
- log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
748
+ this.log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
661
749
  clientId: this.clientId,
750
+ ...conn.loggingMetadata,
662
751
  validationErrors: [
663
752
  ...import_value.Value.Errors(OpaqueTransportMessageSchema, parsedMsg)
664
753
  ]
@@ -672,34 +761,41 @@ var Transport = class {
672
761
  * You generally shouldn't need to override this in downstream transport implementations.
673
762
  * @param msg The received message.
674
763
  */
675
- handleMsg(msg) {
764
+ handleMsg(msg, conn) {
676
765
  if (this.state !== "open")
677
766
  return;
678
767
  const session = this.sessions.get(msg.from);
679
768
  if (!session) {
680
- log?.error(`no existing session for ${msg.from}`, {
769
+ this.log?.error(`received message for unknown session from ${msg.from}`, {
681
770
  clientId: this.clientId,
682
771
  transportMessage: msg,
772
+ ...conn.loggingMetadata,
683
773
  tags: ["invariant-violation"]
684
774
  });
685
775
  return;
686
776
  }
687
777
  session.cancelGrace();
688
- log?.debug(`received msg`, {
778
+ this.log?.debug(`received msg`, {
689
779
  clientId: this.clientId,
690
- transportMessage: msg
780
+ transportMessage: msg,
781
+ ...conn.loggingMetadata
691
782
  });
692
783
  if (msg.seq !== session.nextExpectedSeq) {
693
784
  if (msg.seq < session.nextExpectedSeq) {
694
- log?.debug(
785
+ this.log?.debug(
695
786
  `received duplicate msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq}), discarding`,
696
- { clientId: this.clientId, transportMessage: msg }
787
+ {
788
+ clientId: this.clientId,
789
+ transportMessage: msg,
790
+ ...conn.loggingMetadata
791
+ }
697
792
  );
698
793
  } else {
699
794
  const errMsg = `received out-of-order msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq})`;
700
- log?.error(`${errMsg}, marking connection as dead`, {
795
+ this.log?.error(`${errMsg}, marking connection as dead`, {
701
796
  clientId: this.clientId,
702
797
  transportMessage: msg,
798
+ ...conn.loggingMetadata,
703
799
  tags: ["invariant-violation"]
704
800
  });
705
801
  this.protocolError(ProtocolError.MessageOrderingViolated, errMsg);
@@ -715,9 +811,10 @@ var Transport = class {
715
811
  if (!isAck(msg.controlFlags)) {
716
812
  this.eventDispatcher.dispatchEvent("message", msg);
717
813
  } else {
718
- log?.debug(`discarding msg (ack bit set)`, {
814
+ this.log?.debug(`discarding msg (ack bit set)`, {
719
815
  clientId: this.clientId,
720
- transportMessage: msg
816
+ transportMessage: msg,
817
+ ...conn.loggingMetadata
721
818
  });
722
819
  }
723
820
  }
@@ -746,7 +843,7 @@ var Transport = class {
746
843
  send(to, msg) {
747
844
  if (this.state === "destroyed") {
748
845
  const err = "transport is destroyed, cant send";
749
- log?.error(err, {
846
+ this.log?.error(err, {
750
847
  clientId: this.clientId,
751
848
  transportMessage: msg,
752
849
  tags: ["invariant-violation"]
@@ -754,7 +851,7 @@ var Transport = class {
754
851
  this.protocolError(ProtocolError.UseAfterDestroy, err);
755
852
  return void 0;
756
853
  } else if (this.state === "closed") {
757
- log?.info(`transport closed when sending, discarding`, {
854
+ this.log?.info(`transport closed when sending, discarding`, {
758
855
  clientId: this.clientId,
759
856
  transportMessage: msg
760
857
  });
@@ -785,7 +882,7 @@ var Transport = class {
785
882
  for (const session of this.sessions.values()) {
786
883
  this.deleteSession(session);
787
884
  }
788
- log?.info(`manually closed transport`, { clientId: this.clientId });
885
+ this.log?.info(`manually closed transport`, { clientId: this.clientId });
789
886
  }
790
887
  /**
791
888
  * Default destroy implementation for transports. You should override this in the downstream
@@ -797,7 +894,7 @@ var Transport = class {
797
894
  for (const session of this.sessions.values()) {
798
895
  this.deleteSession(session);
799
896
  }
800
- log?.info(`manually destroyed transport`, { clientId: this.clientId });
897
+ this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
801
898
  }
802
899
  };
803
900
  var ServerTransport = class extends Transport {
@@ -820,7 +917,7 @@ var ServerTransport = class extends Transport {
820
917
  ...providedOptions
821
918
  };
822
919
  this.sessionHandshakeMetadata = /* @__PURE__ */ new WeakMap();
823
- log?.info(`initiated server transport`, {
920
+ this.log?.info(`initiated server transport`, {
824
921
  clientId: this.clientId,
825
922
  protocolVersion: PROTOCOL_VERSION
826
923
  });
@@ -831,20 +928,20 @@ var ServerTransport = class extends Transport {
831
928
  handleConnection(conn) {
832
929
  if (this.state !== "open")
833
930
  return;
834
- log?.info(`new incoming connection`, {
835
- clientId: this.clientId,
836
- connId: conn.id
931
+ this.log?.info(`new incoming connection`, {
932
+ ...conn.loggingMetadata,
933
+ clientId: this.clientId
837
934
  });
838
935
  let session = void 0;
839
936
  const client = () => session?.to ?? "unknown";
840
937
  const handshakeTimeout = setTimeout(() => {
841
938
  if (!session) {
842
- log?.warn(
939
+ this.log?.warn(
843
940
  `connection to ${client()} timed out waiting for handshake, closing`,
844
941
  {
942
+ ...conn.loggingMetadata,
845
943
  clientId: this.clientId,
846
- connectedTo: client(),
847
- connId: conn.id
944
+ connectedTo: client()
848
945
  }
849
946
  );
850
947
  conn.telemetry?.span.setStatus({
@@ -871,12 +968,12 @@ var ServerTransport = class extends Transport {
871
968
  }
872
969
  session = maybeSession;
873
970
  const dataHandler = (data2) => {
874
- const parsed = this.parseMsg(data2);
971
+ const parsed = this.parseMsg(data2, conn);
875
972
  if (!parsed) {
876
973
  conn.close();
877
974
  return;
878
975
  }
879
- this.handleMsg(parsed);
976
+ this.handleMsg(parsed, conn);
880
977
  };
881
978
  for (const data2 of buffer) {
882
979
  dataHandler(data2);
@@ -891,9 +988,9 @@ var ServerTransport = class extends Transport {
891
988
  conn.addCloseListener(() => {
892
989
  if (!session)
893
990
  return;
894
- log?.info(`connection to ${client()} disconnected`, {
895
- clientId: this.clientId,
896
- connId: conn.id
991
+ this.log?.info(`connection to ${client()} disconnected`, {
992
+ ...conn.loggingMetadata,
993
+ clientId: this.clientId
897
994
  });
898
995
  this.onDisconnect(conn, session);
899
996
  });
@@ -904,9 +1001,9 @@ var ServerTransport = class extends Transport {
904
1001
  });
905
1002
  if (!session)
906
1003
  return;
907
- log?.warn(
1004
+ this.log?.warn(
908
1005
  `connection to ${client()} got an error: ${coerceErrorString(err)}`,
909
- { clientId: this.clientId, connId: conn.id }
1006
+ { ...conn.loggingMetadata, clientId: this.clientId }
910
1007
  );
911
1008
  });
912
1009
  }
@@ -924,9 +1021,9 @@ var ServerTransport = class extends Transport {
924
1021
  reason
925
1022
  });
926
1023
  conn.send(this.codec.toBuffer(responseMsg));
927
- log?.warn(`received malformed handshake metadata from ${from}`, {
1024
+ this.log?.warn(`received malformed handshake metadata from ${from}`, {
1025
+ ...conn.loggingMetadata,
928
1026
  clientId: this.clientId,
929
- connId: conn.id,
930
1027
  validationErrors: [
931
1028
  ...import_value.Value.Errors(this.handshakeExtensions.schema, rawMetadata)
932
1029
  ]
@@ -950,9 +1047,9 @@ var ServerTransport = class extends Transport {
950
1047
  reason
951
1048
  });
952
1049
  conn.send(this.codec.toBuffer(responseMsg));
953
- log?.warn(`rejected handshake from ${from}`, {
954
- clientId: this.clientId,
955
- connId: conn.id
1050
+ this.log?.warn(`rejected handshake from ${from}`, {
1051
+ ...conn.loggingMetadata,
1052
+ clientId: this.clientId
956
1053
  });
957
1054
  this.protocolError(ProtocolError.HandshakeFailed, reason);
958
1055
  return false;
@@ -961,7 +1058,7 @@ var ServerTransport = class extends Transport {
961
1058
  return parsedMetadata;
962
1059
  }
963
1060
  async receiveHandshakeRequestMessage(data, conn) {
964
- const parsed = this.parseMsg(data);
1061
+ const parsed = this.parseMsg(data, conn);
965
1062
  if (!parsed) {
966
1063
  conn.telemetry?.span.setStatus({
967
1064
  code: import_api3.SpanStatusCode.ERROR,
@@ -984,10 +1081,10 @@ var ServerTransport = class extends Transport {
984
1081
  reason
985
1082
  });
986
1083
  conn.send(this.codec.toBuffer(responseMsg2));
987
- log?.warn(reason, {
1084
+ this.log?.warn(reason, {
1085
+ ...conn.loggingMetadata,
988
1086
  clientId: this.clientId,
989
- connId: conn.id,
990
- // safe to log metadata here as we remove the payload
1087
+ // safe to this.log metadata here as we remove the payload
991
1088
  // before passing it to user-land
992
1089
  transportMessage: parsed,
993
1090
  validationErrors: [
@@ -1012,9 +1109,9 @@ var ServerTransport = class extends Transport {
1012
1109
  reason
1013
1110
  });
1014
1111
  conn.send(this.codec.toBuffer(responseMsg2));
1015
- log?.warn(
1112
+ this.log?.warn(
1016
1113
  `received handshake msg with incompatible protocol version (got: ${gotVersion}, expected: ${PROTOCOL_VERSION})`,
1017
- { clientId: this.clientId, connId: conn.id }
1114
+ { ...conn.loggingMetadata, clientId: this.clientId }
1018
1115
  );
1019
1116
  this.protocolError(ProtocolError.HandshakeFailed, reason);
1020
1117
  return false;
@@ -1036,9 +1133,9 @@ var ServerTransport = class extends Transport {
1036
1133
  parsed.tracing
1037
1134
  );
1038
1135
  this.sessionHandshakeMetadata.set(session, parsedMetadata);
1039
- log?.debug(
1136
+ this.log?.debug(
1040
1137
  `handshake from ${parsed.from} ok, responding with handshake success`,
1041
- { clientId: this.clientId, connId: conn.id }
1138
+ conn.loggingMetadata
1042
1139
  );
1043
1140
  const responseMsg = handshakeResponseMessage(this.clientId, parsed.from, {
1044
1141
  ok: true,