Skip to content

add snapstart span#911

Merged
jchrostek-dd merged 7 commits into
mainfrom
john/snapstart-span
Nov 6, 2025
Merged

add snapstart span#911
jchrostek-dd merged 7 commits into
mainfrom
john/snapstart-span

Conversation

@jchrostek-dd

Copy link
Copy Markdown
Contributor

Task

https://datadoghq.atlassian.net/browse/SVLS-7836?atlOrigin=eyJpIjoiMWNmZTMzOGE4NGEwNDE4MTk5Njk0N2ZmMmU3MzExMjgiLCJwIjoiaiJ9

Overview

The extension neither creates SnapStart spans nor emits SnapStart metrics. This PR adds both.

When a lambda with snapshot enabled is invoked for the first time, we get Platform.RestoreStart and Platform.RestoreReport. These effectively take the place of Platform.InitStart and Platform.InitReport events, so our code flow is pretty much identical to how we handle the cold start span and duration metric.

Note - When a SnapStart instance is restored, we actually receive the Platform.InitStart and Platform.InitReport events in addition to the Platform.RestoreStart and Platform.RestoreReport. However, the Init events are not from the sandbox starting for that invoke. These Init events are actually generated from when the Snapshot is created. This is very misleading - You can see that this trace is more than 3 hours long. The lambda was invoked more than 3 hours after the snapshot version was created. (This is the current experience).

Testing

I deployed my own extension with the changes and confirmed we are now getting a restore span and not an init span, link.

@jchrostek-dd
jchrostek-dd requested a review from a team as a code owner October 30, 2025 21:54
pub duration_ms: f64,
}

/// Restore report metrics

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.

Please add test coverage for new struct and new field above.

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.

Added.

@litianningdatadog

Copy link
Copy Markdown
Contributor

besides the unit tests, can we consider adding tests in bottlecap/tests/ to verify:
- SnapStart events create restore spans
- Restore spans are prioritized over cold start spans
- Metrics are correctly emitted

{
error!("Failed to send platform restore report to processor: {}", e);
}
}

@litianningdatadog litianningdatadog Nov 5, 2025

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.

Can we log error in case metrics is None as it may indicate malformed data?

@litianningdatadog litianningdatadog 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.

Left some comments.

@jchrostek-dd
jchrostek-dd merged commit 290016e into main Nov 6, 2025
39 checks passed
@jchrostek-dd
jchrostek-dd deleted the john/snapstart-span branch November 6, 2025 21:17
litianningdatadog pushed a commit that referenced this pull request Dec 1, 2025
https://datadoghq.atlassian.net/browse/SVLS-7836?atlOrigin=eyJpIjoiMWNmZTMzOGE4NGEwNDE4MTk5Njk0N2ZmMmU3MzExMjgiLCJwIjoiaiJ9

The extension neither creates SnapStart spans nor emits SnapStart
metrics. This PR adds both.

When a lambda with snapshot enabled is invoked for the first time, we
get `Platform.RestoreStart` and `Platform.RestoreReport`. These
effectively take the place of `Platform.InitStart` and
`Platform.InitReport` events, so our code flow is pretty much identical
to how we handle the cold start span and duration metric.

Note - When a SnapStart instance is restored, we actually receive the
`Platform.InitStart` and `Platform.InitReport` events in addition to the
`Platform.RestoreStart` and `Platform.RestoreReport`. However, the
`Init` events are not from the sandbox starting for that invoke. These
`Init` events are actually generated from when the Snapshot is created.
This is very misleading - You can see that this
[trace](https://ddserverless.datadoghq.com/serverless/aws/lambda?fromUser=false&graphType=flamegraph&group=&highlight=snapstart-java-cdk-function&panel_end=1761860524106&panel_paused=false&panel_start=1761846124106&shouldShowLegend=true&sp=%5B%7B%22p%22%3A%7B%22entityId%22%3A%22aws-lambda-functions%2Bsnapstart-java-cdk-function%2Bus-east-1%2B425362996713%22%7D%2C%22i%22%3A%22lambda-panel%22%7D%2C%7B%22p%22%3A%7B%22traceID%22%3A%225400520227836710313%22%2C%22selectedSpanID%22%3A%22644948261311059067%22%7D%2C%22i%22%3A%22trace-panel%22%7D%5D&spanID=644948261311059067&text_search=snapstart&traceID=5400520227836710313&traceQuery=&start=1761845683104&end=1761860083104&paused=false)
is more than 3 hours long. The lambda was invoked more than 3 hours
after the snapshot version was created. (This is the current
experience).

I deployed my own extension with the changes and confirmed we are now
getting a restore span and not an init span,
[link](https://ddserverless.datadoghq.com/serverless/aws/lambda?fromUser=false&graphType=flamegraph&group=&panel_end=1761860640000&panel_paused=false&panel_start=1761846240000&shouldShowLegend=true&sp=%5B%7B%22p%22%3A%7B%22entityId%22%3A%22aws-lambda-functions%2Bsnapstart-java-function%2Bus-east-1%2B425362996713%22%7D%2C%22i%22%3A%22lambda-panel%22%7D%2C%7B%22p%22%3A%7B%22traceID%22%3A%226634828896084800457%22%2C%22selectedSpanID%22%3A%222017721198037440020%22%7D%2C%22i%22%3A%22trace-panel%22%7D%5D&spanID=2017721198037440020&text_search=snapstart&traceID=6634828896084800457&traceQuery=&start=1761845683104&end=1761860083104&paused=false).
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