import type { SdkOperatingSystem } from '../../utils/getOperatingSystem/getOperatingSystem.types';
import type { SdkPlatform } from '../../utils/getPlatform/getPlatform.types';
export type InstrumentationEventPhase = 'started' | 'resolved' | 'rejected';
/**
 * Datadog reserved attribute for log severity. DD uses this field to colour-
 * code rows and power the Status facet — must be one of its recognised values.
 */
export type InstrumentationStatus = 'error' | 'info' | 'debug';
/**
 * Fields shared by every instrumentation event. All values here are either
 * SDK-controlled metadata or non-sensitive identifiers — none derive from a
 * function's arguments or return value, so the context is always safe to
 * forward to an external transport.
 */
export type InstrumentationContext = {
    environmentId: string;
    /** The operating system the SDK is executing on. */
    operatingSystem: SdkOperatingSystem;
    /** The runtime platform the SDK is executing on. */
    platform: SdkPlatform;
    /** Extension keys registered on the client at the time the event was emitted. */
    registeredExtensionKeys: string[];
    sdkSessionId: string;
    sdkVersion: string;
    status: InstrumentationStatus;
    timestamp: string;
    tokenSessionId: string | null;
    userAgent: string;
    userId: string | null;
};
/**
 * An explicit, opt-in telemetry payload. Restricting values to primitives is
 * the core guardrail of the explicit-logging model: a selector can only forward
 * individually chosen, known-safe fields (e.g. `{ scope }`) and can never hand
 * a whole object/array (e.g. `{ user }`) to a transport, where nested secrets
 * or PII would ride along unnoticed. Keeping the type primitive-only makes each
 * logged field a deliberate, statically reviewable decision.
 */
export type SafePayload = Record<string, string | number | boolean | null>;
/**
 * Co-located selectors that build an explicit {@link SafePayload} from a
 * function's arguments (started) and/or resolved value (resolved). A function
 * with no selectors emits envelope-only events. This is the only path from
 * arguments/return value into a log, and it is statically reviewable.
 *
 * `resolved` receives the awaited value, so selectors for async functions see
 * the unwrapped result (not the Promise).
 */
export type InstrumentationPayloadSelectors<Args extends unknown[], Result> = {
    resolved?: (result: Awaited<Result>) => SafePayload;
    started?: (args: Args) => SafePayload;
};
/**
 * General instrumentation event emitted by the logger bridge. Retains a
 * free-form (key-scrubbed) `parameters` bag because it forwards arbitrary
 * error diagnostics rather than a single function's call shape.
 */
export type InstrumentationEvent = InstrumentationContext & {
    parameters: Record<string, unknown>;
};
/**
 * A telemetry record emitted by instrumentFunction for each phase of a
 * function call (started, resolved, rejected). Carries only the safe envelope
 * plus an optional explicit {@link SafePayload} — never raw arguments or
 * return values.
 */
export type FunctionInstrumentationEvent = InstrumentationContext & {
    /** Wall-clock duration of the call. Present on resolved/rejected only. */
    durationMs?: number;
    /** Stable error code on the rejected phase, when the error extends BaseError. */
    errorCode?: string;
    /** Error subclass name on the rejected phase. Never the message or stack. */
    errorName?: string;
    functionName: string;
    payload?: SafePayload;
    phase: InstrumentationEventPhase;
};
/** Any event the transport may receive. */
export type AnyInstrumentationEvent = InstrumentationEvent | FunctionInstrumentationEvent;
export type InstrumentationConfig = {
    enabled: boolean;
    piiFields: string[];
};
/** Pluggable sink that receives events for forwarding. */
export type InstrumentationTransport = {
    log: (event: AnyInstrumentationEvent) => void;
};
/**
 * The instrumentation service instance held on DynamicCore.
 * Acts as a gatekeeper: events are only forwarded to the transport when
 * enabled, and the transport can be swapped at any time without restarting.
 */
export type Instrumentation = {
    config: InstrumentationConfig;
    log: (event: InstrumentationEvent) => void;
    logFunction: (event: FunctionInstrumentationEvent) => void;
    setEnabled: (enabled: boolean) => void;
    setTransport: (transport: InstrumentationTransport) => void;
};
//# sourceMappingURL=instrumentation.types.d.ts.map