CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-opentelemetry--instrumentation-express

OpenTelemetry instrumentation for Express.js web applications enabling automatic distributed tracing and observability

80

1.63x
Overview
Eval results
Files

task.mdevals/scenario-3/

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.

Install with Tessl CLI

npx tessl i tessl/npm-opentelemetry--instrumentation-express

tile.json