{"version":3,"file":"inspect.cjs","names":[],"sources":["../src/inspect.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Attributes, AttributeValue } from '@opentelemetry/api';\nimport type { Resource } from '@opentelemetry/resources';\n\n/**\n * Well-known symbol used by Node.js `util.inspect` (and `console.*`) to\n * render an object via a custom representation. Defined as a global Symbol\n * so it works without importing from `node:util`, keeping this module safe\n * for browser builds (where the symbol is simply never looked up).\n */\nexport const inspectCustom = Symbol.for('nodejs.util.inspect.custom');\n\n/**\n * Collect a Resource's settled attributes without touching the\n * `attributes` getter, which emits diag.error/debug entries when async\n * attribute detectors are still pending. Promise-like (unsettled)\n * entries are silently skipped so logging a Span/Tracer/Provider during\n * startup doesn't recurse through the diag pipeline.\n */\nexport function settledResourceAttributes(resource: Resource): Attributes {\n  const attrs: Attributes = {};\n  for (const [k, v] of resource.getRawAttributes()) {\n    if (typeof (v as Partial<PromiseLike<unknown>>)?.then === 'function') {\n      continue;\n    }\n    if (v != null) {\n      attrs[k] ??= v as AttributeValue;\n    }\n  }\n  return attrs;\n}\n\nexport type InspectFn = (value: unknown, options: unknown) => string;\n\nexport interface InspectStylizeOptions {\n  depth?: number | null;\n  stylize?: (text: string, styleType: string) => string;\n}\n\n/**\n * Build a class-tagged inspect representation. Returns a stub like\n * `[ClassName]` once the recursion budget is exhausted, otherwise returns\n * `ClassName <inspected payload>` so nested fields keep proper coloring,\n * indentation, and depth handling. In environments that don't supply an\n * `inspect` callback (e.g. browsers), falls back to returning the raw\n * payload object.\n */\nexport function formatInspect(\n  className: string,\n  payload: object,\n  depth: number,\n  options: InspectStylizeOptions | undefined,\n  inspect: InspectFn | undefined\n): unknown {\n  if (typeof depth === 'number' && depth < 0) {\n    const tag = `[${className}]`;\n    return options?.stylize ? options.stylize(tag, 'special') : tag;\n  }\n  if (typeof inspect !== 'function' || !options) {\n    return payload;\n  }\n  const childOptions = {\n    ...options,\n    depth: options.depth == null ? options.depth : options.depth - 1,\n  };\n  return `${className} ${inspect(payload, childOptions)}`;\n}\n"],"mappings":";;;;;;;AAcA,MAAa,gBAAgB,OAAO,IAAI,4BAA4B;;;;;;;;AASpE,SAAgB,0BAA0B,UAAgC;CACxE,MAAM,QAAoB,CAAC;CAC3B,KAAK,MAAM,CAAC,GAAG,MAAM,SAAS,iBAAiB,GAAG;EAChD,IAAI,OAAQ,GAAqC,SAAS,YACxD;EAEF,IAAI,KAAK,MACP,MAAM,OAAO;CAEjB;CACA,OAAO;AACT;;;;;;;;;AAiBA,SAAgB,cACd,WACA,SACA,OACA,SACA,SACS;CACT,IAAI,OAAO,UAAU,YAAY,QAAQ,GAAG;EAC1C,MAAM,MAAM,IAAI,UAAU;EAC1B,OAAO,SAAS,UAAU,QAAQ,QAAQ,KAAK,SAAS,IAAI;CAC9D;CACA,IAAI,OAAO,YAAY,cAAc,CAAC,SACpC,OAAO;CAMT,OAAO,GAAG,UAAU,GAAG,QAAQ,SAAS;EAHtC,GAAG;EACH,OAAO,QAAQ,SAAS,OAAO,QAAQ,QAAQ,QAAQ,QAAQ;CAEd,CAAC;AACtD"}