or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-3/

Express Middleware Observability Tool

Build a simple observability tool for an Express.js application that tracks the execution of different middleware and route handlers using distributed tracing.

Requirements

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.

Server Setup

Create an Express application with the following:

  1. A logging middleware that logs request information
  2. An authentication middleware that checks for an auth header
  3. A router mounted at /api/users with:
    • A GET handler at / that returns a list of users
    • A GET handler at /:id that returns a specific user
  4. A simple GET route at /health that returns server health status

Tracing Requirements

Configure 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.

Test Cases

  • The server responds to GET /health with status 200 @test
  • The server responds to GET /api/users with a list of users @test
  • The server responds to GET /api/users/123 with a specific user @test

Implementation

@generates

API

/**
 * 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
};

Dependencies { .dependencies }

express { .dependency }

Provides the web application framework for handling HTTP requests and middleware.

@opentelemetry/instrumentation-express { .dependency }

Provides automatic instrumentation and span creation for Express.js applications.

@opentelemetry/sdk-trace-node { .dependency }

Provides the tracing SDK for Node.js applications to collect and export traces.

@opentelemetry/api { .dependency }

Provides the OpenTelemetry API for working with traces and spans.