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

Add Connected/Sent/Received Log::Timeline probes #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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: 3 additions & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"Digest::SHA1::Native",
"Crypt::Random",
"JSON::Fast",
"OO::Monitors"
"OO::Monitors",
"Log::Timeline"
],
"provides": {
"Cro::HTTP::Router::WebSocket": "lib/Cro/HTTP/Router/WebSocket.pm6",
Expand All @@ -25,6 +26,7 @@
"Cro::WebSocket::FrameSerializer": "lib/Cro/WebSocket/FrameSerializer.pm6",
"Cro::WebSocket::Handler": "lib/Cro/WebSocket/Handler.pm6",
"Cro::WebSocket::Internal": "lib/Cro/WebSocket/Internal.pm6",
"Cro::WebSocket::LogTimelineSchema": "lib/Cro/WebSocket/LogTimelineSchema.pm6",
"Cro::WebSocket::Message": "lib/Cro/WebSocket/Message.pm6",
"Cro::WebSocket::Message::Opcode": "lib/Cro/WebSocket/Message/Opcode.pm6",
"Cro::WebSocket::MessageParser": "lib/Cro/WebSocket/MessageParser.pm6",
Expand Down
2 changes: 2 additions & 0 deletions lib/Cro/WebSocket/Client.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Cro::WebSocket::BodySerializers;
use Cro::WebSocket::Client::Connection;
use Crypt::Random;
use Digest::SHA1::Native;
use Cro::WebSocket::LogTimelineSchema;

class X::Cro::WebSocket::Client::CannotUpgrade is Exception {
has $.reason;
Expand Down Expand Up @@ -102,6 +103,7 @@ class Cro::WebSocket::Client {
# No extensions for now
# die unless $resp.header('Sec-WebSocket-Extensions') eq Nil;
# die unless $resp.header('Sec-WebSocket-Protocol') eq 'echo-protocol'; # XXX
Cro::WebSocket::LogTimelineSchema::Connected.log();
Cro::WebSocket::Client::Connection.new(
in => $resp.body-byte-stream, :$out,
|(%(:$!body-parsers, :$!body-serializers) with self)
Expand Down
5 changes: 4 additions & 1 deletion lib/Cro/WebSocket/Client/Connection.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use Cro::WebSocket::Internal;
use Cro::WebSocket::Message;
use Cro::WebSocket::MessageParser;
use Cro::WebSocket::MessageSerializer;
use Cro::WebSocket::LogTimelineSchema;
use OO::Monitors;

class X::Cro::WebSocket::Client::Closed is Exception {
Expand Down Expand Up @@ -123,7 +124,9 @@ class Cro::WebSocket::Client::Connection {
multi method send(Cro::WebSocket::Message $m --> Nil) {
self!ensure-open('send');
my $serialized = $m.serialization-outcome //= Promise.new;
$!sender.emit($m);
Cro::WebSocket::LogTimelineSchema::Sent.log: -> {
$!sender.emit($m);
}
await $serialized;
}
multi method send($m) {
Expand Down
1 change: 0 additions & 1 deletion lib/Cro/WebSocket/FrameSerializer.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Cro::WebSocket::FrameSerializer does Cro::Transform {

# Mask flag and payload length
my $payload-len = $frame.payload.elems;
my $pos;
if $payload-len < 126 {
$message[1] = ($!mask ?? 128 !! 0) + $payload-len;
}
Expand Down
9 changes: 7 additions & 2 deletions lib/Cro/WebSocket/Handler.pm6
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use Cro::Transform;
use Cro::WebSocket::Message;
use Cro::WebSocket::LogTimelineSchema;

class Cro::WebSocket::Handler does Cro::Transform {
has &.block;
Expand Down Expand Up @@ -65,15 +66,19 @@ class Cro::WebSocket::Handler does Cro::Transform {

whenever $block-result {
when Cro::WebSocket::Message {
emit $_;
Cro::WebSocket::LogTimelineSchema::Sent.log: -> {
emit $_
}
if .opcode == Cro::WebSocket::Message::Close {
$supplier.emit(CloseMessage);
$end = True;
done;
}
}
default {
emit Cro::WebSocket::Message.new($_)
Cro::WebSocket::LogTimelineSchema::Sent.log: -> {
emit Cro::WebSocket::Message.new($_)
}
}

LAST {
Expand Down
10 changes: 10 additions & 0 deletions lib/Cro/WebSocket/LogTimelineSchema.pm6
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
unit module Cro::WebSocket::LogTimelineSchema;

use Log::Timeline;

class Connected does Log::Timeline::Event['Cro::WebSocket', 'Client', 'Connected'] is export { }

class Sent does Log::Timeline::Task['Cro::WebSocket', 'Message', 'Sent'] is export { }

class Received does Log::Timeline::Task['Cro::WebSocket', 'Message', 'Received'] is export { }