CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-azure--core-auth

Provides low-level interfaces and helper methods for authentication in Azure SDK

Overall
score

97%

Overview
Eval results
Files

task.mdevals/scenario-10/

Distributed Tracing Context Manager

Build a tracing context manager that maintains correlation data across asynchronous operations. The manager should support immutable context propagation, allowing trace information to flow through a chain of async operations without mutation.

Requirements

Your implementation should provide a ContextManager class with the following capabilities:

  1. Context Creation: Create new context instances with initial trace data
  2. Context Propagation: Pass context through async operations while maintaining immutability
  3. Context Enrichment: Add new trace metadata at each operation stage
  4. Context Reading: Extract trace information for logging and monitoring

The manager should work with symbol-based keys for type safety and support arbitrary metadata values.

Example Usage

// Create a context manager with initial trace data
const manager = new ContextManager();
const initialContext = manager.createContext(TRACE_ID_KEY, "trace-123");

// Propagate context through async operations, adding metadata at each stage
async function operationA(context: unknown) {
  console.log("Operation A - Trace ID:", manager.getValue(context, TRACE_ID_KEY));
  const enrichedContext = manager.addMetadata(context, SPAN_ID_KEY, "span-a");
  return enrichedContext;
}

async function operationB(context: unknown) {
  console.log("Operation B - Trace ID:", manager.getValue(context, TRACE_ID_KEY));
  const enrichedContext = manager.addMetadata(context, SPAN_ID_KEY, "span-b");
  return enrichedContext;
}

// Execute operations with context propagation
const contextA = await operationA(initialContext);
const contextB = await operationB(contextA);

API Requirements

Implement the following TypeScript API:

// Symbol keys for type-safe context storage
export const TRACE_ID_KEY: unique symbol;
export const SPAN_ID_KEY: unique symbol;

export class ContextManager {
  /**
   * Creates a new context with initial trace data
   */
  createContext(key: symbol, value: unknown): unknown;

  /**
   * Retrieves a value from the context using a symbol key
   */
  getValue(context: unknown, key: symbol): unknown;

  /**
   * Creates a new context with additional metadata (immutable operation)
   */
  addMetadata(context: unknown, key: symbol, value: unknown): unknown;

  /**
   * Creates a new context with a key removed (immutable operation)
   */
  removeMetadata(context: unknown, key: symbol): unknown;
}

Test Cases

  • Creating a context with initial data stores and retrieves the value correctly @test
  • Adding metadata to a context creates a new context instance while preserving original @test
  • Removing metadata from a context creates a new context without the specified key @test
  • Retrieving a non-existent key from a context returns undefined @test

Implementation

@generates

Dependencies { .dependencies }

@azure/core-auth { .dependency }

Provides the TracingContext interface for immutable context propagation compatible with OpenTelemetry.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-azure--core-auth

tile.json