Provides low-level interfaces and helper methods for authentication in Azure SDK
Overall
score
97%
Build a request context manager that propagates trace information across asynchronous operations. The manager should maintain immutable context state and provide utilities for managing trace metadata throughout a request lifecycle.
Implement a context manager with the following capabilities:
Create a utility function createRequestContext() that initializes a new empty tracing context. This will serve as the base context for tracking request metadata.
Implement a function setTraceId(context, traceId) that accepts a tracing context and a trace ID string, returning a new context with the trace ID stored. The trace ID should be associated with a Symbol key named TRACE_ID_KEY.
Implement a function getTraceId(context) that retrieves the trace ID from a context, returning the string value or undefined if not present.
Implement a function setSpanContext(context, spanData) that accepts a tracing context and an object containing span information (such as spanId, parentSpanId, and timestamp), returning a new context with this data stored under a Symbol key named SPAN_CONTEXT_KEY.
Implement a function getSpanContext(context) that retrieves the span context data from a context.
Implement a function removeSpanContext(context) that accepts a tracing context and returns a new context with the span context removed, while preserving other metadata like trace IDs.
Implement a function hasTraceId(context) that checks whether a context contains a trace ID, returning a boolean value.
createRequestContext() returns a valid TracingContext instance @test{ spanId: "span-123", parentSpanId: "parent-456", timestamp: 1234567890 } and retrieving it returns the same object @testgetTraceId still returns the trace ID but getSpanContext returns undefined @testhasTraceId returns true for a context with a trace ID and false for an empty context @test@generates
import { TracingContext } from '@azure/core-auth';
export const TRACE_ID_KEY: symbol;
export const SPAN_CONTEXT_KEY: symbol;
export function createRequestContext(): TracingContext;
export function setTraceId(context: TracingContext, traceId: string): TracingContext;
export function getTraceId(context: TracingContext): string | undefined;
export function setSpanContext(
context: TracingContext,
spanData: { spanId: string; parentSpanId?: string; timestamp: number }
): TracingContext;
export function getSpanContext(
context: TracingContext
): { spanId: string; parentSpanId?: string; timestamp: number } | undefined;
export function removeSpanContext(context: TracingContext): TracingContext;
export function hasTraceId(context: TracingContext): boolean;Provides the TracingContext interface for distributed tracing support.
@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