{"version":3,"file":"semconvStability.cjs","names":[],"sources":["../src/semconvStability.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport enum SemconvStability {\n  /** Emit only stable semantic conventions. */\n  STABLE = 0x1,\n  /** Emit only old semantic conventions. */\n  OLD = 0x2,\n  /** Emit both stable and old semantic conventions. */\n  DUPLICATE = 0x1 | 0x2,\n}\n\n// Common namespaces mentioned in semantic-conventions docs, but allow\n// other custom strings.\ntype SemConvStabilityNamespace =\n  | 'http'\n  | 'messaging'\n  | 'database'\n  | 'k8s'\n  | (string & {});\n\n/**\n * Determine the appropriate semconv stability for the given namespace.\n *\n * This will parse the given string of comma-separated values (often\n * `process.env.OTEL_SEMCONV_STABILITY_OPT_IN`) looking for the `${namespace}`\n * or `${namespace}/dup` tokens. This is a pattern defined by a number of\n * non-normative semconv documents.\n *\n * For example:\n * - namespace 'http': https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/\n * - namespace 'database': https://opentelemetry.io/docs/specs/semconv/non-normative/database-migration/\n * - namespace 'k8s': https://opentelemetry.io/docs/specs/semconv/non-normative/k8s-migration/\n *\n * Usage:\n *\n *  import {SemconvStability, semconvStabilityFromStr} from '@opentelemetry/instrumentation';\n *\n *  export class FooInstrumentation extends InstrumentationBase<FooInstrumentationConfig> {\n *    private _semconvStability: SemconvStability;\n *    constructor(config: FooInstrumentationConfig = {}) {\n *      super('@opentelemetry/instrumentation-foo', VERSION, config);\n *\n *      // When supporting the OTEL_SEMCONV_STABILITY_OPT_IN envvar\n *      this._semconvStability = semconvStabilityFromStr(\n *        'http',\n *        process.env.OTEL_SEMCONV_STABILITY_OPT_IN\n *      );\n *\n *      // or when supporting a `semconvStabilityOptIn` config option (e.g. for\n *      // the web where there are no envvars).\n *      this._semconvStability = semconvStabilityFromStr(\n *        'http',\n *        config?.semconvStabilityOptIn\n *      );\n *    }\n *  }\n *\n *  // Then, to apply semconv, use the following or similar:\n *  if (this._semconvStability & SemconvStability.OLD) {\n *    // ...\n *  }\n *  if (this._semconvStability & SemconvStability.STABLE) {\n *    // ...\n *  }\n *\n */\nexport function semconvStabilityFromStr(\n  namespace: SemConvStabilityNamespace,\n  str: string | undefined\n) {\n  let semconvStability = SemconvStability.OLD;\n\n  // The same parsing of `str` as `getStringListFromEnv` from the core pkg.\n  const entries = str\n    ?.split(',')\n    .map(v => v.trim())\n    .filter(s => s !== '');\n  for (const entry of entries ?? []) {\n    if (entry.toLowerCase() === namespace + '/dup') {\n      // DUPLICATE takes highest precedence.\n      semconvStability = SemconvStability.DUPLICATE;\n      break;\n    } else if (entry.toLowerCase() === namespace) {\n      semconvStability = SemconvStability.STABLE;\n    }\n  }\n\n  return semconvStability;\n}\n"],"mappings":";AAKA,IAAY,mBAAL,yBAAA,kBAAA;;CAEL,iBAAA,iBAAA,YAAA,KAAA;;CAEA,iBAAA,iBAAA,SAAA,KAAA;;CAEA,iBAAA,iBAAA,eAAA,KAAA;;AACF,EAAA,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,SAAgB,wBACd,WACA,KACA;CACA,IAAI,mBAAA;CAGJ,MAAM,UAAU,KACZ,MAAM,GAAG,CAAC,CACX,KAAI,MAAK,EAAE,KAAK,CAAC,CAAC,CAClB,QAAO,MAAK,MAAM,EAAE;CACvB,KAAK,MAAM,SAAS,WAAW,CAAC,GAC9B,IAAI,MAAM,YAAY,MAAM,YAAY,QAAQ;EAE9C,mBAAA;EACA;CACF,OAAO,IAAI,MAAM,YAAY,MAAM,WACjC,mBAAA;CAIJ,OAAO;AACT"}