{"version":3,"file":"utils.cjs","names":[],"sources":["../../src/internal/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { AnyValue, Attributes } from '@opentelemetry/api';\nimport type { InstrumentationScope } from '@opentelemetry/core';\n\nexport type LogInstrumentationScope = InstrumentationScope & {\n  readonly attributes?: Attributes;\n  readonly droppedAttributesCount?: number;\n};\n\n/**\n * Normalizes an AnyValue to a JSON-serializable [typeTag, payload] tuple.\n *\n * Using a type tag as the first element guarantees that two values can only\n * produce the same tuple when they have the same type AND the same data,\n * avoiding cross-type collisions such as:\n *   - null vs NaN vs Infinity (all become JSON `null` via JSON.stringify)\n *   - -0 vs 0 (both become JSON `0` via JSON.stringify)\n *   - string \"null\" vs the value null\n *\n * Object keys are sorted so that attribute maps with the same entries but\n * different insertion orders produce the same key.\n */\nfunction normalizeAnyValue(value: AnyValue): [string, unknown] {\n  if (value === undefined) {\n    return ['u', null];\n  }\n  if (value === null) {\n    return ['n', null];\n  }\n\n  const valueType = typeof value;\n  if (valueType === 'string') {\n    return ['s', value];\n  }\n  if (valueType === 'boolean') {\n    return ['b', value];\n  }\n  if (valueType === 'number') {\n    if (Number.isNaN(value)) return ['nan', null];\n    if (value === Infinity) return ['inf', null];\n    if (value === -Infinity) return ['-inf', null];\n    if (Object.is(value, -0)) return ['n0', null];\n    return ['d', value];\n  }\n  if (value instanceof Uint8Array) {\n    return ['bytes', Array.from(value)];\n  }\n  if (Array.isArray(value)) {\n    return ['arr', value.map(normalizeAnyValue)];\n  }\n  // AnyValueMap — sort keys for insertion-order independence\n  return [\n    'map',\n    Object.entries(value)\n      .sort(([a], [b]) => a.localeCompare(b))\n      .map(([k, v]) => [k, normalizeAnyValue(v)]),\n  ];\n}\n\n/**\n * Converting the instrumentation scope object to a unique identifier string.\n * @param scope - The instrumentation scope to convert\n * @returns A unique string identifier for the scope\n */\nexport function getInstrumentationScopeKey(\n  scope: LogInstrumentationScope\n): string {\n  return JSON.stringify([\n    scope.name,\n    scope.version || '',\n    scope.schemaUrl || '',\n    normalizeAnyValue(scope.attributes ?? {}),\n    // we include the dropped attributes count to avoid collisions between scopes with the same identifying\n    // characteristics, but different dropped counts. While there still can be collisions this is the best we can do if\n    // we want to resolve the same logger without relying on object identity.\n    scope.droppedAttributesCount ?? 0,\n  ]);\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAS,kBAAkB,OAAoC;CAC7D,IAAI,UAAU,KAAA,GACZ,OAAO,CAAC,KAAK,IAAI;CAEnB,IAAI,UAAU,MACZ,OAAO,CAAC,KAAK,IAAI;CAGnB,MAAM,YAAY,OAAO;CACzB,IAAI,cAAc,UAChB,OAAO,CAAC,KAAK,KAAK;CAEpB,IAAI,cAAc,WAChB,OAAO,CAAC,KAAK,KAAK;CAEpB,IAAI,cAAc,UAAU;EAC1B,IAAI,OAAO,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,IAAI;EAC5C,IAAI,UAAU,UAAU,OAAO,CAAC,OAAO,IAAI;EAC3C,IAAI,UAAU,WAAW,OAAO,CAAC,QAAQ,IAAI;EAC7C,IAAI,OAAO,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,IAAI;EAC5C,OAAO,CAAC,KAAK,KAAK;CACpB;CACA,IAAI,iBAAiB,YACnB,OAAO,CAAC,SAAS,MAAM,KAAK,KAAK,CAAC;CAEpC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,CAAC,OAAO,MAAM,IAAI,iBAAiB,CAAC;CAG7C,OAAO,CACL,OACA,OAAO,QAAQ,KAAK,CAAC,CAClB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,CACtC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAC9C;AACF;;;;;;AAOA,SAAgB,2BACd,OACQ;CACR,OAAO,KAAK,UAAU;EACpB,MAAM;EACN,MAAM,WAAW;EACjB,MAAM,aAAa;EACnB,kBAAkB,MAAM,cAAc,CAAC,CAAC;EAIxC,MAAM,0BAA0B;CAClC,CAAC;AACH"}