{"version":3,"file":"InstrumentDescriptor.cjs","names":["ValueType","equalsCaseInsensitive"],"sources":["../src/InstrumentDescriptor.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { MetricAdvice, MetricOptions } from '@opentelemetry/api';\nimport { ValueType, diag } from '@opentelemetry/api';\nimport type { View } from './view/View';\nimport { equalsCaseInsensitive } from './utils';\nimport type { InstrumentType, MetricDescriptor } from './export/MetricData';\n\n/**\n * An internal interface describing the instrument.\n *\n * This is intentionally distinguished from the public MetricDescriptor (a.k.a. InstrumentDescriptor)\n * which may not contains internal fields like metric advice.\n */\nexport interface InstrumentDescriptor extends MetricDescriptor {\n  /**\n   * For internal use; exporter should avoid depending on the type of the\n   * instrument as their resulting aggregator can be re-mapped with views.\n   */\n  readonly type: InstrumentType;\n\n  /**\n   * See {@link MetricAdvice}\n   *\n   * @experimental\n   */\n  readonly advice: MetricAdvice;\n}\n\nexport function createInstrumentDescriptor(\n  name: string,\n  type: InstrumentType,\n  options?: MetricOptions\n): InstrumentDescriptor {\n  if (!isValidName(name)) {\n    diag.warn(\n      `Invalid metric name: \"${name}\". The metric name should be a ASCII string with a length no greater than 255 characters.`\n    );\n  }\n  return {\n    name,\n    type,\n    description: options?.description ?? '',\n    unit: options?.unit ?? '',\n    valueType: options?.valueType ?? ValueType.DOUBLE,\n    advice: options?.advice ?? {},\n  };\n}\n\nexport function createInstrumentDescriptorWithView(\n  view: View,\n  instrument: InstrumentDescriptor\n): InstrumentDescriptor {\n  return {\n    name: view.name ?? instrument.name,\n    description: view.description ?? instrument.description,\n    type: instrument.type,\n    unit: instrument.unit,\n    valueType: instrument.valueType,\n    advice: instrument.advice,\n  };\n}\n\nexport function isDescriptorCompatibleWith(\n  descriptor: InstrumentDescriptor,\n  otherDescriptor: InstrumentDescriptor\n) {\n  // Names are case-insensitive strings.\n  return (\n    equalsCaseInsensitive(descriptor.name, otherDescriptor.name) &&\n    descriptor.unit === otherDescriptor.unit &&\n    descriptor.type === otherDescriptor.type &&\n    descriptor.valueType === otherDescriptor.valueType\n  );\n}\n\n// ASCII string with a length no greater than 255 characters.\n// NB: the first character counted separately from the rest.\nconst NAME_REGEXP = /^[a-z][a-z0-9_.\\-/]{0,254}$/i;\nexport function isValidName(name: string): boolean {\n  return NAME_REGEXP.test(name);\n}\n"],"mappings":";;;AAgCA,SAAgB,2BACd,MACA,MACA,SACsB;CACtB,IAAI,CAAC,YAAY,IAAI,GACnB,mBAAA,KAAK,KACH,yBAAyB,KAAK,0FAChC;CAEF,OAAO;EACL;EACA;EACA,aAAa,SAAS,eAAe;EACrC,MAAM,SAAS,QAAQ;EACvB,WAAW,SAAS,aAAaA,mBAAAA,UAAU;EAC3C,QAAQ,SAAS,UAAU,CAAC;CAC9B;AACF;AAEA,SAAgB,mCACd,MACA,YACsB;CACtB,OAAO;EACL,MAAM,KAAK,QAAQ,WAAW;EAC9B,aAAa,KAAK,eAAe,WAAW;EAC5C,MAAM,WAAW;EACjB,MAAM,WAAW;EACjB,WAAW,WAAW;EACtB,QAAQ,WAAW;CACrB;AACF;AAEA,SAAgB,2BACd,YACA,iBACA;CAEA,OACEC,cAAAA,sBAAsB,WAAW,MAAM,gBAAgB,IAAI,KAC3D,WAAW,SAAS,gBAAgB,QACpC,WAAW,SAAS,gBAAgB,QACpC,WAAW,cAAc,gBAAgB;AAE7C;AAIA,MAAM,cAAc;AACpB,SAAgB,YAAY,MAAuB;CACjD,OAAO,YAAY,KAAK,IAAI;AAC9B"}