-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(instrumentation-express): Support multiple routes with RegExp.
- Loading branch information
1 parent
b2bcbed
commit b188318
Showing
4 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
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
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
67 changes: 67 additions & 0 deletions
67
plugins/node/opentelemetry-instrumentation-express/test/fixtures/use-express-regex.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,67 @@ | ||
/* | ||
* 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 express from an ES module: | ||
// node --experimental-loader=@opentelemetry/instrumentation/hook.mjs use-express-regex.mjs | ||
|
||
import { promisify } from 'util'; | ||
import { createTestNodeSdk } from '@opentelemetry/contrib-test-utils'; | ||
|
||
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; | ||
import { ExpressInstrumentation } from '../../build/src/index.js'; | ||
|
||
const sdk = createTestNodeSdk({ | ||
serviceName: 'use-express-regex', | ||
instrumentations: [ | ||
new HttpInstrumentation(), | ||
new ExpressInstrumentation() | ||
] | ||
}) | ||
sdk.start(); | ||
|
||
import express from 'express'; | ||
import * as http from 'http'; | ||
|
||
const app = express(); | ||
|
||
app.use(async function simpleMiddleware(req, res, next) { | ||
// Wait a short delay to ensure this "middleware - ..." span clearly starts | ||
// before the "router - ..." span. The test rely on a start-time-based sort | ||
// of the produced spans. If they start in the same millisecond, then tests | ||
// can be flaky. | ||
await promisify(setTimeout)(10); | ||
next(); | ||
}); | ||
|
||
app.get(['/test/arr/:id', /\/test\/arr[0-9]*\/required(path)?(\/optionalPath)?\/(lastParam)?/], (_req, res) => { | ||
res.send({ response: 'response' }); | ||
}); | ||
|
||
const server = http.createServer(app); | ||
await new Promise(resolve => server.listen(0, resolve)); | ||
const port = server.address().port; | ||
|
||
await new Promise(resolve => { | ||
http.get(`http://localhost:${port}/test/arr/requiredPath/optionalPath/lastParam`, (res) => { | ||
res.resume(); | ||
res.on('end', () => { | ||
resolve(); | ||
}); | ||
}) | ||
}); | ||
|
||
await new Promise(resolve => server.close(resolve)); | ||
await sdk.shutdown(); |