示例#1
0
def test_instrument_context_manager(tracked_request):
    with instrument("Test ContextMgr") as inst:
        inst.tag("foo", "bar")

    assert len(tracked_request.active_spans) == 0
    assert len(tracked_request.complete_spans) == 1
    assert tracked_request.complete_spans[0].operation == "Custom/Test ContextMgr"
示例#2
0
def test_instrument_context_manager_with_kind(tracked_request):
    with instrument("Get", kind="Redis") as inst:
        inst.tag("foo", "bar")

    assert len(tracked_request.active_spans) == 0
    assert len(tracked_request.complete_spans) == 1
    assert tracked_request.complete_spans[0].operation == "Redis/Get"
示例#3
0
def test_instrument_context_manager_default_tags(tracked_request):
    with instrument("tag test", tags={"x": 99}):
        pass

    assert len(tracked_request.active_spans) == 0
    assert len(tracked_request.complete_spans) == 1
    assert tracked_request.complete_spans[0].tags["x"] == 99
示例#4
0
def test_instrument_context_manager_default_tags():
    # Save TR here, so it doesn't disappear on us when span finishes
    tr = TrackedRequest.instance()

    with instrument("tag test", tags={"x": 99}):
        pass

    span = tr.complete_spans[-1]
    assert span.tags["x"] == 99
示例#5
0
def test_instrument_context_manager_with_kind():
    # Save TR here, so it doesn't disappear on us when span finishes
    tr = TrackedRequest.instance()

    with instrument("Get", kind="Redis") as inst:
        inst.tag("foo", "bar")

    span = tr.complete_spans[-1]
    assert span.operation == "Redis/Get"
示例#6
0
def test_instrument_context_manager():
    # Save TR here, so it doesn't disappear on us when span finishes
    tr = TrackedRequest.instance()

    with instrument("Test ContextMgr") as inst:
        inst.tag("foo", "bar")

    span = tr.complete_spans[-1]
    assert span.operation == "Custom/Test ContextMgr"
async def set_future(fut, wait):
    """Helper function to set a future after a set delay.

    :fut: The future to be set.
    :wait: A float of seconds to be waited.
    :returns: nothing.
    """
    await asyncio.sleep(wait)
    with instrument("set_future"):
        fut.set_result("complete")
async def coro(value=None, wait=None):
    """Helper function for testing coroutines.

    :value: This will be inserted into the ``tags`` of ``instrument``.
    :wait: A float of seconds to be waited before calling ``instrument``.
    :loop: EventLoop to be used if any.
    :returns: nothing.
    """
    if wait:
        await asyncio.sleep(wait)
    tags = {"value": value} if value else None
    with instrument("coro", tags=tags):
        await asyncio.sleep(0.1)
async def test_instrument_context_manager_async_await_later(tracked_request):
    """
    Test proving that if an awaitable goes unawaited in a context manager,
    the spans are lost.
    """
    @instrument.async_("Outer")
    async def foo():
        with instrument("Inner"):
            pass

    async def example():
        await foo()

    with instrument("Test Decorator"):
        awaitable = example()

    await awaitable

    assert len(tracked_request.active_spans) == 0
    assert len(tracked_request.complete_spans) == 1
    assert tracked_request.complete_spans[
        0].operation == "Custom/Test Decorator"
 async def foo():
     with instrument("Inner"):
         pass
示例#11
0
 async def awaiting_task():
     with instrument('awaiting_task'):
         await asyncio.sleep(0.1)
         return "done"
示例#12
0
async def get_home():
    with instrument("get_home"):
        await asyncio.sleep(0.2)
        return "home"
示例#13
0
async def get_welcome():
    with instrument("get_welcome"):
        await asyncio.sleep(0.1)
        return "Welcome"