docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a request analytics system for an Express API that enriches distributed tracing spans with custom business metrics and request metadata.
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.
Create an Express API server with the following endpoints:
POST /api/orders - Creates a new orderGET /api/orders/:id - Retrieves order detailsPUT /api/orders/:id/status - Updates order statusThe server must integrate distributed tracing that automatically enriches trace spans with these custom attributes:
User Context: Extract and record the user ID from the x-user-id request header as a span attribute named user.id
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.
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.
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
// Express server that handles order management endpoints
// Integrates OpenTelemetry instrumentation with custom attribute enrichmentWeb framework for building the API server.
Provides automatic instrumentation for Express applications with distributed tracing support.
Provides tracing SDK for span collection and export.
Provides OpenTelemetry API for instrumentation.