diff --git a/crates/observation-tools-client/index.d.ts b/crates/observation-tools-client/index.d.ts index fd67d89..15e6d89 100644 --- a/crates/observation-tools-client/index.d.ts +++ b/crates/observation-tools-client/index.d.ts @@ -2,34 +2,34 @@ /* eslint-disable */ /** Client for observation-tools */ export declare class Client { - beginExecution(name: string): ExecutionHandle; + beginExecution(name: string): ExecutionHandle /** * Begin a new execution with a specific ID (for testing) * * This allows tests to create an execution with a known ID, enabling * navigation to the execution URL before the execution is uploaded. */ - beginExecutionWithId(id: string, name: string): ExecutionHandle; + beginExecutionWithId(id: string, name: string): ExecutionHandle } /** Builder for Client */ export declare class ClientBuilder { /** Create a new client builder */ - constructor(); + constructor() /** Set the base URL for the server */ - setBaseUrl(url: string): void; + setBaseUrl(url: string): void /** Set the API key for authentication */ - setApiKey(apiKey: string): void; + setApiKey(apiKey: string): void /** Build the client */ - build(): Client; + build(): Client } /** Handle to an execution that can be used to send observations */ export declare class ExecutionHandle { /** Get the execution ID as a string */ - get idString(): string; + get idString(): string /** Get the URL to the execution page */ - get url(): string; + get url(): string } /** @@ -40,46 +40,59 @@ export declare class ExecutionHandle { * * Payload methods (`.serde()`, `.debug()`, `.payload()`) send the observation * immediately and return `SendObservation` for optional waiting. + * Named variants (`.named_serde()`, `.named_debug()`, `.named_payload()`) + * return `ObservationPayloadHandle` for adding additional payloads. */ export declare class ObservationBuilder { /** Create a new observation builder with the given name */ - constructor(name: string); + constructor(name: string) /** * Set a custom observation ID (for testing) * * This allows tests to create an observation with a known ID, enabling * navigation to the observation URL before the observation is uploaded. */ - withId(id: string): this; - /** Add a label to the observation */ - label(label: string): this; + withId(id: string): this + /** Add a group to the observation by group ID string */ + group(groupId: string): this /** Add metadata to the observation */ - metadata(key: string, value: string): this; + metadata(key: string, value: string): this /** Set the source info for the observation */ - source(file: string, line: number): this; - /** Set the payload as JSON data, returning a builder that can be sent with an execution */ - jsonPayload(jsonString: string): ObservationBuilderWithPayloadNapi; - /** Set the payload with custom data and MIME type, returning a builder that can be sent */ - rawPayload(data: string, mimeType: string): ObservationBuilderWithPayloadNapi; + source(file: string, line: number): this + /** + * Set the payload as JSON data, returning a builder that can be sent with an + * execution + */ + jsonPayload(jsonString: string): ObservationBuilderWithPayloadNapi + /** + * Set the payload with custom data and MIME type, returning a builder that + * can be sent + */ + rawPayload(data: string, mimeType: string): ObservationBuilderWithPayloadNapi /** Set the payload as markdown content, returning a builder that can be sent */ - markdownPayload(content: string): ObservationBuilderWithPayloadNapi; + markdownPayload(content: string): ObservationBuilderWithPayloadNapi + /** Set the payload as HTML content, returning a builder that can be sent */ + htmlPayload(content: string): ObservationBuilderWithPayloadNapi } -/** Intermediate NAPI type that holds a builder and payload, allowing `.send(exe)` pattern */ +/** + * Intermediate NAPI type that holds a builder and payload, allowing + * `.send(exe)` pattern + */ export declare class ObservationBuilderWithPayloadNapi { /** Send the observation using the provided execution handle */ - send(execution: ExecutionHandle): SendObservation; + send(execution: ExecutionHandle): SendObservation } export declare class ObservationHandle { - get url(): string; - get id(): string; + get url(): string + get id(): string } export declare class SendObservation { - handle(): ObservationHandle; + handle(): ObservationHandle /** Wait for the observation to be uploaded to the server */ - waitForUpload(): Promise; + waitForUpload(): Promise } /** @@ -88,7 +101,7 @@ export declare class SendObservation { * This allows tests to generate an execution ID before creating the execution, * enabling navigation to the execution URL before the execution is uploaded. */ -export declare function generateExecutionId(): string; +export declare function generateExecutionId(): string /** * Generate a new observation ID (for testing) @@ -97,4 +110,4 @@ export declare function generateExecutionId(): string; * observation, enabling navigation to the observation URL before the * observation is uploaded. */ -export declare function generateObservationId(): string; +export declare function generateObservationId(): string diff --git a/crates/observation-tools-client/index.js b/crates/observation-tools-client/index.js index 403fc3e..2be828a 100644 --- a/crates/observation-tools-client/index.js +++ b/crates/observation-tools-client/index.js @@ -4,746 +4,557 @@ /* auto-generated by NAPI-RS */ const { readFileSync } = require('node:fs') -let nativeBinding = null; -const loadErrors = []; +let nativeBinding = null +const loadErrors = [] const isMusl = () => { - let musl = false; - if (process.platform === "linux") { - musl = isMuslFromFilesystem(); + let musl = false + if (process.platform === 'linux') { + musl = isMuslFromFilesystem() if (musl === null) { - musl = isMuslFromReport(); + musl = isMuslFromReport() } if (musl === null) { - musl = isMuslFromChildProcess(); + musl = isMuslFromChildProcess() } } - return musl; -}; + return musl +} -const isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-"); +const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-') const isMuslFromFilesystem = () => { try { - return readFileSync("/usr/bin/ldd", "utf-8").includes("musl"); + return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl') } catch { - return null; + return null } -}; +} const isMuslFromReport = () => { - let report = null; - if (typeof process.report?.getReport === "function") { - process.report.excludeNetwork = true; - report = process.report.getReport(); + let report = null + if (typeof process.report?.getReport === 'function') { + process.report.excludeNetwork = true + report = process.report.getReport() } if (!report) { - return null; + return null } if (report.header && report.header.glibcVersionRuntime) { - return false; + return false } if (Array.isArray(report.sharedObjects)) { if (report.sharedObjects.some(isFileMusl)) { - return true; + return true } } - return false; -}; + return false +} const isMuslFromChildProcess = () => { try { - return require("child_process") - .execSync("ldd --version", { encoding: "utf8" }) - .includes("musl"); + return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl') } catch (e) { // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false - return false; + return false } -}; +} function requireNative() { if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) { try { return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH); } catch (err) { - loadErrors.push(err); + loadErrors.push(err) } - } else if (process.platform === "android") { - if (process.arch === "arm64") { + } else if (process.platform === 'android') { + if (process.arch === 'arm64') { try { - return require("./observation-tools-client.android-arm64.node"); + return require('./observation-tools-client.android-arm64.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-android-arm64"); - const bindingPackageVersion = - require("@observation-tools/client-android-arm64/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-android-arm64') + const bindingPackageVersion = require('@observation-tools/client-android-arm64/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } - } else if (process.arch === "arm") { + } else if (process.arch === 'arm') { try { - return require("./observation-tools-client.android-arm-eabi.node"); + return require('./observation-tools-client.android-arm-eabi.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-android-arm-eabi"); - const bindingPackageVersion = - require("@observation-tools/client-android-arm-eabi/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-android-arm-eabi') + const bindingPackageVersion = require('@observation-tools/client-android-arm-eabi/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { - loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`)); + loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`)) } - } else if (process.platform === "win32") { - if (process.arch === "x64") { - if ( - process.config?.variables?.shlib_suffix === "dll.a" || - process.config?.variables?.node_target_type === "shared_library" - ) { + } else if (process.platform === 'win32') { + if (process.arch === 'x64') { + if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') { try { - return require("./observation-tools-client.win32-x64-gnu.node"); - } catch (e) { - loadErrors.push(e); - } - try { - const binding = require("@observation-tools/client-win32-x64-gnu"); - const bindingPackageVersion = - require("@observation-tools/client-win32-x64-gnu/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; - } catch (e) { - loadErrors.push(e); + return require('./observation-tools-client.win32-x64-gnu.node') + } catch (e) { + loadErrors.push(e) + } + try { + const binding = require('@observation-tools/client-win32-x64-gnu') + const bindingPackageVersion = require('@observation-tools/client-win32-x64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } + return binding + } catch (e) { + loadErrors.push(e) + } } else { try { - return require("./observation-tools-client.win32-x64-msvc.node"); - } catch (e) { - loadErrors.push(e); - } - try { - const binding = require("@observation-tools/client-win32-x64-msvc"); - const bindingPackageVersion = - require("@observation-tools/client-win32-x64-msvc/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; - } catch (e) { - loadErrors.push(e); + return require('./observation-tools-client.win32-x64-msvc.node') + } catch (e) { + loadErrors.push(e) + } + try { + const binding = require('@observation-tools/client-win32-x64-msvc') + const bindingPackageVersion = require('@observation-tools/client-win32-x64-msvc/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } + return binding + } catch (e) { + loadErrors.push(e) + } } - } else if (process.arch === "ia32") { + } else if (process.arch === 'ia32') { try { - return require("./observation-tools-client.win32-ia32-msvc.node"); + return require('./observation-tools-client.win32-ia32-msvc.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-win32-ia32-msvc"); - const bindingPackageVersion = - require("@observation-tools/client-win32-ia32-msvc/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-win32-ia32-msvc') + const bindingPackageVersion = require('@observation-tools/client-win32-ia32-msvc/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } - } else if (process.arch === "arm64") { + } else if (process.arch === 'arm64') { try { - return require("./observation-tools-client.win32-arm64-msvc.node"); + return require('./observation-tools-client.win32-arm64-msvc.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-win32-arm64-msvc"); - const bindingPackageVersion = - require("@observation-tools/client-win32-arm64-msvc/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-win32-arm64-msvc') + const bindingPackageVersion = require('@observation-tools/client-win32-arm64-msvc/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { - loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`)); + loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`)) } - } else if (process.platform === "darwin") { + } else if (process.platform === 'darwin') { try { - return require("./observation-tools-client.darwin-universal.node"); + return require('./observation-tools-client.darwin-universal.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-darwin-universal"); - const bindingPackageVersion = - require("@observation-tools/client-darwin-universal/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-darwin-universal') + const bindingPackageVersion = require('@observation-tools/client-darwin-universal/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } - if (process.arch === "x64") { + if (process.arch === 'x64') { try { - return require("./observation-tools-client.darwin-x64.node"); + return require('./observation-tools-client.darwin-x64.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-darwin-x64"); - const bindingPackageVersion = - require("@observation-tools/client-darwin-x64/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-darwin-x64') + const bindingPackageVersion = require('@observation-tools/client-darwin-x64/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } - } else if (process.arch === "arm64") { + } else if (process.arch === 'arm64') { try { - return require("./observation-tools-client.darwin-arm64.node"); + return require('./observation-tools-client.darwin-arm64.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-darwin-arm64"); - const bindingPackageVersion = - require("@observation-tools/client-darwin-arm64/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-darwin-arm64') + const bindingPackageVersion = require('@observation-tools/client-darwin-arm64/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { - loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`)); + loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`)) } - } else if (process.platform === "freebsd") { - if (process.arch === "x64") { + } else if (process.platform === 'freebsd') { + if (process.arch === 'x64') { try { - return require("./observation-tools-client.freebsd-x64.node"); + return require('./observation-tools-client.freebsd-x64.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-freebsd-x64"); - const bindingPackageVersion = - require("@observation-tools/client-freebsd-x64/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-freebsd-x64') + const bindingPackageVersion = require('@observation-tools/client-freebsd-x64/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } - } else if (process.arch === "arm64") { + } else if (process.arch === 'arm64') { try { - return require("./observation-tools-client.freebsd-arm64.node"); + return require('./observation-tools-client.freebsd-arm64.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-freebsd-arm64"); - const bindingPackageVersion = - require("@observation-tools/client-freebsd-arm64/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-freebsd-arm64') + const bindingPackageVersion = require('@observation-tools/client-freebsd-arm64/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { - loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`)); + loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`)) } - } else if (process.platform === "linux") { - if (process.arch === "x64") { + } else if (process.platform === 'linux') { + if (process.arch === 'x64') { if (isMusl()) { try { - return require("./observation-tools-client.linux-x64-musl.node"); + return require('./observation-tools-client.linux-x64-musl.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-x64-musl"); - const bindingPackageVersion = - require("@observation-tools/client-linux-x64-musl/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-x64-musl') + const bindingPackageVersion = require('@observation-tools/client-linux-x64-musl/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { try { - return require("./observation-tools-client.linux-x64-gnu.node"); + return require('./observation-tools-client.linux-x64-gnu.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-x64-gnu"); - const bindingPackageVersion = - require("@observation-tools/client-linux-x64-gnu/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-x64-gnu') + const bindingPackageVersion = require('@observation-tools/client-linux-x64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } - } else if (process.arch === "arm64") { + } else if (process.arch === 'arm64') { if (isMusl()) { try { - return require("./observation-tools-client.linux-arm64-musl.node"); + return require('./observation-tools-client.linux-arm64-musl.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-arm64-musl"); - const bindingPackageVersion = - require("@observation-tools/client-linux-arm64-musl/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-arm64-musl') + const bindingPackageVersion = require('@observation-tools/client-linux-arm64-musl/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { try { - return require("./observation-tools-client.linux-arm64-gnu.node"); + return require('./observation-tools-client.linux-arm64-gnu.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-arm64-gnu"); - const bindingPackageVersion = - require("@observation-tools/client-linux-arm64-gnu/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-arm64-gnu') + const bindingPackageVersion = require('@observation-tools/client-linux-arm64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } - } else if (process.arch === "arm") { + } else if (process.arch === 'arm') { if (isMusl()) { try { - return require("./observation-tools-client.linux-arm-musleabihf.node"); + return require('./observation-tools-client.linux-arm-musleabihf.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-arm-musleabihf"); - const bindingPackageVersion = - require("@observation-tools/client-linux-arm-musleabihf/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-arm-musleabihf') + const bindingPackageVersion = require('@observation-tools/client-linux-arm-musleabihf/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { try { - return require("./observation-tools-client.linux-arm-gnueabihf.node"); + return require('./observation-tools-client.linux-arm-gnueabihf.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-arm-gnueabihf"); - const bindingPackageVersion = - require("@observation-tools/client-linux-arm-gnueabihf/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-arm-gnueabihf') + const bindingPackageVersion = require('@observation-tools/client-linux-arm-gnueabihf/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } - } else if (process.arch === "loong64") { + } else if (process.arch === 'loong64') { if (isMusl()) { try { - return require("./observation-tools-client.linux-loong64-musl.node"); + return require('./observation-tools-client.linux-loong64-musl.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-loong64-musl"); - const bindingPackageVersion = - require("@observation-tools/client-linux-loong64-musl/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-loong64-musl') + const bindingPackageVersion = require('@observation-tools/client-linux-loong64-musl/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { try { - return require("./observation-tools-client.linux-loong64-gnu.node"); + return require('./observation-tools-client.linux-loong64-gnu.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-loong64-gnu"); - const bindingPackageVersion = - require("@observation-tools/client-linux-loong64-gnu/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-loong64-gnu') + const bindingPackageVersion = require('@observation-tools/client-linux-loong64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } - } else if (process.arch === "riscv64") { + } else if (process.arch === 'riscv64') { if (isMusl()) { try { - return require("./observation-tools-client.linux-riscv64-musl.node"); + return require('./observation-tools-client.linux-riscv64-musl.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-riscv64-musl"); - const bindingPackageVersion = - require("@observation-tools/client-linux-riscv64-musl/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-riscv64-musl') + const bindingPackageVersion = require('@observation-tools/client-linux-riscv64-musl/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { try { - return require("./observation-tools-client.linux-riscv64-gnu.node"); + return require('./observation-tools-client.linux-riscv64-gnu.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-riscv64-gnu"); - const bindingPackageVersion = - require("@observation-tools/client-linux-riscv64-gnu/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); + const binding = require('@observation-tools/client-linux-riscv64-gnu') + const bindingPackageVersion = require('@observation-tools/client-linux-riscv64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) } - return binding; + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } - } else if (process.arch === "ppc64") { + } else if (process.arch === 'ppc64') { try { - return require("./observation-tools-client.linux-ppc64-gnu.node"); + return require('./observation-tools-client.linux-ppc64-gnu.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-ppc64-gnu"); - const bindingPackageVersion = - require("@observation-tools/client-linux-ppc64-gnu/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-linux-ppc64-gnu') + const bindingPackageVersion = require('@observation-tools/client-linux-ppc64-gnu/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } - } else if (process.arch === "s390x") { + } else if (process.arch === 's390x') { try { - return require("./observation-tools-client.linux-s390x-gnu.node"); + return require('./observation-tools-client.linux-s390x-gnu.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-linux-s390x-gnu"); - const bindingPackageVersion = - require("@observation-tools/client-linux-s390x-gnu/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-linux-s390x-gnu') + const bindingPackageVersion = require('@observation-tools/client-linux-s390x-gnu/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { - loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`)); + loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`)) } - } else if (process.platform === "openharmony") { - if (process.arch === "arm64") { + } else if (process.platform === 'openharmony') { + if (process.arch === 'arm64') { try { - return require("./observation-tools-client.openharmony-arm64.node"); + return require('./observation-tools-client.openharmony-arm64.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-openharmony-arm64"); - const bindingPackageVersion = - require("@observation-tools/client-openharmony-arm64/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-openharmony-arm64') + const bindingPackageVersion = require('@observation-tools/client-openharmony-arm64/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } - } else if (process.arch === "x64") { + } else if (process.arch === 'x64') { try { - return require("./observation-tools-client.openharmony-x64.node"); + return require('./observation-tools-client.openharmony-x64.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-openharmony-x64"); - const bindingPackageVersion = - require("@observation-tools/client-openharmony-x64/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-openharmony-x64') + const bindingPackageVersion = require('@observation-tools/client-openharmony-x64/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } - } else if (process.arch === "arm") { + } else if (process.arch === 'arm') { try { - return require("./observation-tools-client.openharmony-arm.node"); + return require('./observation-tools-client.openharmony-arm.node') } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } try { - const binding = require("@observation-tools/client-openharmony-arm"); - const bindingPackageVersion = - require("@observation-tools/client-openharmony-arm/package.json").version; - if ( - bindingPackageVersion !== "0.0.13" && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK && - process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0" - ) { - throw new Error( - `Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`, - ); - } - return binding; + const binding = require('@observation-tools/client-openharmony-arm') + const bindingPackageVersion = require('@observation-tools/client-openharmony-arm/package.json').version + if (bindingPackageVersion !== '0.0.13' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { + throw new Error(`Native binding package version mismatch, expected 0.0.13 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) + } + return binding } catch (e) { - loadErrors.push(e); + loadErrors.push(e) } } else { - loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`)); + loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`)) } } else { - loadErrors.push( - new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`), - ); + loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`)) } } -nativeBinding = requireNative(); +nativeBinding = requireNative() if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { - let wasiBinding = null; - let wasiBindingError = null; + let wasiBinding = null + let wasiBindingError = null try { - wasiBinding = require("./observation-tools-client.wasi.cjs"); - nativeBinding = wasiBinding; + wasiBinding = require('./observation-tools-client.wasi.cjs') + nativeBinding = wasiBinding } catch (err) { if (process.env.NAPI_RS_FORCE_WASI) { - wasiBindingError = err; + wasiBindingError = err } } if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { try { - wasiBinding = require("@observation-tools/client-wasm32-wasi"); - nativeBinding = wasiBinding; + wasiBinding = require('@observation-tools/client-wasm32-wasi') + nativeBinding = wasiBinding } catch (err) { if (process.env.NAPI_RS_FORCE_WASI) { if (!wasiBindingError) { - wasiBindingError = err; + wasiBindingError = err } else { - wasiBindingError.cause = err; + wasiBindingError.cause = err } - loadErrors.push(err); + loadErrors.push(err) } } } - if (process.env.NAPI_RS_FORCE_WASI === "error" && !wasiBinding) { - const error = new Error("WASI binding not found and NAPI_RS_FORCE_WASI is set to error"); - error.cause = wasiBindingError; - throw error; + if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) { + const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error') + error.cause = wasiBindingError + throw error } } @@ -752,25 +563,25 @@ if (!nativeBinding) { throw new Error( `Cannot find native binding. ` + `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` + - "Please try `npm i` again after removing both package-lock.json and node_modules directory.", + 'Please try `npm i` again after removing both package-lock.json and node_modules directory.', { cause: loadErrors.reduce((err, cur) => { - cur.cause = err; - return cur; + cur.cause = err + return cur }), }, - ); + ) } - throw new Error(`Failed to load native binding`); + throw new Error(`Failed to load native binding`) } -module.exports = nativeBinding; -module.exports.Client = nativeBinding.Client; -module.exports.ClientBuilder = nativeBinding.ClientBuilder; -module.exports.ExecutionHandle = nativeBinding.ExecutionHandle; -module.exports.ObservationBuilder = nativeBinding.ObservationBuilder; -module.exports.ObservationBuilderWithPayloadNapi = nativeBinding.ObservationBuilderWithPayloadNapi; -module.exports.ObservationHandle = nativeBinding.ObservationHandle; -module.exports.SendObservation = nativeBinding.SendObservation; -module.exports.generateExecutionId = nativeBinding.generateExecutionId; -module.exports.generateObservationId = nativeBinding.generateObservationId; +module.exports = nativeBinding +module.exports.Client = nativeBinding.Client +module.exports.ClientBuilder = nativeBinding.ClientBuilder +module.exports.ExecutionHandle = nativeBinding.ExecutionHandle +module.exports.ObservationBuilder = nativeBinding.ObservationBuilder +module.exports.ObservationBuilderWithPayloadNapi = nativeBinding.ObservationBuilderWithPayloadNapi +module.exports.ObservationHandle = nativeBinding.ObservationHandle +module.exports.SendObservation = nativeBinding.SendObservation +module.exports.generateExecutionId = nativeBinding.generateExecutionId +module.exports.generateObservationId = nativeBinding.generateObservationId diff --git a/crates/observation-tools-client/src/group.rs b/crates/observation-tools-client/src/group.rs index 1c9539f..2e535be 100644 --- a/crates/observation-tools-client/src/group.rs +++ b/crates/observation-tools-client/src/group.rs @@ -7,9 +7,11 @@ use crate::observation::ObservationBuilder; use crate::observation_handle::SendObservation; use crate::Error; use observation_tools_shared::GroupId; +use observation_tools_shared::LogLevel; use observation_tools_shared::ObservationId; use observation_tools_shared::ObservationType; use observation_tools_shared::Payload; +use observation_tools_shared::SourceInfo; use std::collections::HashMap; /// Builder for creating groups @@ -21,6 +23,8 @@ pub struct GroupBuilder { custom_id: Option, parent_group_id: Option, metadata: HashMap, + source: Option, + log_level: Option, } impl GroupBuilder { @@ -31,6 +35,8 @@ impl GroupBuilder { custom_id: None, parent_group_id: None, metadata: HashMap::new(), + source: None, + log_level: None, } } @@ -52,6 +58,37 @@ impl GroupBuilder { self } + /// Set the source location for the group + pub fn source(mut self, file: impl Into, line: u32) -> Self { + self.source = Some(SourceInfo { + file: file.into(), + line, + column: None, + }); + self + } + + /// Set the log level for the group + pub(crate) fn log_level(mut self, level: LogLevel) -> Self { + self.log_level = Some(level); + self + } + + /// Create a GroupBuilder pre-configured for a tracing span + pub fn from_span( + name: impl Into, + log_level: LogLevel, + parent_group_id: Option, + ) -> Self { + let mut builder = Self::new(name).log_level(log_level); + + if let Some(parent_id) = parent_group_id { + builder = builder.parent(parent_id); + } + + builder + } + /// Build and send the group using the current execution context pub fn build(self) -> SendGroup { match context::get_current_execution() { @@ -88,7 +125,13 @@ impl GroupBuilder { let mut builder = ObservationBuilder::new(self.name) .with_id(observation_id) .observation_type(ObservationType::Group) - .execution(execution); + .log_level(self.log_level.unwrap_or(LogLevel::Info)) + .execution(execution) + .group(&group_handle); + + if let Some(source) = self.source { + builder = builder.source(source.file, source.line); + } if let Some(parent_id) = self.parent_group_id { builder = builder.parent_group(parent_id); diff --git a/crates/observation-tools-client/src/tracing/layer.rs b/crates/observation-tools-client/src/tracing/layer.rs index 55fa883..9a9dabb 100644 --- a/crates/observation-tools-client/src/tracing/layer.rs +++ b/crates/observation-tools-client/src/tracing/layer.rs @@ -1,5 +1,6 @@ use super::span_data::SpanData; use crate::context; +use crate::group::GroupBuilder; use crate::group::GroupHandle; use crate::observation::ObservationBuilder; use observation_tools_shared::GroupId; @@ -86,41 +87,36 @@ where return; }; - // Calculate duration - let duration = data.created_at.elapsed(); - let duration_ms = duration.as_secs_f64() * 1000.0; - - // Get the span's own ID and parent span ID - let span_id = id.into_u64(); - let parent_span_id = span - .parent() - .map(|parent| parent.id().into_u64().to_string()); - - // Create a group handle from the span ID - let group_handle = GroupHandle::from_id(GroupId::from(span_id.to_string()), &execution); + let builder = GroupBuilder::from_span( + &data.name, + tracing_level_to_log_level(data.level), + span + .parent() + .map(|parent| GroupId::from(parent.id().into_u64().to_string())), + ) + .id(id.into_u64().to_string()) + .metadata("target", &data.target); - // Build and send observation - let builder = ObservationBuilder::new(&data.name) - .observation_type(ObservationType::Span) - .log_level(tracing_level_to_log_level(data.level)) - .group(&group_handle) - .metadata("span_id", &span_id.to_string()) - .metadata("duration_ms", format!("{:.3}", duration_ms)) - .metadata("target", &data.target); - - let builder = if let (Some(file), Some(line)) = (data.file, data.line) { - builder.source(file, line) - } else { - builder - }; + let duration = data.created_at.elapsed(); + let mut builder = builder + .metadata("duration_s", duration.as_secs().to_string()) + .metadata("duration_ns", duration.subsec_nanos().to_string()); + + if let serde_json::Value::Object(fields) = &data.fields { + for (key, value) in fields { + let value_str = match value { + serde_json::Value::String(s) => s.clone(), + other => other.to_string(), + }; + builder = builder.metadata(key, value_str); + } + } - let builder = if let Some(parent_id) = parent_span_id { - builder.parent_span_id(parent_id) - } else { - builder - }; + if let (Some(file), Some(line)) = (data.file, data.line) { + builder = builder.source(file, line); + } - let _ = builder.serde(&data.fields); + let _ = builder.build_with_execution(&execution); } fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) { diff --git a/crates/observation-tools-client/tests/tracing_layer_test.rs b/crates/observation-tools-client/tests/tracing_layer_test.rs index fd46850..46f41ae 100644 --- a/crates/observation-tools-client/tests/tracing_layer_test.rs +++ b/crates/observation-tools-client/tests/tracing_layer_test.rs @@ -27,8 +27,12 @@ async fn test_span_captured_on_close() -> anyhow::Result<()> { let obs = &observations[0]; assert_eq!(obs.name.as_str(), "test_span"); assert!( - obs.metadata.contains_key("duration_ms"), - "Expected duration_ms metadata" + obs.metadata.contains_key("duration_s"), + "Expected duration_s metadata" + ); + assert!( + obs.metadata.contains_key("duration_ns"), + "Expected duration_ns metadata" ); Ok(()) @@ -130,33 +134,27 @@ async fn test_parent_span_attribution() -> anyhow::Result<()> { .find(|o| o.name == "outer") .expect("Expected outer span"); - // Get span IDs from metadata - let outer_span_id = outer - .metadata - .get("span_id") - .expect("Outer span should have span_id metadata"); - let inner_span_id = inner - .metadata - .get("span_id") - .expect("Inner span should have span_id metadata"); - // outer should have no parent (it's the root span) assert!( - outer.parent_span_id.is_none(), + outer.parent_group_id.is_none(), "Outer span should not have a parent" ); - // inner's parent_span_id should match outer's span_id + // inner's parent_group_id should reference outer's group ID + let inner_parent = inner + .parent_group_id + .as_ref() + .expect("Inner span should have a parent group"); assert_eq!( - inner.parent_span_id.as_ref(), - Some(outer_span_id), + inner_parent, + &outer.group_ids[0], "Inner span's parent should be outer span" ); - // The event's parent_span_id should match inner's span_id + // The event's parent_span_id should reference inner's group ID assert_eq!( - event.parent_span_id.as_ref(), - Some(inner_span_id), + event.parent_span_id.as_deref(), + Some(inner.group_ids[0].as_str()), "Event's parent should be inner span" ); @@ -194,18 +192,12 @@ async fn test_observe_macro_gets_parent_span() -> anyhow::Result<()> { .find(|o| o.name == "parent_span") .expect("Expected parent_span observation"); - assert_eq!(span_obs.observation_type, ObservationType::Span); - - // Get the span's tracing ID from metadata - let span_id = span_obs - .metadata - .get("span_id") - .expect("parent_span should have span_id metadata"); + assert_eq!(span_obs.observation_type, ObservationType::Group); - // The observe!() observation's parent_span_id should match the span's span_id + // The observe!() observation's parent_span_id should match the span's group ID assert_eq!( - my_obs.parent_span_id.as_ref(), - Some(span_id), + my_obs.parent_span_id.as_deref(), + Some(span_obs.group_ids[0].as_str()), "observe!() should have parent_span as its parent" ); @@ -274,12 +266,11 @@ async fn test_span_with_multiple_fields() -> anyhow::Result<()> { let observations = server.list_observations(&execution.id()).await?; let obs = server.get_observation(&execution.id(), &observations[0].id).await?; - assert_eq!(obs.observation_type, ObservationType::Span); - let fields = obs.payload().as_json().expect("Expected JSON payload"); - assert_eq!(fields["request_id"], 42); - assert_eq!(fields["user"], "alice"); - assert_eq!(fields["enabled"], true); - assert_eq!(fields["latency"], 1.5); + assert_eq!(obs.observation_type, ObservationType::Group); + assert_eq!(obs.metadata.get("request_id"), Some(&"42".to_string())); + assert_eq!(obs.metadata.get("user"), Some(&"alice".to_string())); + assert_eq!(obs.metadata.get("enabled"), Some(&"true".to_string())); + assert_eq!(obs.metadata.get("latency"), Some(&"1.5".to_string())); Ok(()) }