Skip to content

Commit

Permalink
properly end connection span (#277)
Browse files Browse the repository at this point in the history
## Why

we weren't ending the connection span before!

## What changed

end the connection span when the connection ends

## Versioning

- [ ] Breaking protocol change
- [ ] Breaking ts/js API change

<!-- Kind reminder to add tests and updated documentation if needed -->
  • Loading branch information
jackyzha0 authored Oct 22, 2024
1 parent b32d9f7 commit 9b4912d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@replit/river",
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
"version": "0.203.1",
"version": "0.203.2",
"type": "module",
"exports": {
".": {
Expand Down
20 changes: 20 additions & 0 deletions transport/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ export abstract class Connection {
return [...this._errorListeners];
}

onData(msg: Uint8Array) {
for (const cb of this.dataListeners) {
cb(msg);
}
}

onError(err: Error) {
for (const cb of this.errorListeners) {
cb(err);
}
}

onClose() {
for (const cb of this.closeListeners) {
cb();
}

this.telemetry?.span.end();
}

/**
* Handle adding a callback for when a message is received.
* @param msg The message that was received.
Expand Down
12 changes: 3 additions & 9 deletions transport/impls/ws/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,14 @@ export class WebSocketConnection extends Connection {
`websocket closed with code and reason: ${code} - ${reason}`,
);

for (const cb of this.errorListeners) {
cb(err);
}
this.onError(err);
}

for (const cb of this.closeListeners) {
cb();
}
this.onClose();
};

this.ws.onmessage = (msg) => {
for (const cb of this.dataListeners) {
cb(msg.data as Uint8Array);
}
this.onData(msg.data as Uint8Array);
};
}

Expand Down

0 comments on commit 9b4912d

Please sign in to comment.