Skip to content

feat: wire in AAP span processor in the trace_processor#767

Merged
RomainMuller merged 25 commits into
romain.marcadier/serverless-aap-portfrom
romain.marcadier/serverless-aap-port__span-processor
Aug 11, 2025
Merged

feat: wire in AAP span processor in the trace_processor#767
RomainMuller merged 25 commits into
romain.marcadier/serverless-aap-portfrom
romain.marcadier/serverless-aap-port__span-processor

Conversation

@RomainMuller

@RomainMuller RomainMuller commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

Annotates the spans in TraceProcessor::process_traces if there is a corresponding security context, and the span's name is aws.lambda.

If the response for the request has not been seen yet, temporarily buffers the span to wait for completion before actually sending it out.

Annotates the spans in `TraceAgent::handle_traces` if there is a corresponding
security context, and the span's name is `aws.lambda`.

If the response for the request has not been seen yet, temporarily buffers
the span to wait for completion before actually sending it out.
@RomainMuller RomainMuller changed the title feat: wire in AAP span processor in the trace_agent feat: wire in AAP span processor in the trace_processor Aug 4, 2025
@RomainMuller RomainMuller marked this pull request as ready for review August 4, 2025 13:55
@RomainMuller RomainMuller requested a review from a team as a code owner August 4, 2025 13:55
}
}
impl Drop for Context {
fn drop(&mut self) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this mean that there's a possibility the aws.lambda span will be completely dropped if appsec is not seen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, yes... But all code paths that lead to dropping a Context from the buffer properly finalize it. This Drop here is additional assurance that this does not diverge in the future.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, sounds good, just wanted to check because if this happens, the invocation won't appear in the customers Serverless view, as we depend on the aws.lambda span

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes yes, I am pretty well aware of this... If everything wasn't async-tainted, I'd have released the trace in impl Drop but I can't, because I can't guarantee I have an async runtime available when Drop runs.

Comment thread bottlecap/src/proxy/interceptor.rs Outdated
@RomainMuller RomainMuller force-pushed the romain.marcadier/serverless-aap-port__span-processor branch from 5f296a1 to e1db1a0 Compare August 5, 2025 13:48
@RomainMuller RomainMuller force-pushed the romain.marcadier/serverless-aap-port__span-processor branch from e1db1a0 to d6ebaa6 Compare August 5, 2025 14:00
/// Whether we have had a chance to see the response body or not.
response_seen: bool,
/// Holds a trace for sending once the response is seen.
on_response_seen: Option<(Vec<Span>, SendingTraceProcessor, HoldArguments)>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this instead be the something explaining which values it holds, and then we can use the existing method of is_pending_response as the boolean check?

That way, when we are doing take() its easier to read?

}

/// Marks the response of this request as having been seen.
pub(super) async fn set_response_seen(&mut self) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name set_response_seen is confusing because hold_trace is the one who actually sets the response as seen 🤔 whereas in here we are just processing + sending data to the trace aggregator

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the confusion here... We mark the Context as having seen the response, which possibly allows a trace to be flushed if one was held; or will cause the trace to not be held if we haven't seen it yet.

I was thinking about possibly renaming this to something like finalize so it's context.finalize()... I'd then add some debug_assert! in other setters to ensure we don't try to re-use a finalized context.

Comment on lines +78 to +79
response_seen: false,
on_response_seen: None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah having response_seen and on_response_seen confused me a lot, I just saw these are two different things

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a "classic" finalized/onFinalize pair. But we can model this a little more to make it more obvious.

Comment thread bottlecap/src/appsec/processor/context.rs Outdated
Comment thread bottlecap/src/appsec/processor/context.rs
Comment thread bottlecap/src/appsec/processor/ruleset.rs
Comment thread bottlecap/src/bin/bottlecap/main.rs Outdated

@duncanista duncanista left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, left some comments with suggestions and questions!

RomainMuller and others added 2 commits August 6, 2025 09:59
Co-authored-by: jordan gonzález <30836115+duncanista@users.noreply.github.com>
@RomainMuller RomainMuller force-pushed the romain.marcadier/serverless-aap-port branch from 3a9bf52 to 96ffde8 Compare August 8, 2025 09:48
@RomainMuller RomainMuller force-pushed the romain.marcadier/serverless-aap-port__span-processor branch from 47259ca to 466de2c Compare August 8, 2025 09:49
@duncanista duncanista force-pushed the romain.marcadier/serverless-aap-port__span-processor branch from c924410 to a54a1d1 Compare August 8, 2025 20:17

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size differs from the one in here 1df2130

Are they different?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes it's quite possible git resolved the conflict the wrong way... lemme make sure this is latest.

@RomainMuller RomainMuller merged commit acde692 into romain.marcadier/serverless-aap-port Aug 11, 2025
42 checks passed
@RomainMuller RomainMuller deleted the romain.marcadier/serverless-aap-port__span-processor branch August 11, 2025 08:24
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

Successfully merging this pull request may close these issues.

2 participants