-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Migrate to @fastify/otel
#15542
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
base: develop
Are you sure you want to change the base?
Conversation
38047fd
to
6c347ee
Compare
packages/node/package.json
Outdated
@@ -101,7 +101,8 @@ | |||
"import-in-the-middle": "^1.13.0" | |||
}, | |||
"devDependencies": { | |||
"@types/node": "^18.19.1" | |||
"@types/node": "^18.19.1", | |||
"fastify": "4.18.0" |
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.
Can we avoid this and just vendor in the minimal interface we need to satisfy the types?
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.
Sure 👍
size-limit report 📦
|
88d946e
to
112c80a
Compare
@@ -0,0 +1,32 @@ | |||
/* |
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.
For the files we vendored in from OTEL, we should also link to the git sha we used of the versioned files.
ad52eb9
to
9ca14db
Compare
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.
Great job! This is looking nice.
packages/node/package.json
Outdated
@@ -65,6 +65,7 @@ | |||
"access": "public" | |||
}, | |||
"dependencies": { | |||
"@fastify/otel": "0.5.0", |
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.
l: We can bump to 0.5.1
// /** | ||
// * Minimal request type containing properties around route information. | ||
// * Works for Fastify 3, 4 and presumably 5. | ||
// * | ||
// * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/request.d.ts | ||
// */ | ||
// // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
// interface MinimalFastifyRequest extends Record<string, any> { | ||
// method?: string; | ||
// // since fastify@4.10.0 | ||
// routeOptions?: { | ||
// url?: string; | ||
// }; | ||
// routerPath?: string; | ||
// } | ||
|
||
// /** | ||
// * Minimal reply type containing properties needed for error handling. | ||
// * | ||
// * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/reply.d.ts | ||
// */ | ||
// // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
// interface MinimalFastifyReply extends Record<string, any> { | ||
// statusCode: number; | ||
// } | ||
|
||
// // We inline the types we care about here | ||
// interface Fastify { | ||
// // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
// version: string; | ||
// register: (plugin: any) => Fastify; | ||
// after: (listener?: (err: Error) => void) => Fastify; | ||
// addHook: (name: string, handler: (...params: unknown[]) => void) => Fastify; | ||
// } |
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.
l: Do we want to keep this around?
2bd1c74
to
0308803
Compare
@andreiborza - I updated the PR. Waiting for fastify/otel#35 to be released. |
I would assume this also closes #12844? |
looks like it's been released with Make sure to update the lock file when you bump. |
bd5f0ab
to
b1847dc
Compare
b1847dc
to
275a14d
Compare
@andreiborza, @mydea. I bumped the version. I think it's ready to go now. |
43c201f
to
964cf0c
Compare
Yes, that should resolve it as well |
data: { | ||
'sentry.origin': 'manual', | ||
'fastify.type': 'middleware', | ||
'plugin.name': 'fastify -> @fastify/middie', |
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.
do we have no more plugin/middleware spans like this anymore? Is this "OK"?
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.
Checked again after the updates. We still have the middie
spans, I added them back to the tests. But the problem is now that we don't have access to the requestHook
anymore, the spans are not formatted correctly in NestJS applications (when setupFastifyErrorHandler
is not used). We attempt using addFastifySpanAttributes
inside setupFastifyErrorHandler
.
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.
I'm now trying to use diagnosticsChannel
for it. Maybe we can reach the context from 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.
can we try to PR something like the requestHook to the otel instrumentation, maybe? Or is this something they do not want?
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.
@mydea, they released a way to reach the spans: https://github.com/fastify/otel/releases/tag/v0.6.0
The problem is that with this release, they removed the vendored types we added previously. Adding fastify
here as a devDependency
works for TypeScript 5, but not in previous versions. Should we make this an exception for TS-3.8 support/tests?
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.
they removed the vendored types
what do you mean, can we not replicate this anymore? 😢
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.
Unfortunately, yes: https://github.com/fastify/otel/pull/46/files#diff-7aa4473ede4abd9ec099e87fec67fd57afafaf39e05d493ab4533acc38547eb8
Had to remove the previously vendored types due to conflicts with interface augmentation typical in fastify plugins.
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.
@mydea - Looks like they have overridden the types of fastify
. So, it works now without adding fastify
as a dependency. Please bear with me when I generate sample events and post links.
@onurtemizkan could you maybe share a link of one or two example transactions captured to Sentry with the new version, to compare with the old version? that would be great 🙏 |
5329aaa
to
8ff5f09
Compare
@mydea - Updated the PR description with event links |
}); | ||
|
||
// Returning this as any not to deal with the internal types of the FastifyOtelInstrumentation | ||
return fastifyOtelInstrumentationInstance as any; |
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.
l: Can we return this as unknown
or something like this, to avoid users using this in weird ways? Pretty theoretical probably, but to be safe... or if unknown does not work, return a minimal type that is accepted?
const fastifyOtelInstrumentationInstance = new FastifyOtelInstrumentation(); | ||
const plugin = fastifyOtelInstrumentationInstance.plugin(); | ||
|
||
// This message handler works for Fastify versions 3, 4 and 5 |
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.
this also works for fastify 3? I thought only 4+5?
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.
some small notes but overall looking good!
To clarify, this does not remove the need to call setupFastifyErrorHandler
yet, right?
Resolves: #15130
Example events: