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

Support tail workers over rpc #3707

Merged
merged 1 commit into from
Mar 12, 2025
Merged

Support tail workers over rpc #3707

merged 1 commit into from
Mar 12, 2025

Conversation

danlapid
Copy link
Collaborator

This allows tail workers over rpc, to test use the following files:
config.capnp:

using Workerd = import "/workerd/workerd.capnp";

const tailWorkerExample :Workerd.Config = (
  services = [
    (name = "main", worker = .helloWorld),
    (name = "log", external = ( address = "127.0.0.1:8081", http = ( capnpConnectHost = "capnp" ))),
  ],
  sockets = [ ( name = "http", address = "*:8080", http = (), service = "main" ) ],
);

const helloWorld :Workerd.Worker = (
  modules = [
    (name = "worker", esModule = embed "worker.js")
  ],
  compatibilityDate = "2024-10-14",
  tails = ["log"],
  bindings = [(name = "log", service = "log")]
);

log.capnp:

using Workerd = import "/workerd/workerd.capnp";

const tailWorkerExample :Workerd.Config = (
  services = [
    (name = "log", worker = .logWorker),
  ],
  sockets = [ ( name = "rpc", address = "*:8081", http = ( capnpConnectHost = "capnp" ), service = "log" ) ],
);

const logWorker :Workerd.Worker = (
  modules = [
    (name = "worker", esModule = embed "tail.js")
  ],
  compatibilityDate = "2024-10-14",
);

tail.js:

export default {
  tail(traces) {
    console.log(traces[0].logs);
  },
};

worker.js:

export default {
  async fetch(req, env) {
    console.log('log from worker a');
    return new Response('response from worker a');
  },
};

bash:

workerd serve deps/workerd/samples/tail-workers/log.capnp
workerd serve deps/workerd/samples/tail-workers/config.capnp
curl http://localhost:8080

@danlapid danlapid requested review from a team as code owners March 12, 2025 18:05
@danlapid
Copy link
Collaborator Author

Sadly we don't really have tests to set up two workerd instances and talk rpc between them.

Verified

This commit was signed with the committer’s verified signature.
dvandersluis Daniel Vandersluis
@danlapid danlapid force-pushed the dlapid/tail_over_rpc branch from 8f3b24d to 55cc144 Compare March 12, 2025 18:09
@irvinebroque
Copy link
Contributor

@rohinlohe should be able to see both sides this way, even if there's other work to do on wrangler side

@danlapid danlapid merged commit 2faf29d into main Mar 12, 2025
16 of 17 checks passed
@danlapid danlapid deleted the dlapid/tail_over_rpc branch March 12, 2025 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants