Skip to content
Draft
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
7 changes: 7 additions & 0 deletions examples/wasm_guest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.venv/
dist/
src/wit_world/
src/componentize_py_*/
src/poll_loop.py
src/componentize_py_types.py
src/componentize_py_runtime.pyi
19 changes: 19 additions & 0 deletions examples/wasm_guest/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
WIT_DIR := wit
SRC_DIR := src
DIST_DIR := dist
WASM := $(DIST_DIR)/plugin.wasm

.PHONY: bindings build clean

bindings:
uv run componentize-py -d $(WIT_DIR) -w plugin bindings $(SRC_DIR)

$(WASM): $(SRC_DIR)/guest_impl.py $(WIT_DIR)/processor.wit
@mkdir -p $(DIST_DIR)
$(MAKE) bindings
uv run componentize-py -d $(WIT_DIR) -w plugin componentize -p $(SRC_DIR) guest_impl -o $(WASM)

build: $(WASM)

clean:
rm -rf $(DIST_DIR) $(SRC_DIR)/wit_world $(SRC_DIR)/componentize_py_*
21 changes: 21 additions & 0 deletions examples/wasm_guest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# sentry_streams WASM guest example

Sample [componentize-py](https://github.com/bytecodealliance/componentize-py) guest for the
`sentry-streams:processor` WIT world used by `WasmProcessor` in the Rust Arroyo adapter.

## Build

```bash
make build
```

Produces `dist/plugin.wasm`. The WIT contract lives in
[`../../sentry_streams/wit/processor.wit`](../../sentry_streams/wit/processor.wit).

## Guest behavior

- `submit`: buffers the message for the next `poll`
- `submit_watermark`: buffers the watermark for the next `poll`
- `poll`: returns all buffered outputs (messages and watermarks), or `None` if empty

Uses the host `log` import for tracing.
11 changes: 11 additions & 0 deletions examples/wasm_guest/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
name = "sentry-streams-wasm-guest"
version = "0.1.0"
description = "Example componentize-py guest for sentry_streams WasmProcessor"
requires-python = ">=3.11"
dependencies = [
"componentize-py>=0.23.0",
]

[tool.uv]
dev-dependencies = []
31 changes: 31 additions & 0 deletions examples/wasm_guest/src/guest_impl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Sample WASM processor guest: passthrough with host logging."""

from __future__ import annotations

from typing import List, Optional

from wit_world.exports import Processor as ProcessorProtocol
from wit_world.exports import processor as proc
from wit_world.imports import log as host_log


class Processor(ProcessorProtocol):
"""Buffers submitted messages and watermarks; returns them on ``poll``."""

def __init__(self) -> None:
self._pending: List[proc.Output] = []

def submit(self, msg: proc.Message) -> None:
host_log.info(f"submit message len={len(msg.payload)}")
self._pending.append(proc.Output_Msg(value=msg))

def submit_watermark(self, wm: proc.Watermark) -> None:
host_log.info("submit_watermark")
self._pending.append(proc.Output_Wm(value=wm))

def poll(self) -> Optional[List[proc.Output]]:
if not self._pending:
return None
out = self._pending
self._pending = []
return out
30 changes: 30 additions & 0 deletions examples/wasm_guest/uv.lock

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

1 change: 1 addition & 0 deletions examples/wasm_guest/wit/processor.wit
Loading
Loading