or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-5/

Express Layer Metadata Collector

Build a diagnostic tool that instruments an Express application to collect and report metadata about the layers (middleware, routers, and request handlers) executed during HTTP requests.

Requirements

Create an Express application with instrumentation that:

  1. Sets up an Express app with:
    • One middleware function (e.g., logging middleware)
    • A main route at /api/users that returns a list of users
    • A nested router mounted at /api that contains the /users route
  2. Instruments the application to automatically capture layer metadata
  3. Collects the following information for each executed layer:
    • Layer name (function name or assigned name)
    • Layer type (one of: middleware, router, or request handler)
    • Route path (the route pattern matched)
  4. Provides a /metrics endpoint that returns all collected layer metadata as JSON
  5. Ensures metadata is collected automatically through instrumentation hooks

Implementation Files

  • server.js - Express application with routes, middleware, and the /metrics endpoint
  • server.test.js - Tests to verify layer metadata collection

Test Cases

  • Making a GET request to /api/users triggers metadata collection for all layers in the request pipeline @test
  • The /metrics endpoint returns an array of layer metadata objects, each containing name, type, and route properties @test
  • Layer types are correctly identified as "middleware", "router", or "request_handler" @test

@generates

API

const express = require('express');

/**
 * Creates and configures an Express application with instrumentation
 * @returns {express.Application} Configured Express app
 */
function createApp() {
  // Returns Express app with routes and instrumentation
}

module.exports = { createApp };

Dependencies { .dependencies }

express { .dependency }

Provides the web application framework.

@opentelemetry/instrumentation-express { .dependency }

Provides instrumentation capabilities for Express applications to enable automatic layer metadata extraction and observability.