or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-10/

Request Metrics Enrichment System

Build a request analytics system for an Express API that enriches distributed tracing spans with custom business metrics and request metadata.

Background

Your team needs to track business-critical metrics alongside technical observability data. The system should capture user identifiers, request priority levels, and processing metadata in distributed traces to enable better analytics and debugging.

Requirements

Create an Express API server with the following endpoints:

  • POST /api/orders - Creates a new order
  • GET /api/orders/:id - Retrieves order details
  • PUT /api/orders/:id/status - Updates order status

The server must integrate distributed tracing that automatically enriches trace spans with these custom attributes:

  1. User Context: Extract and record the user ID from the x-user-id request header as a span attribute named user.id

  2. Request Priority: Determine request priority based on the x-priority header and record it as request.priority. Valid values are "high", "medium", or "low". Default to "low" if not provided or invalid.

  3. Business Metrics: For POST and PUT requests, record request.has_body as true; for GET requests, record it as false

All custom attributes should be added to spans created for request handlers and middleware.

Test Cases

  • When a request is made with x-user-id: user-123, the trace spans include the attribute user.id with value "user-123" @test

  • When a request is made with x-priority: high, the trace spans include the attribute request.priority with value "high" @test

  • When a POST request is made to /api/orders, the trace spans include request.has_body set to true @test

  • When a GET request is made, the trace spans include request.has_body set to false @test

@generates

API

// Express server that handles order management endpoints
// Integrates OpenTelemetry instrumentation with custom attribute enrichment

Dependencies { .dependencies }

express { .dependency }

Web framework for building the API server.

@opentelemetry/instrumentation-express { .dependency }

Provides automatic instrumentation for Express applications with distributed tracing support.

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

Provides tracing SDK for span collection and export.

@opentelemetry/api { .dependency }

Provides OpenTelemetry API for instrumentation.