Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properly end connection span #277

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading