Skip to content

Manual context propagation doesn't show total time in expanded trace #1577

@jedick

Description

@jedick

It is easy to create a trace with nested spans (Test 1). I want to use manual context propagation to achieve the same effect (Test 2).

with logfire.span("Test 1 - Nested spans"):
    with logfire.span("Sleep 1 second"):
        time.sleep(1)
    with logfire.span("Sleep 2 seconds"):
        time.sleep(2)

with logfire.span("Test 2 - Manual context propagation"):
    context = logfire.get_context()

with logfire.attach_context(context):
    with logfire.span("Sleep 1 second"):
        time.sleep(1)

with logfire.attach_context(context):
    with logfire.span("Sleep 2 seconds"):
        time.sleep(2)
Image

The issue is that the trace created with manual context propagation shows the total time when the trace is collapsed but a shorter time (probably just for get_context()) when the trace is expanded. Is there some way to get the expanded trace to show the total time?

For context: the use case is a Gradio app where the event chain should be logged in a single trace. The nested span approach isn't an option because there's no outer function to instrument.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions