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

Unclear how to use tracing within applications #323

Open
ArtemPt239 opened this issue Oct 23, 2023 · 2 comments
Open

Unclear how to use tracing within applications #323

ArtemPt239 opened this issue Oct 23, 2023 · 2 comments

Comments

@ArtemPt239
Copy link

ArtemPt239 commented Oct 23, 2023

I tried running an example recipe with python hello.py - and it works perfectly.

However, I can not find any instructions on how to use tracing functionality not as a standalone demonstration, but inside other applications.

A simplest example would be:

hello.py:

from ice.recipe import recipe

async def say_hello():
    return "Hello world!"

recipe.main(say_hello)

test.py:

from hello import say_hello
import asyncio

if __name__ == '__main__':
    print(asyncio.run(say_hello()))

Which does not work when run with python test.py - no traces being recorded.

Could anyone please point me towards a way to achieve this?

@ArtemPt239
Copy link
Author

For anyone stumbling into this issue later:

After digging into the code of ICE I came up with this SOLUTION:

hello.py:

from ice.trace import trace

@trace
async def say_hello():
    return "Hello world!"

test.py:

from hello import say_hello
import asyncio
from ice.trace import trace, enable_trace

if __name__ == '__main__':
    enable_trace()
    @trace
    async def main_wrapper():
        # A traced function cannot be called until the event loop is running.
        return await say_hello()

    print(asyncio.run(main_wrapper()))

This code performs tracing when started with python test.py

@ArtemPt239
Copy link
Author

Despite the solution being found - it may be benificial to mention this method of running tracing in the README.
Hence I am leaving the issue open.

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

No branches or pull requests

1 participant