-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add used build plugins and their versions to exec-build span #5584
Conversation
packages/build/src/core/build.ts
Outdated
if (execBuildSpan && pluginsOptionsA?.length) { | ||
for (const plugin of pluginsOptionsA) { | ||
if (plugin?.pluginPackageJson?.name) { | ||
execBuildSpan.setAttribute( | ||
`build.plugins['${plugin.pluginPackageJson.name}']`, | ||
plugin?.pluginPackageJson?.version ?? 'N/A', | ||
) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a bit of argument drilling to make sure we set those attributes on exec-build
span (instead of using something like active span) so this doesn't accidentally start putting this attributes on other spans as we do want to ensure those are on exec-build
.
I'm not sure if it's possible to have plugin name without actual version, so 'N/A' is just fallback to ensure the plugin is at least logged even if we didn't manage to get its version.
build.plugins['<plugin-name>']
is just something that made some sense initially to me, but if there is better semantic name to use - I'm more than happy to adjust.
Similarly if there is maybe other approach that could be used instead of those individual attributes with ['<plugin-name>']
syntax that you think is better that will still allow us to filter spans for @netlify/plugin-nextjs
with version above or equal 5 - also happy to adjust it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sure we set those attributes on exec-build span (instead of using something like active span) so this doesn't accidentally start putting this attributes on other spans as we do want to ensure those are on exec-build.
Ah missed this bit before creating - #5587. Sorry about that. I wonder though if there's other alternative besides passing the span all the way down 😬 I'm affraid of creating an anti pattern here.
The way contexts are setup for JS otel is really annoying in this sense 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use something like AsyncLocalStorage
directly (same thing that powers OTEL's active span tracking), but just put exec-build
span on it directly and get access to it this way without "argument drilling".
I'm not sure if there are features in (JS) OTEL API / packages / helpers that could maybe allow us to use something like that with "first-class otel citizen" approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevertheless I think we should be good to just tap into wtv the active span is here.
If your biggest concern is that we may end up changing the span here leading your query (being filtered by exec-build
) to comeback empty in terms of build.plugins
we could instead create a specific span here which could:
- Have a well known name to y'all, making sure the span you most rely on suddently doesn't change.
- Passing the over the
plugins
options as baggage to the child spans, so that way we could even ensure we could filter other spans by these new properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://opentelemetry.io/docs/languages/js/context/ is potentially OTEL abstraction for AsyncLocalStorage (or other async_hooks
) that might do that, but I'm not sure if we don't use it in some way where this could be problematic. We could add exec-build
and create new derived context so that all descendent spans could get exec-build
span from it, but we might use context already to propagate other kind of data so it might mess with that (i.e. - would this mess with something like this
return context.with(getGlobalContext(), async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just come clarification here as well - all those attributes don't necessarily need to land exec-build
span - we can use anything else but the actual requirement is that whatever span we use need to have build status (success / failure) and ideally build error "location"/"type" (so for example we can rule out failed builds because user's build command failed because of user error and only track build/deploy errors that in some way were possibly caused by Next runtime doing something wrong - either directly in their build step or possibly producing problematic function that later failed to bundle/upload etc).
exec-build
seems to be the span that always have build status and build errors (location/type) attributes on it and hence this was used as target for new attributes in this PR. It also seem like only span today that wrap entire build with all its steps so at least now it seem to be only span that fit the requirements, but creating new span could work too (tho it feels it will have similar "challenges" as exec-build
with either argument drilling or trying to use async_hooks
in some way - either directly or via OTEL ContextManager, so that doesn't seem to solve the problem to me (?) )
Alternatively entire assumption that all the attributes need to be on the same span is wrong and we can do some kind of "joins" in honeycomb to find traces that has some attributes/values on one span and then other attributes/values on other span, but I couldn't find anything like that and only filtering I was able to achieve was about attribute combination on same span.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a comment in here, but something else we need to be aware of is changing the coventional commit prefix here so this triggers a release.
Should this be |
yep needs to be a |
67160b1
to
90446fa
Compare
90446fa
to
bf55141
Compare
Summary
We are currently unable to create SLO in honeycomb that target just Next Runtime v5 to capture overall build error rates with it.
We do have individual build steps annotated with plugin name and version that is being executed, but we can't join
exec-build
span with those to extract needed information. This PR adds information about used Build Plugins toexec-build
by adding 1 span attribute per plugin with name containing plugin name and value being its version to be able to filterexec-build
by specific plugins (and their versions).This will allow queries like below to be able to create actual SLO and alerting
![image](https://private-user-images.githubusercontent.com/419821/319980221-38190e64-889b-4d98-9e45-355081e76164.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1ODgzNTYsIm5iZiI6MTczOTU4ODA1NiwicGF0aCI6Ii80MTk4MjEvMzE5OTgwMjIxLTM4MTkwZTY0LTg4OWItNGQ5OC05ZTQ1LTM1NTA4MWU3NjE2NC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNVQwMjU0MTZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iMzhiMzg5NDQwOTViOTc3MDk1ZDhjMDA1OWY5ZmM1NmIyMDFkNDcwZDdlYjNiYjRmMTQwNmQ0YzdiN2I5OTZkJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.m42QsUUVq4ldkzP3_CDmnEXnEvVLLq1YKdXflsUVXvU)
Related to https://linear.app/netlify/issue/FRA-367/update-build-time-metrics
Relevant slack discussion: https://netlify.slack.com/archives/C031MPNJWK1/p1712068846389239