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,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACtB,OAAO,gCAAgC,CAAC,GAAG,CAAC,CAAC;KAC9C;IAED,OAAO,8BAA8B,CAAC,GAAG,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,gCAAgC,CAAC,GAAc;;IACtD,IAAI,IAAwB,CAAC;;QAE7B,KAAsB,IAAA,QAAA,SAAA,GAAG,CAAA,wBAAA,yCAAE;YAAtB,IAAM,OAAO,gBAAA;YAChB,sCAAsC;YACtC,IAAI,OAAO,IAAI,IAAI;gBAAE,SAAS;YAE9B,IAAI,CAAC,IAAI,EAAE;gBACT,IAAI,8BAA8B,CAAC,OAAO,CAAC,EAAE;oBAC3C,IAAI,GAAG,OAAO,OAAO,CAAC;oBACtB,SAAS;iBACV;gBACD,mCAAmC;gBACnC,OAAO,KAAK,CAAC;aACd;YAED,IAAI,OAAO,OAAO,KAAK,IAAI,EAAE;gBAC3B,SAAS;aACV;YAED,OAAO,KAAK,CAAC;SACd;;;;;;;;;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,8BAA8B,CAAC,GAAY;IAClD,QAAQ,OAAO,GAAG,EAAE;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,IAAI,CAAC;KACf;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { diag, SpanAttributeValue, SpanAttributes } from '@opentelemetry/api';\n\nexport function sanitizeAttributes(attributes: unknown): SpanAttributes {\n const out: SpanAttributes = {};\n\n if (typeof attributes !== 'object' || attributes == null) {\n return out;\n }\n\n for (const [key, val] of Object.entries(attributes)) {\n if (!isAttributeKey(key)) {\n diag.warn(`Invalid attribute key: ${key}`);\n continue;\n }\n if (!isAttributeValue(val)) {\n diag.warn(`Invalid attribute value set for key: ${key}`);\n continue;\n }\n if (Array.isArray(val)) {\n out[key] = val.slice();\n } else {\n out[key] = val;\n }\n }\n\n return out;\n}\n\nexport function isAttributeKey(key: unknown): key is string {\n return typeof key === 'string' && key.length > 0;\n}\n\nexport function isAttributeValue(val: unknown): val is SpanAttributeValue {\n if (val == null) {\n return true;\n }\n\n if (Array.isArray(val)) {\n return isHomogeneousAttributeValueArray(val);\n }\n\n return isValidPrimitiveAttributeValue(val);\n}\n\nfunction isHomogeneousAttributeValueArray(arr: unknown[]): boolean {\n let type: string | undefined;\n\n for (const element of arr) {\n // null/undefined elements are allowed\n if (element == null) continue;\n\n if (!type) {\n if (isValidPrimitiveAttributeValue(element)) {\n type = typeof element;\n continue;\n }\n // encountered an invalid primitive\n return false;\n }\n\n if (typeof element === type) {\n continue;\n }\n\n return false;\n }\n\n return true;\n}\n\nfunction isValidPrimitiveAttributeValue(val: unknown): boolean {\n switch (typeof val) {\n case 'number':\n case 'boolean':\n case 'string':\n return true;\n }\n\n return false;\n}\n"]}