awslabs / aws-lambda-rust-runtime

A Rust runtime for AWS Lambda
Apache License 2.0
3.36k stars 343 forks source link

Make child-spans work as expected when using the lambda-runtime #896

Closed TethysSvensson closed 5 months ago

TethysSvensson commented 5 months ago

Issue #, if available: N/A

Description of changes: Implementing a sub-span directly in the service_fn does not currently set the parent-span in the expected way. Example:

let func = service_fn(move |event: LambdaEvent<T>| {
    let event_span = create_event_span(outer_variable);
    inner_handler(event, state.clone()).instrument(event_span)
});

The problem is, that at the time where the create_event_span() function is called, the span returned by request_span() has not been entered, so it will be not be set as the parent.

The solution is to enter the span before calling the inner service. This also matches e.g. how tower_http does it.

By submitting this pull request

TethysSvensson commented 5 months ago

And thank you for accepting it!

Are you by any chance planning to do a release for this?

I'm asking because if you are, then I would rather wait for your release than create a work-around in our internal code.

calavera commented 5 months ago

I'm asking because if you are, then I would rather wait for your release than create a work-around in our internal code.

Not this week.