docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a simple observability tool for an Express.js application that tracks the execution of different middleware and route handlers using distributed tracing.
You need to create a basic Express server with several middleware functions and route handlers. The server should be instrumented to automatically create trace spans for each layer of the Express application (middleware, routers, and request handlers) so you can observe the execution flow and timing of requests.
Create an Express application with the following:
/api/users with:
/ that returns a list of users/:id that returns a specific user/health that returns server health statusConfigure automatic span creation for all Express layers (middleware, routers, and request handlers) to capture timing and execution flow. The tracing should work without manually instrumenting each middleware or handler.
/**
* Creates and configures an Express application with tracing.
* @returns {Express.Application} The configured Express app
*/
function createApp() {
// Implementation here
}
/**
* Starts the Express server on the specified port.
* @param {number} port - The port to listen on
* @returns {Server} The HTTP server instance
*/
function startServer(port) {
// Implementation here
}
module.exports = {
createApp,
startServer
};Provides the web application framework for handling HTTP requests and middleware.
Provides automatic instrumentation and span creation for Express.js applications.
Provides the tracing SDK for Node.js applications to collect and export traces.
Provides the OpenTelemetry API for working with traces and spans.