or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

Express Request Tracer

A simple Express.js application that demonstrates distributed tracing with OpenTelemetry by instrumenting HTTP requests and Express middleware to capture request lifecycle data.

Capabilities

Basic Express Server Setup

  • Creates an Express server with multiple routes that can be traced @test
  • Starts server on a configurable port @test

OpenTelemetry Tracing Setup

  • Configures OpenTelemetry tracing with HTTP instrumentation @test
  • Captures trace data for incoming HTTP requests @test

Route Instrumentation

  • Instruments a GET /users/:id route to trace parameterized path handling @test
  • Instruments a POST /users route to trace different HTTP methods @test
  • Traces include HTTP method, route path, and status code information @test

Implementation

@generates

The implementation should:

  1. Set up OpenTelemetry with both HTTP and Express instrumentation
  2. Configure a basic in-memory span exporter to capture traces
  3. Create an Express application with at least two routes:
    • GET /users/:id - Returns a mock user object with the given ID
    • POST /users - Creates a mock user and returns success response
  4. Ensure HTTP instrumentation is enabled so Express instrumentation can enrich the HTTP spans

API

/**
 * Starts the Express server with OpenTelemetry tracing enabled.
 *
 * @param {number} port - The port to listen on
 * @returns {Promise<object>} Server instance
 */
function startServer(port) {
  // IMPLEMENTATION HERE
}

/**
 * Stops the server and flushes any remaining traces.
 *
 * @param {object} server - The server instance to stop
 * @returns {Promise<void>}
 */
function stopServer(server) {
  // IMPLEMENTATION HERE
}

/**
 * Retrieves captured spans from the in-memory exporter.
 *
 * @returns {Array} Array of captured span objects
 */
function getSpans() {
  // IMPLEMENTATION HERE
}

module.exports = {
  startServer,
  stopServer,
  getSpans,
};

Dependencies { .dependencies }

express { .dependency }

Fast, unopinionated, minimalist web framework for Node.js

@opentelemetry/api { .dependency }

Public API for OpenTelemetry tracing

@opentelemetry/sdk-node { .dependency }

OpenTelemetry SDK for Node.js with automatic instrumentation support

@opentelemetry/instrumentation-http { .dependency }

Automatic instrumentation for Node.js HTTP/HTTPS modules

@opentelemetry/instrumentation-express { .dependency }

Automatic instrumentation for Express.js applications

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

Core tracing functionality including span processors and exporters