import { OtelTraceContext, UserAlias, UserProfile } from "@gala-chain/api"; import { Attributes, Span } from "@opentelemetry/api"; import { Context } from "fabric-contract-api"; import { ChaincodeStub } from "fabric-shim"; import { GalaChainStub } from "./GalaChainStub"; import { GalaLoggerInstance } from "./GalaLoggerInstance"; import { OperationContext } from "./OperationContext"; export interface GalaChainContextConfig { readonly adminPublicKey?: string; } /** * OTEL facade for a transaction context. * Export is async (BatchSpanProcessor); `send` / `end` never wait on OTLP. */ export declare class GalaChainOtel { private readonly ctx; constructor(ctx: GalaChainContext); /** DTO parent trace — log correlation and SERVER parenting. */ trace?: OtelTraceContext; private server?; private active?; /** SERVER span for this Fabric invoke (before → after). */ get current(): Span | undefined; /** * Stub-bound recording span, else SERVER. * Used when Fabric drops AsyncLocalStorage (getState). Never `gala.handle`. */ private get fallback(); /** Run `fn` with SERVER as the active OTEL ALS span. */ run(fn: () => Promise): Promise; /** Record an error on the SERVER span. */ recordError(err: unknown): void; /** * Record `fn` as an INTERNAL child span. * Parents to ALS when intact; otherwise to `fallback`. * Does not change the stub parent (`gala.handle` must not steal it). * Telemetry failures never propagate; errors from `fn` do. */ send(name: string, attributes: Attributes, fn: (span: Span | undefined) => Promise): Promise; /** * Like `send`, but parents to `fallback` (not ambient ALS) and binds the child * as stub parent for the duration of `fn`. Use at Fabric/tx boundaries and for * state helpers so nested I/O does not inherit an outer span (e.g. batch.operation). */ sendBound(name: string, attributes: Attributes, fn: (span: Span | undefined) => Promise): Promise; /** * Bind the stub fallback parent for Fabric I/O that drops ALS. * Omitting `span` (or passing undefined) binds SERVER. */ private setActive; private withActive; private bind; /** Start the SERVER span once. Safe to call again (no-op if `current` exists). */ start(name: string, dtoPlain: unknown, attributes: Attributes): void; /** End SERVER and drop span state. */ end(failed?: boolean): Promise; /** * Sandbox ctx: share caller trace and stub parent, not SERVER. * Nested decorated methods start their own SERVER via `start()`. */ attachFrom(parent: GalaChainOtel): void; } export declare class GalaChainContext extends Context { stub: GalaChainStub; private callingUserValue?; private callingUserEthAddressValue?; private callingUserRolesValue?; private callingUserSignedByValue?; private callingUserSignatureQuorumValue?; private callingUserAllowedSignersValue?; private isMultisigValue?; private operationCtxValue?; private txUnixTimeValue?; private loggerInstance?; isDryRun: boolean; config: GalaChainContextConfig; /** Tracing for this invoke. Use `otel.send` / `otel.run` / `otel.end`. */ readonly otel: GalaChainOtel; constructor(config: GalaChainContextConfig); get logger(): GalaLoggerInstance; get callingUser(): UserAlias; get callingUserAddress(): string; get callingUserRoles(): string[]; get callingUserSignedBy(): UserAlias[]; get callingUserSignatureQuorum(): number; get callingUserAllowedSigners(): UserAlias[]; get isMultisig(): boolean; get callingUserProfile(): UserProfile; set callingUserData(d: { alias?: UserAlias; ethAddress?: string; roles: string[]; signedBy: UserAlias[]; signatureQuorum: number; allowedSigners: UserAlias[]; isMultisig: boolean; }); resetCallingUser(): void; get operationCtx(): OperationContext; setDryRunOnBehalfOf(d: { alias: UserAlias; ethAddress?: string; roles: string[]; }): void; get txUnixTime(): number; /** * @returns a new, empty context that uses the same chaincode stub as * the current context, but with dry run set (disables writes and deletes). */ createReadOnlyContext(index: number | undefined): GalaChainContext; setChaincodeStub(stub: ChaincodeStub): void; } //# sourceMappingURL=GalaChainContext.d.ts.map