Skip to content
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
44 changes: 44 additions & 0 deletions profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import modal
import time
import logging

image = (
modal.Image.debian_slim(python_version="3.11")
.apt_install("git")
.pip_install("middleware-io", "middleware-io[profiling]")
.run_commands(
"middleware-bootstrap -a install",
# This creates the CORRECT wrapper script inside the container
"echo '#!/bin/sh' > /root/run.sh",
"echo 'exec middleware-run \"$@\"' >> /root/run.sh",
"chmod +x /root/run.sh",
)
.dockerfile_commands('ENTRYPOINT ["/root/run.sh"]')
)

app = modal.App(
"hello-world-app",
image=image
)

@app.function(
secrets=[
modal.Secret.from_name("middleware"),
modal.Secret.from_dict({
"MW_TRACKER": "True",
"MW_APM_COLLECT_PROFILING": "True",
"MW_SERVICE_NAME": "MyModalApp-Fixed",
})
]
)
def hello():
logging.info("Function started. Middleware is now correctly wrapping the Modal worker.")
time.sleep(1)
logging.info("Processing complete.")
return {"status": "success", "message": "hello world from a non-crashing container"}

@app.local_entrypoint()
def main():
result = hello.remote()
print(f"Result from remote function: {result}")

2 changes: 2 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec middleware-run "$@"
23 changes: 23 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import modal

def main():
try:
# 1. Look up the deployed function by its app name and function name.
# The app name is "hello-world-app" from your profiler.py.
# The function name is "hello".
f = modal.Function.lookup("hello-world-app", "hello")
print("Successfully found the deployed function 'hello'.")

# 2. Trigger the function using .remote()
print("Calling the function on Modal's servers...")
result = f.remote()

# 3. Print the result
print(f"Result from deployed function: {result}")

except modal.exception.NotFoundError:
print("Error: Could not find the deployed app 'hello-world-app'.")
print("Please make sure you have successfully run 'modal deploy profiler.py'.")

if __name__ == "__main__":
main()