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mB,QAAA,EAAE,oBAAoB,QAAA;YACjD,+CACK,KAAI,CAAC,eAAe,GACpB,mBAAmB,GAEnB,CAAC,MAAC,KAAkB,CAAC,eAAe,mCAAI,KAAK,CAAC,UAAU,CAAC,GACzD,oBAAoB,EACvB;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,QAAQ,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,CAAC;IACrE,CAAC;IAzHe,cAAK,GAAG,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAC;IA0H3C,eAAC;CAAA,AA3HD,IA2HC;SA3HY,QAAQ","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 } from '@opentelemetry/api';\nimport {\n SEMRESATTRS_SERVICE_NAME,\n SEMRESATTRS_TELEMETRY_SDK_LANGUAGE,\n SEMRESATTRS_TELEMETRY_SDK_NAME,\n SEMRESATTRS_TELEMETRY_SDK_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport { SDK_INFO } from '@opentelemetry/core';\nimport { ResourceAttributes } from './types';\nimport { defaultServiceName } from './platform';\nimport { IResource } from './IResource';\n\n/**\n * A Resource describes the entity for which a signals (metrics or trace) are\n * collected.\n */\nexport class Resource implements IResource {\n static readonly EMPTY = new Resource({});\n private _syncAttributes?: ResourceAttributes;\n private _asyncAttributesPromise?: Promise;\n private _attributes?: ResourceAttributes;\n\n /**\n * Check if async attributes have resolved. This is useful to avoid awaiting\n * waitForAsyncAttributes (which will introduce asynchronous behavior) when not necessary.\n *\n * @returns true if the resource \"attributes\" property is not yet settled to its final value\n */\n public asyncAttributesPending?: boolean;\n\n /**\n * Returns an empty Resource\n */\n static empty(): IResource {\n return Resource.EMPTY;\n }\n\n /**\n * Returns a Resource that identifies the SDK in use.\n */\n static default(): IResource {\n return new Resource({\n [SEMRESATTRS_SERVICE_NAME]: defaultServiceName(),\n [SEMRESATTRS_TELEMETRY_SDK_LANGUAGE]:\n SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_LANGUAGE],\n [SEMRESATTRS_TELEMETRY_SDK_NAME]:\n SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_NAME],\n [SEMRESATTRS_TELEMETRY_SDK_VERSION]:\n SDK_INFO[SEMRESATTRS_TELEMETRY_SDK_VERSION],\n });\n }\n\n constructor(\n /**\n * A dictionary of attributes with string keys and values that provide\n * information about the entity as numbers, strings or booleans\n * TODO: Consider to add check/validation on attributes.\n */\n attributes: ResourceAttributes,\n asyncAttributesPromise?: Promise\n ) {\n this._attributes = attributes;\n this.asyncAttributesPending = asyncAttributesPromise != null;\n this._syncAttributes = this._attributes ?? {};\n this._asyncAttributesPromise = asyncAttributesPromise?.then(\n asyncAttributes => {\n this._attributes = Object.assign({}, this._attributes, asyncAttributes);\n this.asyncAttributesPending = false;\n return asyncAttributes;\n },\n err => {\n diag.debug(\"a resource's async attributes promise rejected: %s\", err);\n this.asyncAttributesPending = false;\n return {};\n }\n );\n }\n\n get attributes(): ResourceAttributes {\n if (this.asyncAttributesPending) {\n diag.error(\n 'Accessing resource attributes before async attributes settled'\n );\n }\n\n return this._attributes ?? {};\n }\n\n /**\n * Returns a promise that will never be rejected. Resolves when all async attributes have finished being added to\n * this Resource's attributes. This is useful in exporters to block until resource detection\n * has finished.\n */\n async waitForAsyncAttributes?(): Promise {\n if (this.asyncAttributesPending) {\n await this._asyncAttributesPromise;\n }\n }\n\n /**\n * Returns a new, merged {@link Resource} by merging the current Resource\n * with the other Resource. In case of a collision, other Resource takes\n * precedence.\n *\n * @param other the Resource that will be merged with this.\n * @returns the newly merged Resource.\n */\n merge(other: IResource | null): IResource {\n if (!other) return this;\n\n // SpanAttributes from other resource overwrite attributes from this resource.\n const mergedSyncAttributes = {\n ...this._syncAttributes,\n //Support for old resource implementation where _syncAttributes is not defined\n ...((other as Resource)._syncAttributes ?? other.attributes),\n };\n\n if (\n !this._asyncAttributesPromise &&\n !(other as Resource)._asyncAttributesPromise\n ) {\n return new Resource(mergedSyncAttributes);\n }\n\n const mergedAttributesPromise = Promise.all([\n this._asyncAttributesPromise,\n (other as Resource)._asyncAttributesPromise,\n ]).then(([thisAsyncAttributes, otherAsyncAttributes]) => {\n return {\n ...this._syncAttributes,\n ...thisAsyncAttributes,\n //Support for old resource implementation where _syncAttributes is not defined\n ...((other as Resource)._syncAttributes ?? other.attributes),\n ...otherAsyncAttributes,\n };\n });\n\n return new Resource(mergedSyncAttributes, mergedAttributesPromise);\n }\n}\n"]}