import { Tracer, Span, type Context } from '@opentelemetry/api'; /** * Get the OpenTelemetry Tracer instance for the Optimizely SDK. * * The tracer uses the global OTEL provider. If no provider is configured, * all spans will be no-ops. * * @example * ```typescript * import { getTracer } from '@optimizely/cms-sdk'; * * const tracer = getTracer(); * const span = tracer.startSpan('my.custom.operation'); * try { * // your code here * span.setStatus({ code: SpanStatusCode.OK }); * } catch (error) { * span.recordException(error); * span.setStatus({ code: SpanStatusCode.ERROR }); * } finally { * span.end(); * } * ``` * * @returns The SDK's tracer instance */ export declare const getTracer: () => Tracer; /** * Options for creating a span. */ export type SpanOptions = { /** Optional attributes to add to the span when it starts */ attributes?: Record; /** Optional parent context for creating child spans */ parentContext?: Context; }; /** * Wraps an async operation in an OTEL span with automatic error handling. * * This utility function: * 1. Starts an active span (makes it current in context) * 2. Executes the provided function with the span as a parameter * 3. Sets span status to OK on success * 4. Records exceptions and sets ERROR status on failure * 5. Always ends the span (even on error) * 6. Re-throws any exceptions (preserves error propagation) * * The span is "active" which means nested SDK calls will automatically * become children of this span in the trace hierarchy. * * @param name - Span name (use namespace format: "optimizely.operation.name") * @param fn - Async function to execute within the span * @param options - Optional span attributes and parent context * @returns The result of the function * @throws Re-throws any exception from the function after recording it * * @example * ```typescript * const result = await createSpan( * 'myapp.process.data', * async (span) => { * span.setAttribute('record.count', records.length); * return processRecords(records); * }, * { attributes: { 'data.source': 'api' } } * ); * ``` */ export declare const createSpan: (name: string, fn: (span: Span) => Promise | T, options?: SpanOptions) => Promise;