Provides low-level interfaces and helper methods for authentication in Azure SDK
Overall
score
97%
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.
Your implementation should provide a ContextManager class with the following capabilities:
The manager should work with symbol-based keys for type safety and support arbitrary metadata values.
// 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);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;
}@generates
Provides the TracingContext interface for immutable context propagation compatible with OpenTelemetry.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-azure--core-authdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10