-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(instrumentation-fastify): fix span attributes and avoid FSTDEP017…
… FastifyDeprecation warning for 404 request (#1763) For a 404 `request.routeOptions.url` is undefined. Since fastify@4.10.0 when routeOptions was added, we shouldn't fallback to the deprecated request.routerPath. This also corrects the assumption that the handler name is "bound ..." in all cases. E.g. for a 404 it is Fastify's core "basic404" internal function. Also add a test that Fastify instrumentation works for ESM usage. Fixes: #1757 Co-authored-by: Marc Pichler <marc.pichler@dynatrace.com>
- Loading branch information
1 parent
b39c96c
commit 18ae75c
Showing
6 changed files
with
151 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
"fastify": | ||
- versions: "4.23.2" | ||
# Sanity check the first 4.x release, instead of all releases, plus recent | ||
# releases. | ||
- versions: "4.0.0 || >=4.24.3 <5" | ||
commands: npm run test | ||
|
||
# Fastify versions after 4.18.0 require a typescript greater than 4.4.4. | ||
"typescript": | ||
- versions: "4.7.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
plugins/node/opentelemetry-instrumentation-fastify/test/fixtures/use-fastify.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// Use fastify from an ES module: | ||
// node --experimental-loader=@opentelemetry/instrumentation/hook.mjs use-fastify.mjs | ||
|
||
import { trace } from '@opentelemetry/api'; | ||
import { createTestNodeSdk } from '@opentelemetry/contrib-test-utils'; | ||
|
||
import { FastifyInstrumentation } from '../../build/src/index.js'; | ||
|
||
const sdk = createTestNodeSdk({ | ||
serviceName: 'use-fastify', | ||
instrumentations: [ | ||
new FastifyInstrumentation() | ||
] | ||
}) | ||
sdk.start(); | ||
|
||
import Fastify from 'fastify'; | ||
import http from 'http'; | ||
|
||
// Start a fastify server. | ||
const app = Fastify(); | ||
app.get('/a-route', function aRoute(_request, reply) { | ||
reply.send({ hello: 'world' }); | ||
}) | ||
const addr = await app.listen({ port: 0 }); | ||
|
||
// Make a single request to it. | ||
await new Promise(resolve => { | ||
http.get(addr + '/a-route', (res) => { | ||
res.resume(); | ||
res.on('end', () => { | ||
resolve(); | ||
}); | ||
}) | ||
}) | ||
|
||
await app.close(); | ||
await sdk.shutdown(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters