Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

@opentelemetry/resources

Package Overview
Dependencies
Maintainers
2
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/resources - npm Package Compare versions

Comparing version
1.0.1
to
1.1.0
+18
build/src/detectors/BrowserDetector.d.ts
import { Detector, Resource, ResourceDetectionConfig } from '..';
/**
* BrowserDetector will be used to detect the resources related to browser.
*/
declare class BrowserDetector implements Detector {
detect(config?: ResourceDetectionConfig): Promise<Resource>;
/**
* Validates process resource attribute map from process variables
*
* @param browserResource The un-sanitized resource attributes from process as key/value pairs.
* @param config: Config
* @returns The sanitized resource attributes.
*/
private _getResourceAttributes;
}
export declare const browserDetector: BrowserDetector;
export {};
//# sourceMappingURL=BrowserDetector.d.ts.map
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.browserDetector = void 0;
const api_1 = require("@opentelemetry/api");
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const __1 = require("..");
/**
* BrowserDetector will be used to detect the resources related to browser.
*/
class BrowserDetector {
async detect(config) {
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
if (!isBrowser) {
return __1.Resource.empty();
}
const browserResource = {
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_RUNTIME_NAME]: 'browser',
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_RUNTIME_DESCRIPTION]: 'Web Browser',
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_RUNTIME_VERSION]: window.navigator.userAgent
};
return this._getResourceAttributes(browserResource, config);
}
/**
* Validates process resource attribute map from process variables
*
* @param browserResource The un-sanitized resource attributes from process as key/value pairs.
* @param config: Config
* @returns The sanitized resource attributes.
*/
_getResourceAttributes(browserResource, _config) {
if (browserResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] === '') {
api_1.diag.debug('BrowserDetector failed: Unable to find required browser resources. ');
return __1.Resource.empty();
}
else {
return new __1.Resource(Object.assign({}, browserResource));
}
}
}
exports.browserDetector = new BrowserDetector();
//# sourceMappingURL=BrowserDetector.js.map
{"version":3,"file":"BrowserDetector.js","sourceRoot":"","sources":["../../../src/detectors/BrowserDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAC1C,8EAAiF;AACjF,0BAAiE;AAGjE;;GAEG;AACH,MAAM,eAAe;IACnB,KAAK,CAAC,MAAM,CAAC,MAAgC;QAC3C,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW,CAAC;QAC1F,IAAI,CAAC,SAAS,EAAE;YACd,OAAO,YAAQ,CAAC,KAAK,EAAE,CAAC;SACzB;QACD,MAAM,eAAe,GAAuB;YAC1C,CAAC,iDAA0B,CAAC,oBAAoB,CAAC,EAAE,SAAS;YAC5D,CAAC,iDAA0B,CAAC,2BAA2B,CAAC,EAAE,aAAa;YACvE,CAAC,iDAA0B,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,SAAS;SACjF,CAAC;QACF,OAAO,IAAI,CAAC,sBAAsB,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IACD;;;;;;OAMG;IACK,sBAAsB,CAC5B,eAAmC,EACnC,OAAiC;QAEjC,IACE,eAAe,CAAC,iDAA0B,CAAC,uBAAuB,CAAC,KAAK,EAAE,EAC1E;YACA,UAAI,CAAC,KAAK,CACR,qEAAqE,CACtE,CAAC;YACF,OAAO,YAAQ,CAAC,KAAK,EAAE,CAAC;SACzB;aAAM;YACL,OAAO,IAAI,YAAQ,mBACd,eAAe,EAClB,CAAC;SACJ;IACH,CAAC;CACF;AAGY,QAAA,eAAe,GAAG,IAAI,eAAe,EAAE,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 } from '@opentelemetry/api';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { Detector, Resource, ResourceDetectionConfig } from '..';\nimport { ResourceAttributes } from '../types';\n\n/**\n * BrowserDetector will be used to detect the resources related to browser.\n */\nclass BrowserDetector implements Detector {\n async detect(config?: ResourceDetectionConfig): Promise<Resource> {\n const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';\n if (!isBrowser) {\n return Resource.empty();\n }\n const browserResource: ResourceAttributes = {\n [SemanticResourceAttributes.PROCESS_RUNTIME_NAME]: 'browser',\n [SemanticResourceAttributes.PROCESS_RUNTIME_DESCRIPTION]: 'Web Browser',\n [SemanticResourceAttributes.PROCESS_RUNTIME_VERSION]: window.navigator.userAgent\n };\n return this._getResourceAttributes(browserResource, config);\n }\n /**\n * Validates process resource attribute map from process variables\n *\n * @param browserResource The un-sanitized resource attributes from process as key/value pairs.\n * @param config: Config\n * @returns The sanitized resource attributes.\n */\n private _getResourceAttributes(\n browserResource: ResourceAttributes,\n _config?: ResourceDetectionConfig\n ) {\n if (\n browserResource[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] === ''\n ) {\n diag.debug(\n 'BrowserDetector failed: Unable to find required browser resources. '\n );\n return Resource.empty();\n } else {\n return new Resource({\n ...browserResource,\n });\n }\n }\n}\n\n\nexport const browserDetector = new BrowserDetector();\n"]}
import { Resource } from '../Resource';
import { Detector } from '../types';
import { ResourceDetectionConfig } from '../config';
/**
* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_ATTRIBUTES environment variable.
*/
declare class EnvDetector implements Detector {
private readonly _MAX_LENGTH;
private readonly _COMMA_SEPARATOR;
private readonly _LABEL_KEY_VALUE_SPLITTER;
private readonly _ERROR_MESSAGE_INVALID_CHARS;
private readonly _ERROR_MESSAGE_INVALID_VALUE;
/**
* Returns a {@link Resource} populated with attributes from the
* OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async
* function to conform to the Detector interface.
*
* @param config The resource detection config
*/
detect(_config?: ResourceDetectionConfig): Promise<Resource>;
/**
* Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment
* variable.
*
* OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes describing
* the source in more detail, e.g. “key1=val1,key2=val2”. Domain names and
* paths are accepted as attribute keys. Values may be quoted or unquoted in
* general. If a value contains whitespaces, =, or " characters, it must
* always be quoted.
*
* @param rawEnvAttributes The resource attributes as a comma-seperated list
* of key/value pairs.
* @returns The sanitized resource attributes.
*/
private _parseResourceAttributes;
/**
* Determines whether the given String is a valid printable ASCII string with
* a length not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid.
*/
private _isValid;
private _isPrintableString;
/**
* Determines whether the given String is a valid printable ASCII string with
* a length greater than 0 and not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid and not empty.
*/
private _isValidAndNotEmpty;
}
export declare const envDetector: EnvDetector;
export {};
//# sourceMappingURL=EnvDetector.d.ts.map
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.envDetector = void 0;
const api_1 = require("@opentelemetry/api");
const core_1 = require("@opentelemetry/core");
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const Resource_1 = require("../Resource");
/**
* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_ATTRIBUTES environment variable.
*/
class EnvDetector {
constructor() {
// Type, attribute keys, and attribute values should not exceed 256 characters.
this._MAX_LENGTH = 255;
// OTEL_RESOURCE_ATTRIBUTES is a comma-separated list of attributes.
this._COMMA_SEPARATOR = ',';
// OTEL_RESOURCE_ATTRIBUTES contains key value pair separated by '='.
this._LABEL_KEY_VALUE_SPLITTER = '=';
this._ERROR_MESSAGE_INVALID_CHARS = 'should be a ASCII string with a length greater than 0 and not exceed ' +
this._MAX_LENGTH +
' characters.';
this._ERROR_MESSAGE_INVALID_VALUE = 'should be a ASCII string with a length not exceed ' +
this._MAX_LENGTH +
' characters.';
}
/**
* Returns a {@link Resource} populated with attributes from the
* OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async
* function to conform to the Detector interface.
*
* @param config The resource detection config
*/
async detect(_config) {
const attributes = {};
const env = (0, core_1.getEnv)();
const rawAttributes = env.OTEL_RESOURCE_ATTRIBUTES;
const serviceName = env.OTEL_SERVICE_NAME;
if (rawAttributes) {
try {
const parsedAttributes = this._parseResourceAttributes(rawAttributes);
Object.assign(attributes, parsedAttributes);
}
catch (e) {
api_1.diag.debug(`EnvDetector failed: ${e.message}`);
}
}
if (serviceName) {
attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] = serviceName;
}
return new Resource_1.Resource(attributes);
}
/**
* Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment
* variable.
*
* OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes describing
* the source in more detail, e.g. “key1=val1,key2=val2”. Domain names and
* paths are accepted as attribute keys. Values may be quoted or unquoted in
* general. If a value contains whitespaces, =, or " characters, it must
* always be quoted.
*
* @param rawEnvAttributes The resource attributes as a comma-seperated list
* of key/value pairs.
* @returns The sanitized resource attributes.
*/
_parseResourceAttributes(rawEnvAttributes) {
if (!rawEnvAttributes)
return {};
const attributes = {};
const rawAttributes = rawEnvAttributes.split(this._COMMA_SEPARATOR, -1);
for (const rawAttribute of rawAttributes) {
const keyValuePair = rawAttribute.split(this._LABEL_KEY_VALUE_SPLITTER, -1);
if (keyValuePair.length !== 2) {
continue;
}
let [key, value] = keyValuePair;
// Leading and trailing whitespaces are trimmed.
key = key.trim();
value = value.trim().split('^"|"$').join('');
if (!this._isValidAndNotEmpty(key)) {
throw new Error(`Attribute key ${this._ERROR_MESSAGE_INVALID_CHARS}`);
}
if (!this._isValid(value)) {
throw new Error(`Attribute value ${this._ERROR_MESSAGE_INVALID_VALUE}`);
}
attributes[key] = value;
}
return attributes;
}
/**
* Determines whether the given String is a valid printable ASCII string with
* a length not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid.
*/
_isValid(name) {
return name.length <= this._MAX_LENGTH && this._isPrintableString(name);
}
_isPrintableString(str) {
for (let i = 0; i < str.length; i++) {
const ch = str.charAt(i);
if (ch <= ' ' || ch >= '~') {
return false;
}
}
return true;
}
/**
* Determines whether the given String is a valid printable ASCII string with
* a length greater than 0 and not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid and not empty.
*/
_isValidAndNotEmpty(str) {
return str.length > 0 && this._isValid(str);
}
}
exports.envDetector = new EnvDetector();
//# sourceMappingURL=EnvDetector.js.map
{"version":3,"file":"EnvDetector.js","sourceRoot":"","sources":["../../../src/detectors/EnvDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;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,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI,GAAG,EAAE;gBAC1B,OAAO,KAAK,CAAC;aACd;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACK,mBAAmB,CAAC,GAAW;QACrC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;CACF;AAEY,QAAA,WAAW,GAAG,IAAI,WAAW,EAAE,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 } from '@opentelemetry/api';\nimport { getEnv } from '@opentelemetry/core';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { Resource } from '../Resource';\nimport { Detector, ResourceAttributes } from '../types';\nimport { ResourceDetectionConfig } from '../config';\n\n/**\n * EnvDetector can be used to detect the presence of and create a Resource\n * from the OTEL_RESOURCE_ATTRIBUTES environment variable.\n */\nclass EnvDetector implements Detector {\n // Type, attribute keys, and attribute values should not exceed 256 characters.\n private readonly _MAX_LENGTH = 255;\n\n // OTEL_RESOURCE_ATTRIBUTES is a comma-separated list of attributes.\n private readonly _COMMA_SEPARATOR = ',';\n\n // OTEL_RESOURCE_ATTRIBUTES contains key value pair separated by '='.\n private readonly _LABEL_KEY_VALUE_SPLITTER = '=';\n\n private readonly _ERROR_MESSAGE_INVALID_CHARS =\n 'should be a ASCII string with a length greater than 0 and not exceed ' +\n this._MAX_LENGTH +\n ' characters.';\n\n private readonly _ERROR_MESSAGE_INVALID_VALUE =\n 'should be a ASCII string with a length not exceed ' +\n this._MAX_LENGTH +\n ' characters.';\n\n /**\n * Returns a {@link Resource} populated with attributes from the\n * OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async\n * function to conform to the Detector interface.\n *\n * @param config The resource detection config\n */\n async detect(_config?: ResourceDetectionConfig): Promise<Resource> {\n const attributes: ResourceAttributes = {};\n const env = getEnv();\n\n const rawAttributes = env.OTEL_RESOURCE_ATTRIBUTES;\n const serviceName = env.OTEL_SERVICE_NAME;\n\n if (rawAttributes) {\n try {\n const parsedAttributes = this._parseResourceAttributes(rawAttributes);\n Object.assign(attributes, parsedAttributes);\n } catch (e) {\n diag.debug(`EnvDetector failed: ${e.message}`);\n }\n }\n\n if (serviceName) {\n attributes[SemanticResourceAttributes.SERVICE_NAME] = serviceName;\n }\n\n return new Resource(attributes);\n }\n\n /**\n * Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment\n * variable.\n *\n * OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes describing\n * the source in more detail, e.g. “key1=val1,key2=val2”. Domain names and\n * paths are accepted as attribute keys. Values may be quoted or unquoted in\n * general. If a value contains whitespaces, =, or \" characters, it must\n * always be quoted.\n *\n * @param rawEnvAttributes The resource attributes as a comma-seperated list\n * of key/value pairs.\n * @returns The sanitized resource attributes.\n */\n private _parseResourceAttributes(\n rawEnvAttributes?: string\n ): ResourceAttributes {\n if (!rawEnvAttributes) return {};\n\n const attributes: ResourceAttributes = {};\n const rawAttributes: string[] = rawEnvAttributes.split(\n this._COMMA_SEPARATOR,\n -1\n );\n for (const rawAttribute of rawAttributes) {\n const keyValuePair: string[] = rawAttribute.split(\n this._LABEL_KEY_VALUE_SPLITTER,\n -1\n );\n if (keyValuePair.length !== 2) {\n continue;\n }\n let [key, value] = keyValuePair;\n // Leading and trailing whitespaces are trimmed.\n key = key.trim();\n value = value.trim().split('^\"|\"$').join('');\n if (!this._isValidAndNotEmpty(key)) {\n throw new Error(`Attribute key ${this._ERROR_MESSAGE_INVALID_CHARS}`);\n }\n if (!this._isValid(value)) {\n throw new Error(`Attribute value ${this._ERROR_MESSAGE_INVALID_VALUE}`);\n }\n attributes[key] = value;\n }\n return attributes;\n }\n\n /**\n * Determines whether the given String is a valid printable ASCII string with\n * a length not exceed _MAX_LENGTH characters.\n *\n * @param str The String to be validated.\n * @returns Whether the String is valid.\n */\n private _isValid(name: string): boolean {\n return name.length <= this._MAX_LENGTH && this._isPrintableString(name);\n }\n\n private _isPrintableString(str: string): boolean {\n for (let i = 0; i < str.length; i++) {\n const ch: string = str.charAt(i);\n if (ch <= ' ' || ch >= '~') {\n return false;\n }\n }\n return true;\n }\n\n /**\n * Determines whether the given String is a valid printable ASCII string with\n * a length greater than 0 and not exceed _MAX_LENGTH characters.\n *\n * @param str The String to be validated.\n * @returns Whether the String is valid and not empty.\n */\n private _isValidAndNotEmpty(str: string): boolean {\n return str.length > 0 && this._isValid(str);\n }\n}\n\nexport const envDetector = new EnvDetector();\n"]}
export * from './EnvDetector';
export * from './ProcessDetector';
export * from './BrowserDetector';
//# sourceMappingURL=index.d.ts.map
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./EnvDetector"), exports);
__exportStar(require("./ProcessDetector"), exports);
__exportStar(require("./BrowserDetector"), exports);
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/detectors/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,gDAA8B;AAC9B,oDAAkC;AAClC,oDAAkC","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\nexport * from './EnvDetector';\nexport * from './ProcessDetector';\nexport * from './BrowserDetector';\n"]}
import { Resource } from '../Resource';
import { Detector } from '../types';
import { ResourceDetectionConfig } from '../config';
/**
* ProcessDetector will be used to detect the resources related current process running
* and being instrumented from the NodeJS Process module.
*/
declare class ProcessDetector implements Detector {
detect(config?: ResourceDetectionConfig): Promise<Resource>;
/**
* Validates process resource attribute map from process varaibls
*
* @param processResource The unsantized resource attributes from process as key/value pairs.
* @param config: Config
* @returns The sanitized resource attributes.
*/
private _getResourceAttributes;
}
export declare const processDetector: ProcessDetector;
export {};
//# sourceMappingURL=ProcessDetector.d.ts.map
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.processDetector = void 0;
const api_1 = require("@opentelemetry/api");
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const Resource_1 = require("../Resource");
/**
* ProcessDetector will be used to detect the resources related current process running
* and being instrumented from the NodeJS Process module.
*/
class ProcessDetector {
async detect(config) {
// Skip if not in Node.js environment.
if (typeof process !== 'object') {
return Resource_1.Resource.empty();
}
const processResource = {
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_PID]: process.pid,
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME]: process.title || '',
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_COMMAND]: process.argv[1] || '',
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_COMMAND_LINE]: process.argv.join(' ') || '',
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_RUNTIME_VERSION]: process.versions.node,
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_RUNTIME_NAME]: 'nodejs',
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_RUNTIME_DESCRIPTION]: 'Node.js',
};
return this._getResourceAttributes(processResource, config);
}
/**
* Validates process resource attribute map from process varaibls
*
* @param processResource The unsantized resource attributes from process as key/value pairs.
* @param config: Config
* @returns The sanitized resource attributes.
*/
_getResourceAttributes(processResource, _config) {
if (processResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME] ===
'' ||
processResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_EXECUTABLE_PATH] ===
'' ||
processResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_COMMAND] === '' ||
processResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_COMMAND_LINE] === '' ||
processResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] === '') {
api_1.diag.debug('ProcessDetector failed: Unable to find required process resources. ');
return Resource_1.Resource.empty();
}
else {
return new Resource_1.Resource(Object.assign({}, processResource));
}
}
}
exports.processDetector = new ProcessDetector();
//# sourceMappingURL=ProcessDetector.js.map
{"version":3,"file":"ProcessDetector.js","sourceRoot":"","sources":["../../../src/detectors/ProcessDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAC1C,8EAAiF;AACjF,0CAAuC;AAIvC;;;GAGG;AACH,MAAM,eAAe;IACnB,KAAK,CAAC,MAAM,CAAC,MAAgC;QAC3C,sCAAsC;QACtC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,OAAO,mBAAQ,CAAC,KAAK,EAAE,CAAC;SACzB;QACD,MAAM,eAAe,GAAuB;YAC1C,CAAC,iDAA0B,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,GAAG;YACrD,CAAC,iDAA0B,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;YACzE,CAAC,iDAA0B,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;YACnE,CAAC,iDAA0B,CAAC,oBAAoB,CAAC,EAC/C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;YAC9B,CAAC,iDAA0B,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;YAC3E,CAAC,iDAA0B,CAAC,oBAAoB,CAAC,EAAE,QAAQ;YAC3D,CAAC,iDAA0B,CAAC,2BAA2B,CAAC,EAAE,SAAS;SACpE,CAAC;QACF,OAAO,IAAI,CAAC,sBAAsB,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IACD;;;;;;OAMG;IACK,sBAAsB,CAC5B,eAAmC,EACnC,OAAiC;QAEjC,IACE,eAAe,CAAC,iDAA0B,CAAC,uBAAuB,CAAC;YACjE,EAAE;YACJ,eAAe,CAAC,iDAA0B,CAAC,uBAAuB,CAAC;gBACjE,EAAE;YACJ,eAAe,CAAC,iDAA0B,CAAC,eAAe,CAAC,KAAK,EAAE;YAClE,eAAe,CAAC,iDAA0B,CAAC,oBAAoB,CAAC,KAAK,EAAE;YACvE,eAAe,CAAC,iDAA0B,CAAC,uBAAuB,CAAC,KAAK,EAAE,EAC1E;YACA,UAAI,CAAC,KAAK,CACR,qEAAqE,CACtE,CAAC;YACF,OAAO,mBAAQ,CAAC,KAAK,EAAE,CAAC;SACzB;aAAM;YACL,OAAO,IAAI,mBAAQ,mBACd,eAAe,EAClB,CAAC;SACJ;IACH,CAAC;CACF;AAEY,QAAA,eAAe,GAAG,IAAI,eAAe,EAAE,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 } from '@opentelemetry/api';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { Resource } from '../Resource';\nimport { Detector, ResourceAttributes } from '../types';\nimport { ResourceDetectionConfig } from '../config';\n\n/**\n * ProcessDetector will be used to detect the resources related current process running\n * and being instrumented from the NodeJS Process module.\n */\nclass ProcessDetector implements Detector {\n async detect(config?: ResourceDetectionConfig): Promise<Resource> {\n // Skip if not in Node.js environment.\n if (typeof process !== 'object') {\n return Resource.empty();\n }\n const processResource: ResourceAttributes = {\n [SemanticResourceAttributes.PROCESS_PID]: process.pid,\n [SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME]: process.title || '',\n [SemanticResourceAttributes.PROCESS_COMMAND]: process.argv[1] || '',\n [SemanticResourceAttributes.PROCESS_COMMAND_LINE]:\n process.argv.join(' ') || '',\n [SemanticResourceAttributes.PROCESS_RUNTIME_VERSION]: process.versions.node,\n [SemanticResourceAttributes.PROCESS_RUNTIME_NAME]: 'nodejs',\n [SemanticResourceAttributes.PROCESS_RUNTIME_DESCRIPTION]: 'Node.js',\n };\n return this._getResourceAttributes(processResource, config);\n }\n /**\n * Validates process resource attribute map from process varaibls\n *\n * @param processResource The unsantized resource attributes from process as key/value pairs.\n * @param config: Config\n * @returns The sanitized resource attributes.\n */\n private _getResourceAttributes(\n processResource: ResourceAttributes,\n _config?: ResourceDetectionConfig\n ) {\n if (\n processResource[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME] ===\n '' ||\n processResource[SemanticResourceAttributes.PROCESS_EXECUTABLE_PATH] ===\n '' ||\n processResource[SemanticResourceAttributes.PROCESS_COMMAND] === '' ||\n processResource[SemanticResourceAttributes.PROCESS_COMMAND_LINE] === '' ||\n processResource[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] === ''\n ) {\n diag.debug(\n 'ProcessDetector failed: Unable to find required process resources. '\n );\n return Resource.empty();\n } else {\n return new Resource({\n ...processResource,\n });\n }\n }\n}\n\nexport const processDetector = new ProcessDetector();\n"]}
+1
-0

@@ -5,2 +5,3 @@ export * from './Resource';

export * from './config';
export * from './detectors';
//# sourceMappingURL=index.d.ts.map

@@ -32,2 +32,3 @@ "use strict";

__exportStar(require("./config"), exports);
__exportStar(require("./detectors"), exports);
//# sourceMappingURL=index.js.map
+1
-1

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,6CAA2B;AAC3B,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB","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\nexport * from './Resource';\nexport * from './platform';\nexport * from './types';\nexport * from './config';\n"]}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,6CAA2B;AAC3B,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,8CAA4B","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\nexport * from './Resource';\nexport * from './platform';\nexport * from './types';\nexport * from './config';\nexport * from './detectors';\n"]}
import { Resource } from '../../Resource';
import { ResourceDetectionConfig } from '../../config';
/**
* Detects resources for the browser platform, which is currently only the
* telemetry SDK resource. More could be added in the future. This method
* is async to match the signature of corresponding method for node.
* Runs all resource detectors and returns the results merged into a single
* Resource.
*
* @param config Configuration for resource detection
*/
export declare const detectResources: () => Promise<Resource>;
export declare const detectResources: (config?: ResourceDetectionConfig) => Promise<Resource>;
//# sourceMappingURL=detect-resources.d.ts.map

@@ -20,11 +20,25 @@ "use strict";

const Resource_1 = require("../../Resource");
const api_1 = require("@opentelemetry/api");
/**
* Detects resources for the browser platform, which is currently only the
* telemetry SDK resource. More could be added in the future. This method
* is async to match the signature of corresponding method for node.
* Runs all resource detectors and returns the results merged into a single
* Resource.
*
* @param config Configuration for resource detection
*/
const detectResources = async () => {
return Resource_1.Resource.empty();
const detectResources = async (config = {}) => {
const internalConfig = Object.assign(config);
const resources = await Promise.all((internalConfig.detectors || []).map(async (d) => {
try {
const resource = await d.detect(internalConfig);
api_1.diag.debug(`${d.constructor.name} found resource.`, resource);
return resource;
}
catch (e) {
api_1.diag.debug(`${d.constructor.name} failed: ${e.message}`);
return Resource_1.Resource.empty();
}
}));
return resources.reduce((acc, resource) => acc.merge(resource), Resource_1.Resource.empty());
};
exports.detectResources = detectResources;
//# sourceMappingURL=detect-resources.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"detect-resources.js","sourceRoot":"","sources":["../../../../src/platform/browser/detect-resources.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6CAA0C;AAE1C;;;;GAIG;AACI,MAAM,eAAe,GAAG,KAAK,IAAuB,EAAE;IAC3D,OAAO,mBAAQ,CAAC,KAAK,EAAE,CAAC;AAC1B,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B","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 { Resource } from '../../Resource';\n\n/**\n * Detects resources for the browser platform, which is currently only the\n * telemetry SDK resource. More could be added in the future. This method\n * is async to match the signature of corresponding method for node.\n */\nexport const detectResources = async (): Promise<Resource> => {\n return Resource.empty();\n};\n"]}
{"version":3,"file":"detect-resources.js","sourceRoot":"","sources":["../../../../src/platform/browser/detect-resources.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6CAA0C;AAE1C,4CAA0C;AAE1C;;;;;GAKG;AACI,MAAM,eAAe,GAAG,KAAK,EAClC,SAAkC,EAAE,EACjB,EAAE;IACrB,MAAM,cAAc,GAA4B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEtE,MAAM,SAAS,GAAe,MAAM,OAAO,CAAC,GAAG,CAC7C,CAAC,cAAc,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;QAC7C,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YAChD,UAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,IAAI,kBAAkB,EAAE,QAAQ,CAAC,CAAC;YAC9D,OAAO,QAAQ,CAAC;SACjB;QAAC,OAAO,CAAC,EAAE;YACV,UAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,IAAI,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACzD,OAAO,mBAAQ,CAAC,KAAK,EAAE,CAAC;SACzB;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EACtC,mBAAQ,CAAC,KAAK,EAAE,CACjB,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,eAAe,mBAsB1B","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 { Resource } from '../../Resource';\nimport { ResourceDetectionConfig } from '../../config';\nimport { diag } from '@opentelemetry/api';\n\n/**\n * Runs all resource detectors and returns the results merged into a single\n * Resource.\n *\n * @param config Configuration for resource detection\n */\nexport const detectResources = async (\n config: ResourceDetectionConfig = {}\n): Promise<Resource> => {\n const internalConfig: ResourceDetectionConfig = Object.assign(config);\n\n const resources: Resource[] = await Promise.all(\n (internalConfig.detectors || []).map(async d => {\n try {\n const resource = await d.detect(internalConfig);\n diag.debug(`${d.constructor.name} found resource.`, resource);\n return resource;\n } catch (e) {\n diag.debug(`${d.constructor.name} failed: ${e.message}`);\n return Resource.empty();\n }\n })\n );\n\n return resources.reduce(\n (acc, resource) => acc.merge(resource),\n Resource.empty()\n );\n};\n"]}

@@ -49,3 +49,3 @@ "use strict";

*
* @param resources The array of {@link Resource} that should be logged. Empty entried will be ignored.
* @param resources The array of {@link Resource} that should be logged. Empty entries will be ignored.
*/

@@ -52,0 +52,0 @@ const logResources = (resources) => {

@@ -1,1 +0,1 @@

{"version":3,"file":"detect-resources.js","sourceRoot":"","sources":["../../../../src/platform/node/detect-resources.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6CAA0C;AAE1C,4CAA0C;AAC1C,6BAA6B;AAE7B;;;;;GAKG;AACI,MAAM,eAAe,GAAG,KAAK,EAClC,SAAkC,EAAE,EACjB,EAAE;IACrB,MAAM,cAAc,GAA4B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEtE,MAAM,SAAS,GAAoB,MAAM,OAAO,CAAC,GAAG,CAClD,CAAC,cAAc,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;QAC7C,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;YAChD,UAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,IAAI,kBAAkB,EAAE,QAAQ,CAAC,CAAC;YAC9D,OAAO,QAAQ,CAAC;SACjB;QAAC,OAAO,CAAC,EAAE;YACV,UAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,IAAI,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;YACzD,OAAO,mBAAQ,CAAC,KAAK,EAAE,CAAC;SACzB;IACH,CAAC,CAAC,CACH,CAAC;IAEF,yDAAyD;IACzD,YAAY,CAAC,SAAS,CAAC,CAAC;IAExB,OAAO,SAAS,CAAC,MAAM,CACrB,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EACtC,mBAAQ,CAAC,KAAK,EAAE,CACjB,CAAC;AACJ,CAAC,CAAC;AAzBW,QAAA,eAAe,mBAyB1B;AAEF;;;;GAIG;AACH,MAAM,YAAY,GAAG,CAAC,SAA0B,EAAE,EAAE;IAClD,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,iCAAiC;QACjC,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/C,MAAM,mBAAmB,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE;gBAC5D,KAAK,EAAE,CAAC;gBACR,WAAW,EAAE,QAAQ;gBACrB,MAAM,EAAE,IAAI;gBACZ,OAAO,EAAE,KAAK;aACf,CAAC,CAAC;YACH,UAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;SACnC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,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 { Resource } from '../../Resource';\nimport { ResourceDetectionConfig } from '../../config';\nimport { diag } from '@opentelemetry/api';\nimport * as util from 'util';\n\n/**\n * Runs all resource detectors and returns the results merged into a single\n * Resource.\n *\n * @param config Configuration for resource detection\n */\nexport const detectResources = async (\n config: ResourceDetectionConfig = {}\n): Promise<Resource> => {\n const internalConfig: ResourceDetectionConfig = Object.assign(config);\n\n const resources: Array<Resource> = await Promise.all(\n (internalConfig.detectors || []).map(async d => {\n try {\n const resource = await d.detect(internalConfig);\n diag.debug(`${d.constructor.name} found resource.`, resource);\n return resource;\n } catch (e) {\n diag.debug(`${d.constructor.name} failed: ${e.message}`);\n return Resource.empty();\n }\n })\n );\n\n // Future check if verbose logging is enabled issue #1903\n logResources(resources);\n\n return resources.reduce(\n (acc, resource) => acc.merge(resource),\n Resource.empty()\n );\n};\n\n/**\n * Writes debug information about the detected resources to the logger defined in the resource detection config, if one is provided.\n *\n * @param resources The array of {@link Resource} that should be logged. Empty entried will be ignored.\n */\nconst logResources = (resources: Array<Resource>) => {\n resources.forEach(resource => {\n // Print only populated resources\n if (Object.keys(resource.attributes).length > 0) {\n const resourceDebugString = util.inspect(resource.attributes, {\n depth: 2,\n breakLength: Infinity,\n sorted: true,\n compact: false,\n });\n diag.verbose(resourceDebugString);\n }\n });\n};\n"]}
{"version":3,"file":"detect-resources.js","sourceRoot":"","sources":["../../../../src/platform/node/detect-resources.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,6CAA0C;AAE1C,4CAA0C;AAC1C,6BAA6B;AAE7B;;;;;GAKG;AACI,MAAM,eAAe,GAAG,KAAK,EAClC,SAAkC,EAAE,EACjB,EAAE;IACrB,MAAM,cAAc,GAA4B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEtE,MAAM,SAAS,GAAe,MAAM,OAAO,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O,CAAC,mBAAmB,CAAC,CAAC;SACnC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,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 { Resource } from '../../Resource';\nimport { ResourceDetectionConfig } from '../../config';\nimport { diag } from '@opentelemetry/api';\nimport * as util from 'util';\n\n/**\n * Runs all resource detectors and returns the results merged into a single\n * Resource.\n *\n * @param config Configuration for resource detection\n */\nexport const detectResources = async (\n config: ResourceDetectionConfig = {}\n): Promise<Resource> => {\n const internalConfig: ResourceDetectionConfig = Object.assign(config);\n\n const resources: Resource[] = await Promise.all(\n (internalConfig.detectors || []).map(async d => {\n try {\n const resource = await d.detect(internalConfig);\n diag.debug(`${d.constructor.name} found resource.`, resource);\n return resource;\n } catch (e) {\n diag.debug(`${d.constructor.name} failed: ${e.message}`);\n return Resource.empty();\n }\n })\n );\n\n // Future check if verbose logging is enabled issue #1903\n logResources(resources);\n\n return resources.reduce(\n (acc, resource) => acc.merge(resource),\n Resource.empty()\n );\n};\n\n\n/**\n * Writes debug information about the detected resources to the logger defined in the resource detection config, if one is provided.\n *\n * @param resources The array of {@link Resource} that should be logged. Empty entries will be ignored.\n */\nconst logResources = (resources: Array<Resource>) => {\n resources.forEach(resource => {\n // Print only populated resources\n if (Object.keys(resource.attributes).length > 0) {\n const resourceDebugString = util.inspect(resource.attributes, {\n depth: 2,\n breakLength: Infinity,\n sorted: true,\n compact: false,\n });\n diag.verbose(resourceDebugString);\n }\n });\n};\n"]}
export * from './default-service-name';
export * from './detect-resources';
export * from './detectors';
//# sourceMappingURL=index.d.ts.map

@@ -30,3 +30,2 @@ "use strict";

__exportStar(require("./detect-resources"), exports);
__exportStar(require("./detectors"), exports);
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,yDAAuC;AACvC,qDAAmC;AACnC,8CAA4B","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\nexport * from './default-service-name';\nexport * from './detect-resources';\nexport * from './detectors';\n"]}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,yDAAuC;AACvC,qDAAmC","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\nexport * from './default-service-name';\nexport * from './detect-resources';\n"]}

@@ -47,3 +47,3 @@ "use strict";

return new Resource({
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: platform_1.defaultServiceName(),
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: (0, platform_1.defaultServiceName)(),
[semantic_conventions_1.SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]: core_1.SDK_INFO[semantic_conventions_1.SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE],

@@ -50,0 +50,0 @@ [semantic_conventions_1.SemanticResourceAttributes.TELEMETRY_SDK_NAME]: core_1.SDK_INFO[semantic_conventions_1.SemanticResourceAttributes.TELEMETRY_SDK_NAME],

@@ -1,1 +0,1 @@

{"version":3,"file":"Resource.js","sourceRoot":"","sources":["../../src/Resource.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,8EAAiF;AACjF,8CAA+C;AAE/C,yCAAgD;AAEhD;;;GAGG;AACH,MAAa,QAAQ;IAyBnB;IACE;;;;OAIG;IACM,UAA8B;QAA9B,eAAU,GAAV,UAAU,CAAoB;IACtC,CAAC;IA7BJ;;OAEG;IACH,MAAM,CAAC,KAAK;QACV,OAAO,QAAQ,CAAC,KAAK,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO;QACZ,OAAO,IAAI,QAAQ,CAAC;YAClB,CAAC,iDAA0B,CAAC,YAAY,CAAC,EAAE,6BAAkB,EAAE;YAC/D,CAAC,iDAA0B,CAAC,sBAAsB,CAAC,EACjD,eAAQ,CAAC,iDAA0B,CAAC,sBAAsB,CAAC;YAC7D,CAAC,iDAA0B,CAAC,kBAAkB,CAAC,EAC7C,eAAQ,CAAC,iDAA0B,CAAC,kBAAkB,CAAC;YACzD,CAAC,iDAA0B,CAAC,qBAAqB,CAAC,EAChD,eAAQ,CAAC,iDAA0B,CAAC,qBAAqB,CAAC;SAC7D,CAAC,CAAA;IACJ,CAAC;IAWD;;;;;;;OAOG;IACH,KAAK,CAAC,KAAsB;QAC1B,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAEjE,yEAAyE;QACzE,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CACpC,EAAE,EACF,IAAI,CAAC,UAAU,EACf,KAAK,CAAC,UAAU,CACjB,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACxC,CAAC;;AApDH,4BAqDC;AApDiB,cAAK,GAAG,IAAI,QAAQ,CAAC,EAAE,CAAC,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 { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { SDK_INFO } from '@opentelemetry/core';\nimport { ResourceAttributes } from './types';\nimport { defaultServiceName } from './platform';\n\n/**\n * A Resource describes the entity for which a signals (metrics or trace) are\n * collected.\n */\nexport class Resource {\n static readonly EMPTY = new Resource({});\n\n /**\n * Returns an empty Resource\n */\n static empty(): Resource {\n return Resource.EMPTY;\n }\n\n /**\n * Returns a Resource that indentifies the SDK in use.\n */\n static default(): Resource {\n return new Resource({\n [SemanticResourceAttributes.SERVICE_NAME]: defaultServiceName(),\n [SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]:\n SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE],\n [SemanticResourceAttributes.TELEMETRY_SDK_NAME]:\n SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_NAME],\n [SemanticResourceAttributes.TELEMETRY_SDK_VERSION]:\n SDK_INFO[SemanticResourceAttributes.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 readonly attributes: ResourceAttributes\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: Resource | null): Resource {\n if (!other || !Object.keys(other.attributes).length) return this;\n\n // SpanAttributes from resource overwrite attributes from other resource.\n const mergedAttributes = Object.assign(\n {},\n this.attributes,\n other.attributes\n );\n return new Resource(mergedAttributes);\n }\n}\n"]}
{"version":3,"file":"Resource.js","sourceRoot":"","sources":["../../src/Resource.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,8EAAiF;AACjF,8CAA+C;AAE/C,yCAAgD;AAEhD;;;GAGG;AACH,MAAa,QAAQ;IAyBnB;IACE;;;;OAIG;IACM,UAA8B;QAA9B,eAAU,GAAV,UAAU,CAAoB;IACtC,CAAC;IA7BJ;;OAEG;IACH,MAAM,CAAC,KAAK;QACV,OAAO,QAAQ,CAAC,KAAK,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO;QACZ,OAAO,IAAI,QAAQ,CAAC;YAClB,CAAC,iDAA0B,CAAC,YAAY,CAAC,EAAE,IAAA,6BAAkB,GAAE;YAC/D,CAAC,iDAA0B,CAAC,sBAAsB,CAAC,EACjD,eAAQ,CAAC,iDAA0B,CAAC,sBAAsB,CAAC;YAC7D,CAAC,iDAA0B,CAAC,kBAAkB,CAAC,EAC7C,eAAQ,CAAC,iDAA0B,CAAC,kBAAkB,CAAC;YACzD,CAAC,iDAA0B,CAAC,qBAAqB,CAAC,EAChD,eAAQ,CAAC,iDAA0B,CAAC,qBAAqB,CAAC;SAC7D,CAAC,CAAC;IACL,CAAC;IAWD;;;;;;;OAOG;IACH,KAAK,CAAC,KAAsB;QAC1B,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAEjE,yEAAyE;QACzE,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CACpC,EAAE,EACF,IAAI,CAAC,UAAU,EACf,KAAK,CAAC,UAAU,CACjB,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACxC,CAAC;;AApDH,4BAqDC;AApDiB,cAAK,GAAG,IAAI,QAAQ,CAAC,EAAE,CAAC,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 { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { SDK_INFO } from '@opentelemetry/core';\nimport { ResourceAttributes } from './types';\nimport { defaultServiceName } from './platform';\n\n/**\n * A Resource describes the entity for which a signals (metrics or trace) are\n * collected.\n */\nexport class Resource {\n static readonly EMPTY = new Resource({});\n\n /**\n * Returns an empty Resource\n */\n static empty(): Resource {\n return Resource.EMPTY;\n }\n\n /**\n * Returns a Resource that indentifies the SDK in use.\n */\n static default(): Resource {\n return new Resource({\n [SemanticResourceAttributes.SERVICE_NAME]: defaultServiceName(),\n [SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]:\n SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE],\n [SemanticResourceAttributes.TELEMETRY_SDK_NAME]:\n SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_NAME],\n [SemanticResourceAttributes.TELEMETRY_SDK_VERSION]:\n SDK_INFO[SemanticResourceAttributes.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 readonly attributes: ResourceAttributes\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: Resource | null): Resource {\n if (!other || !Object.keys(other.attributes).length) return this;\n\n // SpanAttributes from resource overwrite attributes from other resource.\n const mergedAttributes = Object.assign(\n {},\n this.attributes,\n other.attributes\n );\n return new Resource(mergedAttributes);\n }\n}\n"]}

@@ -1,2 +0,2 @@

export declare const VERSION = "1.0.1";
export declare const VERSION = "1.1.0";
//# sourceMappingURL=version.d.ts.map

@@ -20,3 +20,3 @@ "use strict";

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '1.0.1';
exports.VERSION = '1.1.0';
//# sourceMappingURL=version.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,OAAO,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\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.0.1';\n"]}
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,OAAO,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\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.1.0';\n"]}
{
"name": "@opentelemetry/resources",
"version": "1.0.1",
"version": "1.1.0",
"description": "OpenTelemetry SDK resources",
"main": "build/src/index.js",
"module": "build/esm/index.js",
"esnext": "build/esnext/index.js",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts",
"./build/esm/platform/index.js": "./build/esm/platform/browser/index.js",
"./build/esnext/platform/index.js": "./build/esnext/platform/browser/index.js",
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"

@@ -15,11 +17,13 @@ },

"scripts": {
"compile": "tsc --build tsconfig.json tsconfig.esm.json",
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json",
"compile": "tsc --build tsconfig.all.json",
"clean": "tsc --build --clean tsconfig.all.json",
"codecov:browser": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test:browser": "nyc karma start --single-run",
"tdd": "npm run test -- --watch-extensions ts --watch",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"version": "node ../../scripts/version-update.js",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "npm run precompile"

@@ -43,2 +47,5 @@ },

"build/esm/**/*.d.ts",
"build/esnext/**/*.js",
"build/esnext/**/*.js.map",
"build/esnext/**/*.d.ts",
"build/src/**/*.js",

@@ -55,9 +62,17 @@ "build/src/**/*.js.map",

"devDependencies": {
"@opentelemetry/api": "~1.0.3",
"@opentelemetry/api": "~1.1.0",
"@types/mocha": "8.2.3",
"@types/node": "14.17.11",
"@types/sinon": "10.0.2",
"@types/node": "14.17.33",
"@types/sinon": "10.0.6",
"@types/webpack-env": "1.16.3",
"codecov": "3.8.3",
"karma": "6.3.16",
"karma-chrome-launcher": "3.1.0",
"karma-coverage-istanbul-reporter": "3.0.3",
"karma-mocha": "2.0.1",
"karma-mocha-webworker": "1.3.0",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "4.0.2",
"mocha": "7.2.0",
"nock": "12.0.3",
"nock": "13.0.11",
"nyc": "15.1.0",

@@ -67,12 +82,15 @@ "rimraf": "3.0.2",

"ts-mocha": "8.0.0",
"typescript": "4.3.5"
"typescript": "4.4.4",
"webpack": "4.46.0",
"webpack-cli": "4.9.1",
"webpack-merge": "5.8.0"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.0.0 <1.1.0"
"@opentelemetry/api": ">=1.0.0 <1.2.0"
},
"dependencies": {
"@opentelemetry/core": "1.0.1",
"@opentelemetry/semantic-conventions": "1.0.1"
"@opentelemetry/core": "1.1.0",
"@opentelemetry/semantic-conventions": "1.1.0"
},
"gitHead": "9cf402ee4231ee1446884b5f59958ceafc1b5188"
"gitHead": "f384303ac469914d0dbafde0758ccdae473f336e"
}
# OpenTelemetry Resources Util
[![NPM Published Version][npm-img]][npm-url]
[![dependencies][dependencies-image]][dependencies-url]
[![devDependencies][devDependencies-image]][devDependencies-url]
[![Apache License][license-image]][license-image]

@@ -48,6 +46,2 @@

[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-resources
[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-resources
[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js.svg?path=packages%2Fopentelemetry-resources&type=dev
[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js?path=packages%2Fopentelemetry-resources&type=dev
[npm-url]: https://www.npmjs.com/package/@opentelemetry/resources

@@ -54,0 +48,0 @@ [npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fresources.svg

import type { Detector } from './types';
/**
* ResourceDetectionConfig provides an interface for configuring resource auto-detection.
*/
export interface ResourceDetectionConfig {
detectors?: Array<Detector>;
}
//# sourceMappingURL=config.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {};
//# sourceMappingURL=config.js.map
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","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 type { Detector } from './types';\n\n/**\n * ResourceDetectionConfig provides an interface for configuring resource auto-detection.\n */\nexport interface ResourceDetectionConfig {\n detectors?: Array<Detector>;\n}\n"]}
export * from './Resource';
export * from './platform';
export * from './types';
export * from './config';
//# sourceMappingURL=index.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './Resource';
export * from './platform';
export * from './types';
export * from './config';
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,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\nexport * from './Resource';\nexport * from './platform';\nexport * from './types';\nexport * from './config';\n"]}
export declare function defaultServiceName(): string;
//# sourceMappingURL=default-service-name.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export function defaultServiceName() {
return 'unknown_service';
}
//# sourceMappingURL=default-service-name.js.map
{"version":3,"file":"default-service-name.js","sourceRoot":"","sources":["../../../../src/platform/browser/default-service-name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,UAAU,kBAAkB;IAC9B,OAAO,iBAAiB,CAAC;AAC7B,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\nexport function defaultServiceName(): string {\n return 'unknown_service';\n}\n"]}
import { Resource } from '../../Resource';
/**
* Detects resources for the browser platform, which is currently only the
* telemetry SDK resource. More could be added in the future. This method
* is async to match the signature of corresponding method for node.
*/
export declare const detectResources: () => Promise<Resource>;
//# sourceMappingURL=detect-resources.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { Resource } from '../../Resource';
/**
* Detects resources for the browser platform, which is currently only the
* telemetry SDK resource. More could be added in the future. This method
* is async to match the signature of corresponding method for node.
*/
export var detectResources = function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, Resource.empty()];
});
}); };
//# sourceMappingURL=detect-resources.js.map
{"version":3,"file":"detect-resources.js","sourceRoot":"","sources":["../../../../src/platform/browser/detect-resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C;;;;GAIG;AACH,MAAM,CAAC,IAAM,eAAe,GAAG;;QAC7B,sBAAO,QAAQ,CAAC,KAAK,EAAE,EAAC;;KACzB,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 { Resource } from '../../Resource';\n\n/**\n * Detects resources for the browser platform, which is currently only the\n * telemetry SDK resource. More could be added in the future. This method\n * is async to match the signature of corresponding method for node.\n */\nexport const detectResources = async (): Promise<Resource> => {\n return Resource.empty();\n};\n"]}
export * from './default-service-name';
export * from './detect-resources';
//# sourceMappingURL=index.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './default-service-name';
export * from './detect-resources';
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/browser/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,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\nexport * from './default-service-name';\nexport * from './detect-resources';\n"]}
export * from './node';
//# sourceMappingURL=index.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './node';
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/platform/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,QAAQ,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\nexport * from './node';\n"]}
export declare function defaultServiceName(): string;
//# sourceMappingURL=default-service-name.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export function defaultServiceName() {
return "unknown_service:" + process.argv0;
}
//# sourceMappingURL=default-service-name.js.map
{"version":3,"file":"default-service-name.js","sourceRoot":"","sources":["../../../../src/platform/node/default-service-name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,UAAU,kBAAkB;IAC9B,OAAO,qBAAmB,OAAO,CAAC,KAAO,CAAC;AAC9C,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\nexport function defaultServiceName(): string {\n return `unknown_service:${process.argv0}`;\n}\n"]}
import { Resource } from '../../Resource';
import { ResourceDetectionConfig } from '../../config';
/**
* Runs all resource detectors and returns the results merged into a single
* Resource.
*
* @param config Configuration for resource detection
*/
export declare const detectResources: (config?: ResourceDetectionConfig) => Promise<Resource>;
//# sourceMappingURL=detect-resources.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { Resource } from '../../Resource';
import { diag } from '@opentelemetry/api';
import * as util from 'util';
/**
* Runs all resource detectors and returns the results merged into a single
* Resource.
*
* @param config Configuration for resource detection
*/
export var detectResources = function (config) {
if (config === void 0) { config = {}; }
return __awaiter(void 0, void 0, void 0, function () {
var internalConfig, resources;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
internalConfig = Object.assign(config);
return [4 /*yield*/, Promise.all((internalConfig.detectors || []).map(function (d) { return __awaiter(void 0, void 0, void 0, function () {
var resource, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, d.detect(internalConfig)];
case 1:
resource = _a.sent();
diag.debug(d.constructor.name + " found resource.", resource);
return [2 /*return*/, resource];
case 2:
e_1 = _a.sent();
diag.debug(d.constructor.name + " failed: " + e_1.message);
return [2 /*return*/, Resource.empty()];
case 3: return [2 /*return*/];
}
});
}); }))];
case 1:
resources = _a.sent();
// Future check if verbose logging is enabled issue #1903
logResources(resources);
return [2 /*return*/, resources.reduce(function (acc, resource) { return acc.merge(resource); }, Resource.empty())];
}
});
});
};
/**
* Writes debug information about the detected resources to the logger defined in the resource detection config, if one is provided.
*
* @param resources The array of {@link Resource} that should be logged. Empty entried will be ignored.
*/
var logResources = function (resources) {
resources.forEach(function (resource) {
// Print only populated resources
if (Object.keys(resource.attributes).length > 0) {
var resourceDebugString = util.inspect(resource.attributes, {
depth: 2,
breakLength: Infinity,
sorted: true,
compact: false,
});
diag.verbose(resourceDebugString);
}
});
};
//# sourceMappingURL=detect-resources.js.map
{"version":3,"file":"detect-resources.js","sourceRoot":"","sources":["../../../../src/platform/node/detect-resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,CAAC,IAAM,eAAe,GAAG,UAC7B,MAAoC;IAApC,uBAAA,EAAA,WAAoC;;;;;;oBAE9B,cAAc,GAA4B,MAAM,CAAC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mBAAmB,CAAC,CAAC;SACnC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,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 { Resource } from '../../Resource';\nimport { ResourceDetectionConfig } from '../../config';\nimport { diag } from '@opentelemetry/api';\nimport * as util from 'util';\n\n/**\n * Runs all resource detectors and returns the results merged into a single\n * Resource.\n *\n * @param config Configuration for resource detection\n */\nexport const detectResources = async (\n config: ResourceDetectionConfig = {}\n): Promise<Resource> => {\n const internalConfig: ResourceDetectionConfig = Object.assign(config);\n\n const resources: Array<Resource> = await Promise.all(\n (internalConfig.detectors || []).map(async d => {\n try {\n const resource = await d.detect(internalConfig);\n diag.debug(`${d.constructor.name} found resource.`, resource);\n return resource;\n } catch (e) {\n diag.debug(`${d.constructor.name} failed: ${e.message}`);\n return Resource.empty();\n }\n })\n );\n\n // Future check if verbose logging is enabled issue #1903\n logResources(resources);\n\n return resources.reduce(\n (acc, resource) => acc.merge(resource),\n Resource.empty()\n );\n};\n\n/**\n * Writes debug information about the detected resources to the logger defined in the resource detection config, if one is provided.\n *\n * @param resources The array of {@link Resource} that should be logged. Empty entried will be ignored.\n */\nconst logResources = (resources: Array<Resource>) => {\n resources.forEach(resource => {\n // Print only populated resources\n if (Object.keys(resource.attributes).length > 0) {\n const resourceDebugString = util.inspect(resource.attributes, {\n depth: 2,\n breakLength: Infinity,\n sorted: true,\n compact: false,\n });\n diag.verbose(resourceDebugString);\n }\n });\n};\n"]}
import { Detector, Resource, ResourceDetectionConfig } from '../../../';
/**
* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_ATTRIBUTES environment variable.
*/
declare class EnvDetector implements Detector {
private readonly _MAX_LENGTH;
private readonly _COMMA_SEPARATOR;
private readonly _LABEL_KEY_VALUE_SPLITTER;
private readonly _ERROR_MESSAGE_INVALID_CHARS;
private readonly _ERROR_MESSAGE_INVALID_VALUE;
/**
* Returns a {@link Resource} populated with attributes from the
* OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async
* function to conform to the Detector interface.
*
* @param config The resource detection config
*/
detect(_config?: ResourceDetectionConfig): Promise<Resource>;
/**
* Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment
* variable.
*
* OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes describing
* the source in more detail, e.g. “key1=val1,key2=val2”. Domain names and
* paths are accepted as attribute keys. Values may be quoted or unquoted in
* general. If a value contains whitespaces, =, or " characters, it must
* always be quoted.
*
* @param rawEnvAttributes The resource attributes as a comma-seperated list
* of key/value pairs.
* @returns The sanitized resource attributes.
*/
private _parseResourceAttributes;
/**
* Determines whether the given String is a valid printable ASCII string with
* a length not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid.
*/
private _isValid;
private _isPrintableString;
/**
* Determines whether the given String is a valid printable ASCII string with
* a length greater than 0 and not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid and not empty.
*/
private _isValidAndNotEmpty;
}
export declare const envDetector: EnvDetector;
export {};
//# sourceMappingURL=EnvDetector.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { diag } from '@opentelemetry/api';
import { getEnv } from '@opentelemetry/core';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource, } from '../../../';
/**
* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_ATTRIBUTES environment variable.
*/
var EnvDetector = /** @class */ (function () {
function EnvDetector() {
// Type, attribute keys, and attribute values should not exceed 256 characters.
this._MAX_LENGTH = 255;
// OTEL_RESOURCE_ATTRIBUTES is a comma-separated list of attributes.
this._COMMA_SEPARATOR = ',';
// OTEL_RESOURCE_ATTRIBUTES contains key value pair separated by '='.
this._LABEL_KEY_VALUE_SPLITTER = '=';
this._ERROR_MESSAGE_INVALID_CHARS = 'should be a ASCII string with a length greater than 0 and not exceed ' +
this._MAX_LENGTH +
' characters.';
this._ERROR_MESSAGE_INVALID_VALUE = 'should be a ASCII string with a length not exceed ' +
this._MAX_LENGTH +
' characters.';
}
/**
* Returns a {@link Resource} populated with attributes from the
* OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async
* function to conform to the Detector interface.
*
* @param config The resource detection config
*/
EnvDetector.prototype.detect = function (_config) {
return __awaiter(this, void 0, void 0, function () {
var attributes, env, rawAttributes, serviceName, parsedAttributes;
return __generator(this, function (_a) {
attributes = {};
env = getEnv();
rawAttributes = env.OTEL_RESOURCE_ATTRIBUTES;
serviceName = env.OTEL_SERVICE_NAME;
if (rawAttributes) {
try {
parsedAttributes = this._parseResourceAttributes(rawAttributes);
Object.assign(attributes, parsedAttributes);
}
catch (e) {
diag.debug("EnvDetector failed: " + e.message);
}
}
if (serviceName) {
attributes[SemanticResourceAttributes.SERVICE_NAME] = serviceName;
}
return [2 /*return*/, new Resource(attributes)];
});
});
};
/**
* Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment
* variable.
*
* OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes describing
* the source in more detail, e.g. “key1=val1,key2=val2”. Domain names and
* paths are accepted as attribute keys. Values may be quoted or unquoted in
* general. If a value contains whitespaces, =, or " characters, it must
* always be quoted.
*
* @param rawEnvAttributes The resource attributes as a comma-seperated list
* of key/value pairs.
* @returns The sanitized resource attributes.
*/
EnvDetector.prototype._parseResourceAttributes = function (rawEnvAttributes) {
if (!rawEnvAttributes)
return {};
var attributes = {};
var rawAttributes = rawEnvAttributes.split(this._COMMA_SEPARATOR, -1);
for (var _i = 0, rawAttributes_1 = rawAttributes; _i < rawAttributes_1.length; _i++) {
var rawAttribute = rawAttributes_1[_i];
var keyValuePair = rawAttribute.split(this._LABEL_KEY_VALUE_SPLITTER, -1);
if (keyValuePair.length !== 2) {
continue;
}
var key = keyValuePair[0], value = keyValuePair[1];
// Leading and trailing whitespaces are trimmed.
key = key.trim();
value = value.trim().split('^"|"$').join('');
if (!this._isValidAndNotEmpty(key)) {
throw new Error("Attribute key " + this._ERROR_MESSAGE_INVALID_CHARS);
}
if (!this._isValid(value)) {
throw new Error("Attribute value " + this._ERROR_MESSAGE_INVALID_VALUE);
}
attributes[key] = value;
}
return attributes;
};
/**
* Determines whether the given String is a valid printable ASCII string with
* a length not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid.
*/
EnvDetector.prototype._isValid = function (name) {
return name.length <= this._MAX_LENGTH && this._isPrintableString(name);
};
EnvDetector.prototype._isPrintableString = function (str) {
for (var i = 0; i < str.length; i++) {
var ch = str.charAt(i);
if (ch <= ' ' || ch >= '~') {
return false;
}
}
return true;
};
/**
* Determines whether the given String is a valid printable ASCII string with
* a length greater than 0 and not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid and not empty.
*/
EnvDetector.prototype._isValidAndNotEmpty = function (str) {
return str.length > 0 && this._isValid(str);
};
return EnvDetector;
}());
export var envDetector = new EnvDetector();
//# sourceMappingURL=EnvDetector.js.map
{"version":3,"file":"EnvDetector.js","sourceRoot":"","sources":["../../../../../src/platform/node/detectors/EnvDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO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IAEO,wCAAkB,GAA1B,UAA2B,GAAW;QACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,IAAM,EAAE,GAAW,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI,GAAG,EAAE;gBAC1B,OAAO,KAAK,CAAC;aACd;SACF;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;OAMG;IACK,yCAAmB,GAA3B,UAA4B,GAAW;QACrC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IACH,kBAAC;AAAD,CAAC,AAhID,IAgIC;AAED,MAAM,CAAC,IAAM,WAAW,GAAG,IAAI,WAAW,EAAE,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 } from '@opentelemetry/api';\nimport { getEnv } from '@opentelemetry/core';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport {\n Detector,\n Resource,\n ResourceDetectionConfig,\n ResourceAttributes,\n} from '../../../';\n\n/**\n * EnvDetector can be used to detect the presence of and create a Resource\n * from the OTEL_RESOURCE_ATTRIBUTES environment variable.\n */\nclass EnvDetector implements Detector {\n // Type, attribute keys, and attribute values should not exceed 256 characters.\n private readonly _MAX_LENGTH = 255;\n\n // OTEL_RESOURCE_ATTRIBUTES is a comma-separated list of attributes.\n private readonly _COMMA_SEPARATOR = ',';\n\n // OTEL_RESOURCE_ATTRIBUTES contains key value pair separated by '='.\n private readonly _LABEL_KEY_VALUE_SPLITTER = '=';\n\n private readonly _ERROR_MESSAGE_INVALID_CHARS =\n 'should be a ASCII string with a length greater than 0 and not exceed ' +\n this._MAX_LENGTH +\n ' characters.';\n\n private readonly _ERROR_MESSAGE_INVALID_VALUE =\n 'should be a ASCII string with a length not exceed ' +\n this._MAX_LENGTH +\n ' characters.';\n\n /**\n * Returns a {@link Resource} populated with attributes from the\n * OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async\n * function to conform to the Detector interface.\n *\n * @param config The resource detection config\n */\n async detect(_config?: ResourceDetectionConfig): Promise<Resource> {\n const attributes: ResourceAttributes = {};\n const env = getEnv();\n\n const rawAttributes = env.OTEL_RESOURCE_ATTRIBUTES;\n const serviceName = env.OTEL_SERVICE_NAME;\n\n if (rawAttributes) {\n try {\n const parsedAttributes = this._parseResourceAttributes(rawAttributes);\n Object.assign(attributes, parsedAttributes);\n } catch (e) {\n diag.debug(`EnvDetector failed: ${e.message}`);\n }\n }\n\n if (serviceName) {\n attributes[SemanticResourceAttributes.SERVICE_NAME] = serviceName;\n }\n\n return new Resource(attributes);\n }\n\n /**\n * Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment\n * variable.\n *\n * OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes describing\n * the source in more detail, e.g. “key1=val1,key2=val2”. Domain names and\n * paths are accepted as attribute keys. Values may be quoted or unquoted in\n * general. If a value contains whitespaces, =, or \" characters, it must\n * always be quoted.\n *\n * @param rawEnvAttributes The resource attributes as a comma-seperated list\n * of key/value pairs.\n * @returns The sanitized resource attributes.\n */\n private _parseResourceAttributes(\n rawEnvAttributes?: string\n ): ResourceAttributes {\n if (!rawEnvAttributes) return {};\n\n const attributes: ResourceAttributes = {};\n const rawAttributes: string[] = rawEnvAttributes.split(\n this._COMMA_SEPARATOR,\n -1\n );\n for (const rawAttribute of rawAttributes) {\n const keyValuePair: string[] = rawAttribute.split(\n this._LABEL_KEY_VALUE_SPLITTER,\n -1\n );\n if (keyValuePair.length !== 2) {\n continue;\n }\n let [key, value] = keyValuePair;\n // Leading and trailing whitespaces are trimmed.\n key = key.trim();\n value = value.trim().split('^\"|\"$').join('');\n if (!this._isValidAndNotEmpty(key)) {\n throw new Error(`Attribute key ${this._ERROR_MESSAGE_INVALID_CHARS}`);\n }\n if (!this._isValid(value)) {\n throw new Error(`Attribute value ${this._ERROR_MESSAGE_INVALID_VALUE}`);\n }\n attributes[key] = value;\n }\n return attributes;\n }\n\n /**\n * Determines whether the given String is a valid printable ASCII string with\n * a length not exceed _MAX_LENGTH characters.\n *\n * @param str The String to be validated.\n * @returns Whether the String is valid.\n */\n private _isValid(name: string): boolean {\n return name.length <= this._MAX_LENGTH && this._isPrintableString(name);\n }\n\n private _isPrintableString(str: string): boolean {\n for (let i = 0; i < str.length; i++) {\n const ch: string = str.charAt(i);\n if (ch <= ' ' || ch >= '~') {\n return false;\n }\n }\n return true;\n }\n\n /**\n * Determines whether the given String is a valid printable ASCII string with\n * a length greater than 0 and not exceed _MAX_LENGTH characters.\n *\n * @param str The String to be validated.\n * @returns Whether the String is valid and not empty.\n */\n private _isValidAndNotEmpty(str: string): boolean {\n return str.length > 0 && this._isValid(str);\n }\n}\n\nexport const envDetector = new EnvDetector();\n"]}
export * from './EnvDetector';
export * from './ProcessDetector';
//# sourceMappingURL=index.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './EnvDetector';
export * from './ProcessDetector';
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/platform/node/detectors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,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\nexport * from './EnvDetector';\nexport * from './ProcessDetector';\n"]}
import { Detector, Resource, ResourceDetectionConfig } from '../../../';
/**
* ProcessDetector will be used to detect the resources related current process running
* and being instrumented from the NodeJS Process module.
*/
declare class ProcessDetector implements Detector {
detect(config?: ResourceDetectionConfig): Promise<Resource>;
/**
* Validates process resource attribute map from process varaibls
*
* @param processResource The unsantized resource attributes from process as key/value pairs.
* @param config: Config
* @returns The sanitized resource attributes.
*/
private _getResourceAttributes;
}
export declare const processDetector: ProcessDetector;
export {};
//# sourceMappingURL=ProcessDetector.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { diag } from '@opentelemetry/api';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../../../';
/**
* ProcessDetector will be used to detect the resources related current process running
* and being instrumented from the NodeJS Process module.
*/
var ProcessDetector = /** @class */ (function () {
function ProcessDetector() {
}
ProcessDetector.prototype.detect = function (config) {
return __awaiter(this, void 0, void 0, function () {
var processResource;
var _a;
return __generator(this, function (_b) {
processResource = (_a = {},
_a[SemanticResourceAttributes.PROCESS_PID] = process.pid,
_a[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME] = process.title || '',
_a[SemanticResourceAttributes.PROCESS_COMMAND] = process.argv[1] || '',
_a[SemanticResourceAttributes.PROCESS_COMMAND_LINE] = process.argv.join(' ') || '',
_a);
return [2 /*return*/, this._getResourceAttributes(processResource, config)];
});
});
};
/**
* Validates process resource attribute map from process varaibls
*
* @param processResource The unsantized resource attributes from process as key/value pairs.
* @param config: Config
* @returns The sanitized resource attributes.
*/
ProcessDetector.prototype._getResourceAttributes = function (processResource, _config) {
if (processResource[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME] ===
'' ||
processResource[SemanticResourceAttributes.PROCESS_EXECUTABLE_PATH] ===
'' ||
processResource[SemanticResourceAttributes.PROCESS_COMMAND] === '' ||
processResource[SemanticResourceAttributes.PROCESS_COMMAND_LINE] === '') {
diag.debug('ProcessDetector failed: Unable to find required process resources. ');
return Resource.empty();
}
else {
return new Resource(__assign({}, processResource));
}
};
return ProcessDetector;
}());
export var processDetector = new ProcessDetector();
//# sourceMappingURL=ProcessDetector.js.map
{"version":3,"file":"ProcessDetector.js","sourceRoot":"","sources":["../../../../../src/platform/node/detectors/ProcessDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAY,QAAQ,EAA2B,MAAM,WAAW,CAAC;AAGxE;;;GAGG;AACH;IAAA;IAwCA,CAAC;IAvCO,gCAAM,GAAZ,UAAa,MAAgC;;;;;gBACrC,eAAe;oBACnB,GAAC,0BAA0B,CAAC,WAAW,IAAG,OAAO,CAAC,GAAG;oBACrD,GAAC,0BAA0B,CAAC,uBAAuB,IAAG,OAAO,CAAC,KAAK,IAAI,EAAE;oBACzE,GAAC,0BAA0B,CAAC,eAAe,IAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;oBACnE,GAAC,0BAA0B,CAAC,oBAAoB,IAC9C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;uBAC/B,CAAC;gBACF,sBAAO,IAAI,CAAC,sBAAsB,CAAC,eAAe,EAAE,MAAM,CAAC,EAAC;;;KAC7D;IACD;;;;;;OAMG;IACK,gDAAsB,GAA9B,UACE,eAAmC,EACnC,OAAiC;QAEjC,IACE,eAAe,CAAC,0BAA0B,CAAC,uBAAuB,CAAC;YACjE,EAAE;YACJ,eAAe,CAAC,0BAA0B,CAAC,uBAAuB,CAAC;gBACjE,EAAE;YACJ,eAAe,CAAC,0BAA0B,CAAC,eAAe,CAAC,KAAK,EAAE;YAClE,eAAe,CAAC,0BAA0B,CAAC,oBAAoB,CAAC,KAAK,EAAE,EACvE;YACA,IAAI,CAAC,KAAK,CACR,qEAAqE,CACtE,CAAC;YACF,OAAO,QAAQ,CAAC,KAAK,EAAE,CAAC;SACzB;aAAM;YACL,OAAO,IAAI,QAAQ,cACd,eAAe,EAClB,CAAC;SACJ;IACH,CAAC;IACH,sBAAC;AAAD,CAAC,AAxCD,IAwCC;AAED,MAAM,CAAC,IAAM,eAAe,GAAG,IAAI,eAAe,EAAE,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 } from '@opentelemetry/api';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { Detector, Resource, ResourceDetectionConfig } from '../../../';\nimport { ResourceAttributes } from '../../../types';\n\n/**\n * ProcessDetector will be used to detect the resources related current process running\n * and being instrumented from the NodeJS Process module.\n */\nclass ProcessDetector implements Detector {\n async detect(config?: ResourceDetectionConfig): Promise<Resource> {\n const processResource: ResourceAttributes = {\n [SemanticResourceAttributes.PROCESS_PID]: process.pid,\n [SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME]: process.title || '',\n [SemanticResourceAttributes.PROCESS_COMMAND]: process.argv[1] || '',\n [SemanticResourceAttributes.PROCESS_COMMAND_LINE]:\n process.argv.join(' ') || '',\n };\n return this._getResourceAttributes(processResource, config);\n }\n /**\n * Validates process resource attribute map from process varaibls\n *\n * @param processResource The unsantized resource attributes from process as key/value pairs.\n * @param config: Config\n * @returns The sanitized resource attributes.\n */\n private _getResourceAttributes(\n processResource: ResourceAttributes,\n _config?: ResourceDetectionConfig\n ) {\n if (\n processResource[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME] ===\n '' ||\n processResource[SemanticResourceAttributes.PROCESS_EXECUTABLE_PATH] ===\n '' ||\n processResource[SemanticResourceAttributes.PROCESS_COMMAND] === '' ||\n processResource[SemanticResourceAttributes.PROCESS_COMMAND_LINE] === ''\n ) {\n diag.debug(\n 'ProcessDetector failed: Unable to find required process resources. '\n );\n return Resource.empty();\n } else {\n return new Resource({\n ...processResource,\n });\n }\n }\n}\n\nexport const processDetector = new ProcessDetector();\n"]}
export * from './default-service-name';
export * from './detect-resources';
export * from './detectors';
//# sourceMappingURL=index.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './default-service-name';
export * from './detect-resources';
export * from './detectors';
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/platform/node/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,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\nexport * from './default-service-name';\nexport * from './detect-resources';\nexport * from './detectors';\n"]}
import { ResourceAttributes } from './types';
/**
* A Resource describes the entity for which a signals (metrics or trace) are
* collected.
*/
export declare class Resource {
/**
* A dictionary of attributes with string keys and values that provide
* information about the entity as numbers, strings or booleans
* TODO: Consider to add check/validation on attributes.
*/
readonly attributes: ResourceAttributes;
static readonly EMPTY: Resource;
/**
* Returns an empty Resource
*/
static empty(): Resource;
/**
* Returns a Resource that indentifies the SDK in use.
*/
static default(): Resource;
constructor(
/**
* A dictionary of attributes with string keys and values that provide
* information about the entity as numbers, strings or booleans
* TODO: Consider to add check/validation on attributes.
*/
attributes: ResourceAttributes);
/**
* Returns a new, merged {@link Resource} by merging the current Resource
* with the other Resource. In case of a collision, other Resource takes
* precedence.
*
* @param other the Resource that will be merged with this.
* @returns the newly merged Resource.
*/
merge(other: Resource | null): Resource;
}
//# sourceMappingURL=Resource.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { SDK_INFO } from '@opentelemetry/core';
import { defaultServiceName } from './platform';
/**
* A Resource describes the entity for which a signals (metrics or trace) are
* collected.
*/
var Resource = /** @class */ (function () {
function Resource(
/**
* A dictionary of attributes with string keys and values that provide
* information about the entity as numbers, strings or booleans
* TODO: Consider to add check/validation on attributes.
*/
attributes) {
this.attributes = attributes;
}
/**
* Returns an empty Resource
*/
Resource.empty = function () {
return Resource.EMPTY;
};
/**
* Returns a Resource that indentifies the SDK in use.
*/
Resource.default = function () {
var _a;
return new Resource((_a = {},
_a[SemanticResourceAttributes.SERVICE_NAME] = defaultServiceName(),
_a[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE] = SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE],
_a[SemanticResourceAttributes.TELEMETRY_SDK_NAME] = SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_NAME],
_a[SemanticResourceAttributes.TELEMETRY_SDK_VERSION] = SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_VERSION],
_a));
};
/**
* Returns a new, merged {@link Resource} by merging the current Resource
* with the other Resource. In case of a collision, other Resource takes
* precedence.
*
* @param other the Resource that will be merged with this.
* @returns the newly merged Resource.
*/
Resource.prototype.merge = function (other) {
if (!other || !Object.keys(other.attributes).length)
return this;
// SpanAttributes from resource overwrite attributes from other resource.
var mergedAttributes = Object.assign({}, this.attributes, other.attributes);
return new Resource(mergedAttributes);
};
Resource.EMPTY = new Resource({});
return Resource;
}());
export { Resource };
//# sourceMappingURL=Resource.js.map
{"version":3,"file":"Resource.js","sourceRoot":"","sources":["../../src/Resource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD;;;GAGG;AACH;IAyBE;IACE;;;;OAIG;IACM,UAA8B;QAA9B,eAAU,GAAV,UAAU,CAAoB;IACtC,CAAC;IA7BJ;;OAEG;IACI,cAAK,GAAZ;QACE,OAAO,QAAQ,CAAC,KAAK,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,gBAAO,GAAd;;QACE,OAAO,IAAI,QAAQ;YACjB,GAAC,0BAA0B,CAAC,YAAY,IAAG,kBAAkB,EAAE;YAC/D,GAAC,0BAA0B,CAAC,sBAAsB,IAChD,QAAQ,CAAC,0BAA0B,CAAC,sBAAsB,CAAC;YAC7D,GAAC,0BAA0B,CAAC,kBAAkB,IAC5C,QAAQ,CAAC,0BAA0B,CAAC,kBAAkB,CAAC;YACzD,GAAC,0BAA0B,CAAC,qBAAqB,IAC/C,QAAQ,CAAC,0BAA0B,CAAC,qBAAqB,CAAC;gBAC5D,CAAA;IACJ,CAAC;IAWD;;;;;;;OAOG;IACH,wBAAK,GAAL,UAAM,KAAsB;QAC1B,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;QAEjE,yEAAyE;QACzE,IAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CACpC,EAAE,EACF,IAAI,CAAC,UAAU,EACf,KAAK,CAAC,UAAU,CACjB,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACxC,CAAC;IAnDe,cAAK,GAAG,IAAI,QAAQ,CAAC,EAAE,CAAC,CAAC;IAoD3C,eAAC;CAAA,AArDD,IAqDC;SArDY,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 { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { SDK_INFO } from '@opentelemetry/core';\nimport { ResourceAttributes } from './types';\nimport { defaultServiceName } from './platform';\n\n/**\n * A Resource describes the entity for which a signals (metrics or trace) are\n * collected.\n */\nexport class Resource {\n static readonly EMPTY = new Resource({});\n\n /**\n * Returns an empty Resource\n */\n static empty(): Resource {\n return Resource.EMPTY;\n }\n\n /**\n * Returns a Resource that indentifies the SDK in use.\n */\n static default(): Resource {\n return new Resource({\n [SemanticResourceAttributes.SERVICE_NAME]: defaultServiceName(),\n [SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE]:\n SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_LANGUAGE],\n [SemanticResourceAttributes.TELEMETRY_SDK_NAME]:\n SDK_INFO[SemanticResourceAttributes.TELEMETRY_SDK_NAME],\n [SemanticResourceAttributes.TELEMETRY_SDK_VERSION]:\n SDK_INFO[SemanticResourceAttributes.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 readonly attributes: ResourceAttributes\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: Resource | null): Resource {\n if (!other || !Object.keys(other.attributes).length) return this;\n\n // SpanAttributes from resource overwrite attributes from other resource.\n const mergedAttributes = Object.assign(\n {},\n this.attributes,\n other.attributes\n );\n return new Resource(mergedAttributes);\n }\n}\n"]}
import { Resource } from './Resource';
import { ResourceDetectionConfig } from './config';
/** Interface for Resource attributes */
export interface ResourceAttributes {
[key: string]: number | string | boolean;
}
/**
* Interface for a Resource Detector. In order to detect resources in parallel
* a detector returns a Promise containing a Resource.
*/
export interface Detector {
detect(config?: ResourceDetectionConfig): Promise<Resource>;
}
//# sourceMappingURL=types.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export {};
//# sourceMappingURL=types.js.map
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","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 { Resource } from './Resource';\nimport { ResourceDetectionConfig } from './config';\n\n/** Interface for Resource attributes */\nexport interface ResourceAttributes {\n [key: string]: number | string | boolean;\n}\n\n/**\n * Interface for a Resource Detector. In order to detect resources in parallel\n * a detector returns a Promise containing a Resource.\n */\nexport interface Detector {\n detect(config?: ResourceDetectionConfig): Promise<Resource>;\n}\n"]}
export declare const VERSION = "1.0.1";
//# sourceMappingURL=version.d.ts.map
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// this is autogenerated file, see scripts/version-update.js
export var VERSION = '1.0.1';
//# sourceMappingURL=version.js.map
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,OAAO,GAAG,OAAO,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\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.0.1';\n"]}
import { Detector, Resource, ResourceDetectionConfig } from '../../../';
/**
* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_ATTRIBUTES environment variable.
*/
declare class EnvDetector implements Detector {
private readonly _MAX_LENGTH;
private readonly _COMMA_SEPARATOR;
private readonly _LABEL_KEY_VALUE_SPLITTER;
private readonly _ERROR_MESSAGE_INVALID_CHARS;
private readonly _ERROR_MESSAGE_INVALID_VALUE;
/**
* Returns a {@link Resource} populated with attributes from the
* OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async
* function to conform to the Detector interface.
*
* @param config The resource detection config
*/
detect(_config?: ResourceDetectionConfig): Promise<Resource>;
/**
* Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment
* variable.
*
* OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes describing
* the source in more detail, e.g. “key1=val1,key2=val2”. Domain names and
* paths are accepted as attribute keys. Values may be quoted or unquoted in
* general. If a value contains whitespaces, =, or " characters, it must
* always be quoted.
*
* @param rawEnvAttributes The resource attributes as a comma-seperated list
* of key/value pairs.
* @returns The sanitized resource attributes.
*/
private _parseResourceAttributes;
/**
* Determines whether the given String is a valid printable ASCII string with
* a length not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid.
*/
private _isValid;
private _isPrintableString;
/**
* Determines whether the given String is a valid printable ASCII string with
* a length greater than 0 and not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid and not empty.
*/
private _isValidAndNotEmpty;
}
export declare const envDetector: EnvDetector;
export {};
//# sourceMappingURL=EnvDetector.d.ts.map
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.envDetector = void 0;
const api_1 = require("@opentelemetry/api");
const core_1 = require("@opentelemetry/core");
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const __1 = require("../../../");
/**
* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_ATTRIBUTES environment variable.
*/
class EnvDetector {
constructor() {
// Type, attribute keys, and attribute values should not exceed 256 characters.
this._MAX_LENGTH = 255;
// OTEL_RESOURCE_ATTRIBUTES is a comma-separated list of attributes.
this._COMMA_SEPARATOR = ',';
// OTEL_RESOURCE_ATTRIBUTES contains key value pair separated by '='.
this._LABEL_KEY_VALUE_SPLITTER = '=';
this._ERROR_MESSAGE_INVALID_CHARS = 'should be a ASCII string with a length greater than 0 and not exceed ' +
this._MAX_LENGTH +
' characters.';
this._ERROR_MESSAGE_INVALID_VALUE = 'should be a ASCII string with a length not exceed ' +
this._MAX_LENGTH +
' characters.';
}
/**
* Returns a {@link Resource} populated with attributes from the
* OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async
* function to conform to the Detector interface.
*
* @param config The resource detection config
*/
async detect(_config) {
const attributes = {};
const env = core_1.getEnv();
const rawAttributes = env.OTEL_RESOURCE_ATTRIBUTES;
const serviceName = env.OTEL_SERVICE_NAME;
if (rawAttributes) {
try {
const parsedAttributes = this._parseResourceAttributes(rawAttributes);
Object.assign(attributes, parsedAttributes);
}
catch (e) {
api_1.diag.debug(`EnvDetector failed: ${e.message}`);
}
}
if (serviceName) {
attributes[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME] = serviceName;
}
return new __1.Resource(attributes);
}
/**
* Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment
* variable.
*
* OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes describing
* the source in more detail, e.g. “key1=val1,key2=val2”. Domain names and
* paths are accepted as attribute keys. Values may be quoted or unquoted in
* general. If a value contains whitespaces, =, or " characters, it must
* always be quoted.
*
* @param rawEnvAttributes The resource attributes as a comma-seperated list
* of key/value pairs.
* @returns The sanitized resource attributes.
*/
_parseResourceAttributes(rawEnvAttributes) {
if (!rawEnvAttributes)
return {};
const attributes = {};
const rawAttributes = rawEnvAttributes.split(this._COMMA_SEPARATOR, -1);
for (const rawAttribute of rawAttributes) {
const keyValuePair = rawAttribute.split(this._LABEL_KEY_VALUE_SPLITTER, -1);
if (keyValuePair.length !== 2) {
continue;
}
let [key, value] = keyValuePair;
// Leading and trailing whitespaces are trimmed.
key = key.trim();
value = value.trim().split('^"|"$').join('');
if (!this._isValidAndNotEmpty(key)) {
throw new Error(`Attribute key ${this._ERROR_MESSAGE_INVALID_CHARS}`);
}
if (!this._isValid(value)) {
throw new Error(`Attribute value ${this._ERROR_MESSAGE_INVALID_VALUE}`);
}
attributes[key] = value;
}
return attributes;
}
/**
* Determines whether the given String is a valid printable ASCII string with
* a length not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid.
*/
_isValid(name) {
return name.length <= this._MAX_LENGTH && this._isPrintableString(name);
}
_isPrintableString(str) {
for (let i = 0; i < str.length; i++) {
const ch = str.charAt(i);
if (ch <= ' ' || ch >= '~') {
return false;
}
}
return true;
}
/**
* Determines whether the given String is a valid printable ASCII string with
* a length greater than 0 and not exceed _MAX_LENGTH characters.
*
* @param str The String to be validated.
* @returns Whether the String is valid and not empty.
*/
_isValidAndNotEmpty(str) {
return str.length > 0 && this._isValid(str);
}
}
exports.envDetector = new EnvDetector();
//# sourceMappingURL=EnvDetector.js.map
{"version":3,"file":"EnvDetector.js","sourceRoot":"","sources":["../../../../../src/platform/node/detectors/EnvDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAC1C,8CAA6C;AAC7C,8EAAiF;AACjF,iCAKmB;AAEnB;;;GAGG;AACH,MAAM,WAAW;IAAjB;QACE,+EAA+E;QAC9D,gBAAW,GAAG,GAAG,CAAC;QAEnC,oEAAoE;QACnD,qBAAgB,GAAG,GAAG,CAAC;QAExC,qEAAqE;QACpD,8BAAyB,GAAG,GAAG,CAAC;QAEhC,iCAA4B,GAC3C,uEAAuE;YACvE,IAAI,CAAC,WAAW;YAChB,cAAc,CAAC;QAEA,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AAW,GAAG,IAAI,WAAW,EAAE,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 } from '@opentelemetry/api';\nimport { getEnv } from '@opentelemetry/core';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport {\n Detector,\n Resource,\n ResourceDetectionConfig,\n ResourceAttributes,\n} from '../../../';\n\n/**\n * EnvDetector can be used to detect the presence of and create a Resource\n * from the OTEL_RESOURCE_ATTRIBUTES environment variable.\n */\nclass EnvDetector implements Detector {\n // Type, attribute keys, and attribute values should not exceed 256 characters.\n private readonly _MAX_LENGTH = 255;\n\n // OTEL_RESOURCE_ATTRIBUTES is a comma-separated list of attributes.\n private readonly _COMMA_SEPARATOR = ',';\n\n // OTEL_RESOURCE_ATTRIBUTES contains key value pair separated by '='.\n private readonly _LABEL_KEY_VALUE_SPLITTER = '=';\n\n private readonly _ERROR_MESSAGE_INVALID_CHARS =\n 'should be a ASCII string with a length greater than 0 and not exceed ' +\n this._MAX_LENGTH +\n ' characters.';\n\n private readonly _ERROR_MESSAGE_INVALID_VALUE =\n 'should be a ASCII string with a length not exceed ' +\n this._MAX_LENGTH +\n ' characters.';\n\n /**\n * Returns a {@link Resource} populated with attributes from the\n * OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async\n * function to conform to the Detector interface.\n *\n * @param config The resource detection config\n */\n async detect(_config?: ResourceDetectionConfig): Promise<Resource> {\n const attributes: ResourceAttributes = {};\n const env = getEnv();\n\n const rawAttributes = env.OTEL_RESOURCE_ATTRIBUTES;\n const serviceName = env.OTEL_SERVICE_NAME;\n\n if (rawAttributes) {\n try {\n const parsedAttributes = this._parseResourceAttributes(rawAttributes);\n Object.assign(attributes, parsedAttributes);\n } catch (e) {\n diag.debug(`EnvDetector failed: ${e.message}`);\n }\n }\n\n if (serviceName) {\n attributes[SemanticResourceAttributes.SERVICE_NAME] = serviceName;\n }\n\n return new Resource(attributes);\n }\n\n /**\n * Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment\n * variable.\n *\n * OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes describing\n * the source in more detail, e.g. “key1=val1,key2=val2”. Domain names and\n * paths are accepted as attribute keys. Values may be quoted or unquoted in\n * general. If a value contains whitespaces, =, or \" characters, it must\n * always be quoted.\n *\n * @param rawEnvAttributes The resource attributes as a comma-seperated list\n * of key/value pairs.\n * @returns The sanitized resource attributes.\n */\n private _parseResourceAttributes(\n rawEnvAttributes?: string\n ): ResourceAttributes {\n if (!rawEnvAttributes) return {};\n\n const attributes: ResourceAttributes = {};\n const rawAttributes: string[] = rawEnvAttributes.split(\n this._COMMA_SEPARATOR,\n -1\n );\n for (const rawAttribute of rawAttributes) {\n const keyValuePair: string[] = rawAttribute.split(\n this._LABEL_KEY_VALUE_SPLITTER,\n -1\n );\n if (keyValuePair.length !== 2) {\n continue;\n }\n let [key, value] = keyValuePair;\n // Leading and trailing whitespaces are trimmed.\n key = key.trim();\n value = value.trim().split('^\"|\"$').join('');\n if (!this._isValidAndNotEmpty(key)) {\n throw new Error(`Attribute key ${this._ERROR_MESSAGE_INVALID_CHARS}`);\n }\n if (!this._isValid(value)) {\n throw new Error(`Attribute value ${this._ERROR_MESSAGE_INVALID_VALUE}`);\n }\n attributes[key] = value;\n }\n return attributes;\n }\n\n /**\n * Determines whether the given String is a valid printable ASCII string with\n * a length not exceed _MAX_LENGTH characters.\n *\n * @param str The String to be validated.\n * @returns Whether the String is valid.\n */\n private _isValid(name: string): boolean {\n return name.length <= this._MAX_LENGTH && this._isPrintableString(name);\n }\n\n private _isPrintableString(str: string): boolean {\n for (let i = 0; i < str.length; i++) {\n const ch: string = str.charAt(i);\n if (ch <= ' ' || ch >= '~') {\n return false;\n }\n }\n return true;\n }\n\n /**\n * Determines whether the given String is a valid printable ASCII string with\n * a length greater than 0 and not exceed _MAX_LENGTH characters.\n *\n * @param str The String to be validated.\n * @returns Whether the String is valid and not empty.\n */\n private _isValidAndNotEmpty(str: string): boolean {\n return str.length > 0 && this._isValid(str);\n }\n}\n\nexport const envDetector = new EnvDetector();\n"]}
export * from './EnvDetector';
export * from './ProcessDetector';
//# sourceMappingURL=index.d.ts.map
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./EnvDetector"), exports);
__exportStar(require("./ProcessDetector"), exports);
//# sourceMappingURL=index.js.map
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/platform/node/detectors/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;AAEH,gDAA8B;AAC9B,oDAAkC","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\nexport * from './EnvDetector';\nexport * from './ProcessDetector';\n"]}
import { Detector, Resource, ResourceDetectionConfig } from '../../../';
/**
* ProcessDetector will be used to detect the resources related current process running
* and being instrumented from the NodeJS Process module.
*/
declare class ProcessDetector implements Detector {
detect(config?: ResourceDetectionConfig): Promise<Resource>;
/**
* Validates process resource attribute map from process varaibls
*
* @param processResource The unsantized resource attributes from process as key/value pairs.
* @param config: Config
* @returns The sanitized resource attributes.
*/
private _getResourceAttributes;
}
export declare const processDetector: ProcessDetector;
export {};
//# sourceMappingURL=ProcessDetector.d.ts.map
"use strict";
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.processDetector = void 0;
const api_1 = require("@opentelemetry/api");
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const __1 = require("../../../");
/**
* ProcessDetector will be used to detect the resources related current process running
* and being instrumented from the NodeJS Process module.
*/
class ProcessDetector {
async detect(config) {
const processResource = {
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_PID]: process.pid,
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME]: process.title || '',
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_COMMAND]: process.argv[1] || '',
[semantic_conventions_1.SemanticResourceAttributes.PROCESS_COMMAND_LINE]: process.argv.join(' ') || '',
};
return this._getResourceAttributes(processResource, config);
}
/**
* Validates process resource attribute map from process varaibls
*
* @param processResource The unsantized resource attributes from process as key/value pairs.
* @param config: Config
* @returns The sanitized resource attributes.
*/
_getResourceAttributes(processResource, _config) {
if (processResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME] ===
'' ||
processResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_EXECUTABLE_PATH] ===
'' ||
processResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_COMMAND] === '' ||
processResource[semantic_conventions_1.SemanticResourceAttributes.PROCESS_COMMAND_LINE] === '') {
api_1.diag.debug('ProcessDetector failed: Unable to find required process resources. ');
return __1.Resource.empty();
}
else {
return new __1.Resource(Object.assign({}, processResource));
}
}
}
exports.processDetector = new ProcessDetector();
//# sourceMappingURL=ProcessDetector.js.map
{"version":3,"file":"ProcessDetector.js","sourceRoot":"","sources":["../../../../../src/platform/node/detectors/ProcessDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAA0C;AAC1C,8EAAiF;AACjF,iCAAwE;AAGxE;;;GAGG;AACH,MAAM,eAAe;IACnB,KAAK,CAAC,MAAM,CAAC,MAAgC;QAC3C,MAAM,eAAe,GAAuB;YAC1C,CAAC,iDAA0B,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,GAAG;YACrD,CAAC,iDAA0B,CAAC,uBAAuB,CAAC,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;YACzE,CAAC,iDAA0B,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;YACnE,CAAC,iDAA0B,CAAC,oBAAoB,CAAC,EAC/C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;SAC/B,CAAC;QACF,OAAO,IAAI,CAAC,sBAAsB,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IACD;;;;;;OAMG;IACK,sBAAsB,CAC5B,eAAmC,EACnC,OAAiC;QAEjC,IACE,eAAe,CAAC,iDAA0B,CAAC,uBAAuB,CAAC;YACjE,EAAE;YACJ,eAAe,CAAC,iDAA0B,CAAC,uBAAuB,CAAC;gBACjE,EAAE;YACJ,eAAe,CAAC,iDAA0B,CAAC,eAAe,CAAC,KAAK,EAAE;YAClE,eAAe,CAAC,iDAA0B,CAAC,oBAAoB,CAAC,KAAK,EAAE,EACvE;YACA,UAAI,CAAC,KAAK,CACR,qEAAqE,CACtE,CAAC;YACF,OAAO,YAAQ,CAAC,KAAK,EAAE,CAAC;SACzB;aAAM;YACL,OAAO,IAAI,YAAQ,mBACd,eAAe,EAClB,CAAC;SACJ;IACH,CAAC;CACF;AAEY,QAAA,eAAe,GAAG,IAAI,eAAe,EAAE,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 } from '@opentelemetry/api';\nimport { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';\nimport { Detector, Resource, ResourceDetectionConfig } from '../../../';\nimport { ResourceAttributes } from '../../../types';\n\n/**\n * ProcessDetector will be used to detect the resources related current process running\n * and being instrumented from the NodeJS Process module.\n */\nclass ProcessDetector implements Detector {\n async detect(config?: ResourceDetectionConfig): Promise<Resource> {\n const processResource: ResourceAttributes = {\n [SemanticResourceAttributes.PROCESS_PID]: process.pid,\n [SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME]: process.title || '',\n [SemanticResourceAttributes.PROCESS_COMMAND]: process.argv[1] || '',\n [SemanticResourceAttributes.PROCESS_COMMAND_LINE]:\n process.argv.join(' ') || '',\n };\n return this._getResourceAttributes(processResource, config);\n }\n /**\n * Validates process resource attribute map from process varaibls\n *\n * @param processResource The unsantized resource attributes from process as key/value pairs.\n * @param config: Config\n * @returns The sanitized resource attributes.\n */\n private _getResourceAttributes(\n processResource: ResourceAttributes,\n _config?: ResourceDetectionConfig\n ) {\n if (\n processResource[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME] ===\n '' ||\n processResource[SemanticResourceAttributes.PROCESS_EXECUTABLE_PATH] ===\n '' ||\n processResource[SemanticResourceAttributes.PROCESS_COMMAND] === '' ||\n processResource[SemanticResourceAttributes.PROCESS_COMMAND_LINE] === ''\n ) {\n diag.debug(\n 'ProcessDetector failed: Unable to find required process resources. '\n );\n return Resource.empty();\n } else {\n return new Resource({\n ...processResource,\n });\n }\n }\n}\n\nexport const processDetector = new ProcessDetector();\n"]}