Socket
Socket
Sign inDemoInstall

@opentelemetry/resources

Package Overview
Dependencies
2
Maintainers
2
Versions
167
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.9.1 to 1.10.0

build/esm/detect-resources.d.ts

4

build/esm/config.d.ts

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

import type { Detector } from './types';
import type { Detector, DetectorSync } from './types';
/**

@@ -6,4 +6,4 @@ * ResourceDetectionConfig provides an interface for configuring resource auto-detection.

export interface ResourceDetectionConfig {
detectors?: Array<Detector>;
detectors?: Array<Detector | DetectorSync>;
}
//# sourceMappingURL=config.d.ts.map

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

import { Detector, Resource, ResourceDetectionConfig } from '..';
import { Detector, IResource, ResourceDetectionConfig } from '..';
/**

@@ -6,11 +6,3 @@ * 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;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -17,0 +9,0 @@ export declare const browserDetector: BrowserDetector;

@@ -16,52 +16,3 @@ /*

*/
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 '..';
import { browserDetectorSync, } from '..';
/**

@@ -74,35 +25,4 @@ * BrowserDetector will be used to detect the resources related to browser.

BrowserDetector.prototype.detect = function (config) {
return __awaiter(this, void 0, void 0, function () {
var isBrowser, browserResource;
var _a;
return __generator(this, function (_b) {
isBrowser = typeof navigator !== 'undefined';
if (!isBrowser) {
return [2 /*return*/, Resource.empty()];
}
browserResource = (_a = {},
_a[SemanticResourceAttributes.PROCESS_RUNTIME_NAME] = 'browser',
_a[SemanticResourceAttributes.PROCESS_RUNTIME_DESCRIPTION] = 'Web Browser',
_a[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] = navigator.userAgent,
_a);
return [2 /*return*/, this._getResourceAttributes(browserResource, config)];
});
});
return Promise.resolve(browserDetectorSync.detect(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.
*/
BrowserDetector.prototype._getResourceAttributes = function (browserResource, _config) {
if (browserResource[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] === '') {
diag.debug('BrowserDetector failed: Unable to find required browser resources. ');
return Resource.empty();
}
else {
return new Resource(__assign({}, browserResource));
}
};
return BrowserDetector;

@@ -109,0 +29,0 @@ }());

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

import { Resource } from '../Resource';
import { Detector } from '../types';
import { ResourceDetectionConfig } from '../config';
import { IResource } from '../IResource';
/**

@@ -9,7 +9,2 @@ * EnvDetector can be used to detect the presence of and create a Resource

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;
/**

@@ -22,35 +17,3 @@ * Returns a {@link Resource} populated with attributes from the

*/
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 _isBaggageOctetString;
/**
* 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;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -57,0 +20,0 @@ export declare const envDetector: EnvDetector;

@@ -16,69 +16,3 @@ /*

*/
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 };
}
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { diag } from '@opentelemetry/api';
import { getEnv } from '@opentelemetry/core';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../Resource';
import { envDetectorSync } from './EnvDetectorSync';
/**

@@ -90,14 +24,2 @@ * EnvDetector can be used to detect the presence of and create a Resource

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.';
}

@@ -111,105 +33,5 @@ /**

*/
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)];
});
});
EnvDetector.prototype.detect = function (config) {
return Promise.resolve(envDetectorSync.detect(config));
};
/**
* 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) {
var e_1, _a;
if (!rawEnvAttributes)
return {};
var attributes = {};
var rawAttributes = rawEnvAttributes.split(this._COMMA_SEPARATOR, -1);
try {
for (var rawAttributes_1 = __values(rawAttributes), rawAttributes_1_1 = rawAttributes_1.next(); !rawAttributes_1_1.done; rawAttributes_1_1 = rawAttributes_1.next()) {
var rawAttribute = rawAttributes_1_1.value;
var keyValuePair = rawAttribute.split(this._LABEL_KEY_VALUE_SPLITTER, -1);
if (keyValuePair.length !== 2) {
continue;
}
var _b = __read(keyValuePair, 2), key = _b[0], value = _b[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] = decodeURIComponent(value);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (rawAttributes_1_1 && !rawAttributes_1_1.done && (_a = rawAttributes_1.return)) _a.call(rawAttributes_1);
}
finally { if (e_1) throw e_1.error; }
}
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._isBaggageOctetString(name);
};
// https://www.w3.org/TR/baggage/#definition
EnvDetector.prototype._isBaggageOctetString = function (str) {
for (var i = 0; i < str.length; i++) {
var ch = str.charCodeAt(i);
if (ch < 0x21 || ch === 0x2c || ch === 0x3b || ch === 0x5c || ch > 0x7e) {
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;

@@ -216,0 +38,0 @@ }());

export * from './BrowserDetector';
export * from './EnvDetector';
export * from './ProcessDetector';
export * from './BrowserDetectorSync';
export * from './EnvDetectorSync';
export * from './ProcessDetectorSync';
//# sourceMappingURL=index.d.ts.map

@@ -19,2 +19,5 @@ /*

export * from './ProcessDetector';
export * from './BrowserDetectorSync';
export * from './EnvDetectorSync';
export * from './ProcessDetectorSync';
//# sourceMappingURL=index.js.map

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

import { Resource } from '../Resource';
import { Detector } from '../types';
import { IResource } from '../IResource';
export declare class NoopDetector implements Detector {
detect(): Promise<Resource>;
detect(): Promise<IResource>;
}
export declare const noopDetector: NoopDetector;
//# sourceMappingURL=NoopDetector.d.ts.map

@@ -16,39 +16,3 @@ /*

*/
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 { noopDetectorSync } from './NoopDetectorSync';
var NoopDetector = /** @class */ (function () {

@@ -58,7 +22,3 @@ function NoopDetector() {

NoopDetector.prototype.detect = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Resource({})];
});
});
return Promise.resolve(noopDetectorSync.detect());
};

@@ -65,0 +25,0 @@ return NoopDetector;

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

import { Resource } from '../Resource';
import { Detector } from '../types';
import { ResourceDetectionConfig } from '../config';
import { IResource } from '../IResource';
/**

@@ -9,11 +9,3 @@ * ProcessDetector will be used to detect the resources related current process running

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;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -20,0 +12,0 @@ export declare const processDetector: ProcessDetector;

@@ -16,52 +16,3 @@ /*

*/
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 '../Resource';
import { processDetectorSync } from './ProcessDetectorSync';
/**

@@ -75,45 +26,4 @@ * ProcessDetector will be used to detect the resources related current process running

ProcessDetector.prototype.detect = function (config) {
return __awaiter(this, void 0, void 0, function () {
var processResource;
var _a;
return __generator(this, function (_b) {
// Skip if not in Node.js environment.
if (typeof process !== 'object') {
return [2 /*return*/, Resource.empty()];
}
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[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] = process.versions.node,
_a[SemanticResourceAttributes.PROCESS_RUNTIME_NAME] = 'nodejs',
_a[SemanticResourceAttributes.PROCESS_RUNTIME_DESCRIPTION] = 'Node.js',
_a);
return [2 /*return*/, this._getResourceAttributes(processResource, config)];
});
});
return Promise.resolve(processDetectorSync.detect(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] === '' ||
processResource[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] === '') {
diag.debug('ProcessDetector failed: Unable to find required process resources. ');
return Resource.empty();
}
else {
return new Resource(__assign({}, processResource));
}
};
return ProcessDetector;

@@ -120,0 +30,0 @@ }());

export * from './Resource';
export * from './IResource';
export * from './platform';

@@ -6,2 +7,3 @@ export * from './types';

export * from './detectors';
export * from './detect-resources';
//# sourceMappingURL=index.d.ts.map

@@ -17,2 +17,3 @@ /*

export * from './Resource';
export * from './IResource';
export * from './platform';

@@ -22,2 +23,3 @@ export * from './types';

export * from './detectors';
export * from './detect-resources';
//# sourceMappingURL=index.js.map
export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.d.ts.map

@@ -17,5 +17,6 @@ /*

export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.js.map

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

import { Resource } from '../../Resource';
import { Detector } from '../../types';
import { ResourceDetectionConfig } from '../../config';
import { IResource } from '../../IResource';
/**

@@ -9,4 +9,3 @@ * HostDetector detects the resources related to the host current process is

declare class HostDetector implements Detector {
detect(_config?: ResourceDetectionConfig): Promise<Resource>;
private _normalizeArch;
detect(_config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -13,0 +12,0 @@ export declare const hostDetector: HostDetector;

@@ -16,41 +16,3 @@ /*

*/
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 { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../../Resource';
import { arch, hostname } from 'os';
import { hostDetectorSync } from './HostDetectorSync';
/**

@@ -64,28 +26,4 @@ * HostDetector detects the resources related to the host current process is

HostDetector.prototype.detect = function (_config) {
return __awaiter(this, void 0, void 0, function () {
var attributes;
var _a;
return __generator(this, function (_b) {
attributes = (_a = {},
_a[SemanticResourceAttributes.HOST_NAME] = hostname(),
_a[SemanticResourceAttributes.HOST_ARCH] = this._normalizeArch(arch()),
_a);
return [2 /*return*/, new Resource(attributes)];
});
});
return Promise.resolve(hostDetectorSync.detect(_config));
};
HostDetector.prototype._normalizeArch = function (nodeArchString) {
// Maps from https://nodejs.org/api/os.html#osarch to arch values in spec:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/host.md
switch (nodeArchString) {
case 'arm':
return 'arm32';
case 'ppc':
return 'ppc32';
case 'x64':
return 'amd64';
default:
return nodeArchString;
}
};
return HostDetector;

@@ -92,0 +30,0 @@ }());

export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.d.ts.map

@@ -17,5 +17,6 @@ /*

export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.js.map

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

import { Resource } from '../../Resource';
import { Detector } from '../../types';
import { ResourceDetectionConfig } from '../../config';
import { IResource } from '../../IResource';
/**

@@ -9,4 +9,3 @@ * OSDetector detects the resources related to the operating system (OS) on

declare class OSDetector implements Detector {
detect(_config?: ResourceDetectionConfig): Promise<Resource>;
private _normalizeType;
detect(_config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -13,0 +12,0 @@ export declare const osDetector: OSDetector;

@@ -16,41 +16,3 @@ /*

*/
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 { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../../Resource';
import { platform, release } from 'os';
import { osDetectorSync } from './OSDetectorSync';
/**

@@ -64,26 +26,4 @@ * OSDetector detects the resources related to the operating system (OS) on

OSDetector.prototype.detect = function (_config) {
return __awaiter(this, void 0, void 0, function () {
var attributes;
var _a;
return __generator(this, function (_b) {
attributes = (_a = {},
_a[SemanticResourceAttributes.OS_TYPE] = this._normalizeType(platform()),
_a[SemanticResourceAttributes.OS_VERSION] = release(),
_a);
return [2 /*return*/, new Resource(attributes)];
});
});
return Promise.resolve(osDetectorSync.detect(_config));
};
OSDetector.prototype._normalizeType = function (nodePlatform) {
// Maps from https://nodejs.org/api/os.html#osplatform to arch values in spec:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/os.md
switch (nodePlatform) {
case 'sunos':
return 'solaris';
case 'win32':
return 'windows';
default:
return nodePlatform;
}
};
return OSDetector;

@@ -90,0 +30,0 @@ }());

import { ResourceAttributes } from './types';
import { IResource } from './IResource';
/**

@@ -6,3 +7,3 @@ * A Resource describes the entity for which a signals (metrics or trace) are

*/
export declare class Resource {
export declare class Resource implements IResource {
/**

@@ -13,12 +14,21 @@ * A dictionary of attributes with string keys and values that provide

*/
readonly attributes: ResourceAttributes;
private _attributes;
static readonly EMPTY: Resource;
private _syncAttributes;
private _asyncAttributesPromise;
/**
* Check if async attributes have resolved. This is useful to avoid awaiting
* waitForAsyncAttributes (which will introduce asynchronous behavior) when not necessary.
*
* @returns true if the resource "attributes" property is not yet settled to its final value
*/
asyncAttributesPending: boolean;
/**
* Returns an empty Resource
*/
static empty(): Resource;
static empty(): IResource;
/**
* Returns a Resource that identifies the SDK in use.
*/
static default(): Resource;
static default(): IResource;
constructor(

@@ -30,4 +40,11 @@ /**

*/
attributes: ResourceAttributes);
_attributes: ResourceAttributes, asyncAttributesPromise?: Promise<ResourceAttributes>);
get attributes(): ResourceAttributes;
/**
* Returns a promise that will never be rejected. Resolves when all async attributes have finished being added to
* this Resource's attributes. This is useful in exporters to block until resource detection
* has finished.
*/
waitForAsyncAttributes(): Promise<void>;
/**
* Returns a new, merged {@link Resource} by merging the current Resource

@@ -40,4 +57,4 @@ * with the other Resource. In case of a collision, other Resource takes

*/
merge(other: Resource | null): Resource;
merge(other: IResource | null): IResource;
}
//# sourceMappingURL=Resource.d.ts.map

@@ -16,2 +16,66 @@ /*

*/
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 };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { diag } from '@opentelemetry/api';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

@@ -31,4 +95,16 @@ import { SDK_INFO } from '@opentelemetry/core';

*/
attributes) {
this.attributes = attributes;
_attributes, asyncAttributesPromise) {
var _this = this;
this._attributes = _attributes;
this.asyncAttributesPending = asyncAttributesPromise != null;
this._syncAttributes = _attributes;
this._asyncAttributesPromise = asyncAttributesPromise === null || asyncAttributesPromise === void 0 ? void 0 : asyncAttributesPromise.then(function (asyncAttributes) {
_this._attributes = Object.assign({}, _this._attributes, asyncAttributes);
_this.asyncAttributesPending = false;
return asyncAttributes;
}, function (err) {
diag.debug("a resource's async attributes promise rejected: %s", err);
_this.asyncAttributesPending = false;
return {};
});
}

@@ -53,3 +129,33 @@ /**

};
Object.defineProperty(Resource.prototype, "attributes", {
get: function () {
if (this.asyncAttributesPending) {
diag.error('Accessing resource attributes before async attributes settled');
}
return this._attributes;
},
enumerable: false,
configurable: true
});
/**
* Returns a promise that will never be rejected. Resolves when all async attributes have finished being added to
* this Resource's attributes. This is useful in exporters to block until resource detection
* has finished.
*/
Resource.prototype.waitForAsyncAttributes = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.asyncAttributesPending) return [3 /*break*/, 2];
return [4 /*yield*/, this._asyncAttributesPromise];
case 1:
_a.sent();
_a.label = 2;
case 2: return [2 /*return*/];
}
});
});
};
/**
* Returns a new, merged {@link Resource} by merging the current Resource

@@ -63,7 +169,21 @@ * with the other Resource. In case of a collision, other Resource takes

Resource.prototype.merge = function (other) {
if (!other || !Object.keys(other.attributes).length)
var _this = this;
var _a;
if (!other)
return this;
// SpanAttributes from resource overwrite attributes from other resource.
var mergedAttributes = Object.assign({}, this.attributes, other.attributes);
return new Resource(mergedAttributes);
// SpanAttributes from other resource overwrite attributes from this resource.
var mergedSyncAttributes = __assign(__assign({}, this._syncAttributes), ((_a = other._syncAttributes) !== null && _a !== void 0 ? _a : other.attributes));
if (!this._asyncAttributesPromise &&
!other._asyncAttributesPromise) {
return new Resource(mergedSyncAttributes);
}
var mergedAttributesPromise = Promise.all([
this._asyncAttributesPromise,
other._asyncAttributesPromise,
]).then(function (_a) {
var _b;
var _c = __read(_a, 2), thisAsyncAttributes = _c[0], otherAsyncAttributes = _c[1];
return __assign(__assign(__assign(__assign({}, _this._syncAttributes), thisAsyncAttributes), ((_b = other._syncAttributes) !== null && _b !== void 0 ? _b : other.attributes)), otherAsyncAttributes);
});
return new Resource(mergedSyncAttributes, mergedAttributesPromise);
};

@@ -70,0 +190,0 @@ Resource.EMPTY = new Resource({});

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

import { Resource } from './Resource';
import { ResourceDetectionConfig } from './config';
import { SpanAttributes } from '@opentelemetry/api';
import { IResource } from './IResource';
/**

@@ -11,8 +11,14 @@ * Interface for Resource attributes.

/**
* Interface for a Resource Detector. In order to detect resources in parallel
* a detector returns a Promise containing a Resource.
* @deprecated please use {@link DetectorSync}
*/
export interface Detector {
detect(config?: ResourceDetectionConfig): Promise<Resource>;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}
/**
* Interface for a synchronous Resource Detector. In order to detect attributes asynchronously, a detector
* can pass a Promise as the second parameter to the Resource constructor.
*/
export interface DetectorSync {
detect(config?: ResourceDetectionConfig): IResource;
}
//# sourceMappingURL=types.d.ts.map

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

export declare const VERSION = "1.9.1";
export declare const VERSION = "1.10.0";
//# sourceMappingURL=version.d.ts.map

@@ -17,3 +17,3 @@ /*

// this is autogenerated file, see scripts/version-update.js
export var VERSION = '1.9.1';
export var VERSION = '1.10.0';
//# sourceMappingURL=version.js.map

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

import type { Detector } from './types';
import type { Detector, DetectorSync } from './types';
/**

@@ -6,4 +6,4 @@ * ResourceDetectionConfig provides an interface for configuring resource auto-detection.

export interface ResourceDetectionConfig {
detectors?: Array<Detector>;
detectors?: Array<Detector | DetectorSync>;
}
//# sourceMappingURL=config.d.ts.map

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

import { Detector, Resource, ResourceDetectionConfig } from '..';
import { Detector, IResource, ResourceDetectionConfig } from '..';
/**

@@ -6,11 +6,3 @@ * 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;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -17,0 +9,0 @@ export declare const browserDetector: BrowserDetector;

@@ -16,5 +16,3 @@ /*

*/
import { diag } from '@opentelemetry/api';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '..';
import { browserDetectorSync, } from '..';
/**

@@ -24,32 +22,7 @@ * BrowserDetector will be used to detect the resources related to browser.

class BrowserDetector {
async detect(config) {
const isBrowser = typeof navigator !== 'undefined';
if (!isBrowser) {
return Resource.empty();
}
const browserResource = {
[SemanticResourceAttributes.PROCESS_RUNTIME_NAME]: 'browser',
[SemanticResourceAttributes.PROCESS_RUNTIME_DESCRIPTION]: 'Web Browser',
[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION]: navigator.userAgent,
};
return this._getResourceAttributes(browserResource, config);
detect(config) {
return Promise.resolve(browserDetectorSync.detect(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[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] === '') {
diag.debug('BrowserDetector failed: Unable to find required browser resources. ');
return Resource.empty();
}
else {
return new Resource(Object.assign({}, browserResource));
}
}
}
export const browserDetector = new BrowserDetector();
//# sourceMappingURL=BrowserDetector.js.map

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

import { Resource } from '../Resource';
import { Detector } from '../types';
import { ResourceDetectionConfig } from '../config';
import { IResource } from '../IResource';
/**

@@ -9,7 +9,2 @@ * EnvDetector can be used to detect the presence of and create a Resource

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;
/**

@@ -22,35 +17,3 @@ * Returns a {@link Resource} populated with attributes from the

*/
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 _isBaggageOctetString;
/**
* 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;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -57,0 +20,0 @@ export declare const envDetector: EnvDetector;

@@ -16,6 +16,3 @@ /*

*/
import { diag } from '@opentelemetry/api';
import { getEnv } from '@opentelemetry/core';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../Resource';
import { envDetectorSync } from './EnvDetectorSync';
/**

@@ -26,16 +23,2 @@ * EnvDetector can be used to detect the presence of and create a Resource

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.';
}
/**

@@ -48,91 +31,7 @@ * Returns a {@link Resource} populated with attributes from the

*/
async detect(_config) {
const attributes = {};
const env = 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) {
diag.debug(`EnvDetector failed: ${e.message}`);
}
}
if (serviceName) {
attributes[SemanticResourceAttributes.SERVICE_NAME] = serviceName;
}
return new Resource(attributes);
detect(config) {
return Promise.resolve(envDetectorSync.detect(config));
}
/**
* 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] = decodeURIComponent(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._isBaggageOctetString(name);
}
// https://www.w3.org/TR/baggage/#definition
_isBaggageOctetString(str) {
for (let i = 0; i < str.length; i++) {
const ch = str.charCodeAt(i);
if (ch < 0x21 || ch === 0x2c || ch === 0x3b || ch === 0x5c || ch > 0x7e) {
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);
}
}
export const envDetector = new EnvDetector();
//# sourceMappingURL=EnvDetector.js.map
export * from './BrowserDetector';
export * from './EnvDetector';
export * from './ProcessDetector';
export * from './BrowserDetectorSync';
export * from './EnvDetectorSync';
export * from './ProcessDetectorSync';
//# sourceMappingURL=index.d.ts.map

@@ -19,2 +19,5 @@ /*

export * from './ProcessDetector';
export * from './BrowserDetectorSync';
export * from './EnvDetectorSync';
export * from './ProcessDetectorSync';
//# sourceMappingURL=index.js.map

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

import { Resource } from '../Resource';
import { Detector } from '../types';
import { IResource } from '../IResource';
export declare class NoopDetector implements Detector {
detect(): Promise<Resource>;
detect(): Promise<IResource>;
}
export declare const noopDetector: NoopDetector;
//# sourceMappingURL=NoopDetector.d.ts.map

@@ -16,6 +16,6 @@ /*

*/
import { Resource } from '../Resource';
import { noopDetectorSync } from './NoopDetectorSync';
export class NoopDetector {
async detect() {
return new Resource({});
detect() {
return Promise.resolve(noopDetectorSync.detect());
}

@@ -22,0 +22,0 @@ }

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

import { Resource } from '../Resource';
import { Detector } from '../types';
import { ResourceDetectionConfig } from '../config';
import { IResource } from '../IResource';
/**

@@ -9,11 +9,3 @@ * ProcessDetector will be used to detect the resources related current process running

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;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -20,0 +12,0 @@ export declare const processDetector: ProcessDetector;

@@ -16,5 +16,3 @@ /*

*/
import { diag } from '@opentelemetry/api';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../Resource';
import { processDetectorSync } from './ProcessDetectorSync';
/**

@@ -25,42 +23,7 @@ * ProcessDetector will be used to detect the resources related current process running

class ProcessDetector {
async detect(config) {
// Skip if not in Node.js environment.
if (typeof process !== 'object') {
return Resource.empty();
}
const processResource = {
[SemanticResourceAttributes.PROCESS_PID]: process.pid,
[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME]: process.title || '',
[SemanticResourceAttributes.PROCESS_COMMAND]: process.argv[1] || '',
[SemanticResourceAttributes.PROCESS_COMMAND_LINE]: process.argv.join(' ') || '',
[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION]: process.versions.node,
[SemanticResourceAttributes.PROCESS_RUNTIME_NAME]: 'nodejs',
[SemanticResourceAttributes.PROCESS_RUNTIME_DESCRIPTION]: 'Node.js',
};
return this._getResourceAttributes(processResource, config);
detect(config) {
return Promise.resolve(processDetectorSync.detect(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[SemanticResourceAttributes.PROCESS_EXECUTABLE_NAME] ===
'' ||
processResource[SemanticResourceAttributes.PROCESS_EXECUTABLE_PATH] ===
'' ||
processResource[SemanticResourceAttributes.PROCESS_COMMAND] === '' ||
processResource[SemanticResourceAttributes.PROCESS_COMMAND_LINE] === '' ||
processResource[SemanticResourceAttributes.PROCESS_RUNTIME_VERSION] === '') {
diag.debug('ProcessDetector failed: Unable to find required process resources. ');
return Resource.empty();
}
else {
return new Resource(Object.assign({}, processResource));
}
}
}
export const processDetector = new ProcessDetector();
//# sourceMappingURL=ProcessDetector.js.map
export * from './Resource';
export * from './IResource';
export * from './platform';

@@ -6,2 +7,3 @@ export * from './types';

export * from './detectors';
export * from './detect-resources';
//# sourceMappingURL=index.d.ts.map

@@ -17,2 +17,3 @@ /*

export * from './Resource';
export * from './IResource';
export * from './platform';

@@ -22,2 +23,3 @@ export * from './types';

export * from './detectors';
export * from './detect-resources';
//# sourceMappingURL=index.js.map
export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.d.ts.map

@@ -17,5 +17,6 @@ /*

export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.js.map

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

import { Resource } from '../../Resource';
import { Detector } from '../../types';
import { ResourceDetectionConfig } from '../../config';
import { IResource } from '../../IResource';
/**

@@ -9,4 +9,3 @@ * HostDetector detects the resources related to the host current process is

declare class HostDetector implements Detector {
detect(_config?: ResourceDetectionConfig): Promise<Resource>;
private _normalizeArch;
detect(_config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -13,0 +12,0 @@ export declare const hostDetector: HostDetector;

@@ -16,5 +16,3 @@ /*

*/
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../../Resource';
import { arch, hostname } from 'os';
import { hostDetectorSync } from './HostDetectorSync';
/**

@@ -25,25 +23,7 @@ * HostDetector detects the resources related to the host current process is

class HostDetector {
async detect(_config) {
const attributes = {
[SemanticResourceAttributes.HOST_NAME]: hostname(),
[SemanticResourceAttributes.HOST_ARCH]: this._normalizeArch(arch()),
};
return new Resource(attributes);
detect(_config) {
return Promise.resolve(hostDetectorSync.detect(_config));
}
_normalizeArch(nodeArchString) {
// Maps from https://nodejs.org/api/os.html#osarch to arch values in spec:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/host.md
switch (nodeArchString) {
case 'arm':
return 'arm32';
case 'ppc':
return 'ppc32';
case 'x64':
return 'amd64';
default:
return nodeArchString;
}
}
}
export const hostDetector = new HostDetector();
//# sourceMappingURL=HostDetector.js.map
export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.d.ts.map

@@ -17,5 +17,6 @@ /*

export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.js.map

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

import { Resource } from '../../Resource';
import { Detector } from '../../types';
import { ResourceDetectionConfig } from '../../config';
import { IResource } from '../../IResource';
/**

@@ -9,4 +9,3 @@ * OSDetector detects the resources related to the operating system (OS) on

declare class OSDetector implements Detector {
detect(_config?: ResourceDetectionConfig): Promise<Resource>;
private _normalizeType;
detect(_config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -13,0 +12,0 @@ export declare const osDetector: OSDetector;

@@ -16,5 +16,3 @@ /*

*/
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '../../Resource';
import { platform, release } from 'os';
import { osDetectorSync } from './OSDetectorSync';
/**

@@ -25,23 +23,7 @@ * OSDetector detects the resources related to the operating system (OS) on

class OSDetector {
async detect(_config) {
const attributes = {
[SemanticResourceAttributes.OS_TYPE]: this._normalizeType(platform()),
[SemanticResourceAttributes.OS_VERSION]: release(),
};
return new Resource(attributes);
detect(_config) {
return Promise.resolve(osDetectorSync.detect(_config));
}
_normalizeType(nodePlatform) {
// Maps from https://nodejs.org/api/os.html#osplatform to arch values in spec:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/os.md
switch (nodePlatform) {
case 'sunos':
return 'solaris';
case 'win32':
return 'windows';
default:
return nodePlatform;
}
}
}
export const osDetector = new OSDetector();
//# sourceMappingURL=OSDetector.js.map
import { ResourceAttributes } from './types';
import { IResource } from './IResource';
/**

@@ -6,3 +7,3 @@ * A Resource describes the entity for which a signals (metrics or trace) are

*/
export declare class Resource {
export declare class Resource implements IResource {
/**

@@ -13,12 +14,21 @@ * A dictionary of attributes with string keys and values that provide

*/
readonly attributes: ResourceAttributes;
private _attributes;
static readonly EMPTY: Resource;
private _syncAttributes;
private _asyncAttributesPromise;
/**
* Check if async attributes have resolved. This is useful to avoid awaiting
* waitForAsyncAttributes (which will introduce asynchronous behavior) when not necessary.
*
* @returns true if the resource "attributes" property is not yet settled to its final value
*/
asyncAttributesPending: boolean;
/**
* Returns an empty Resource
*/
static empty(): Resource;
static empty(): IResource;
/**
* Returns a Resource that identifies the SDK in use.
*/
static default(): Resource;
static default(): IResource;
constructor(

@@ -30,4 +40,11 @@ /**

*/
attributes: ResourceAttributes);
_attributes: ResourceAttributes, asyncAttributesPromise?: Promise<ResourceAttributes>);
get attributes(): ResourceAttributes;
/**
* Returns a promise that will never be rejected. Resolves when all async attributes have finished being added to
* this Resource's attributes. This is useful in exporters to block until resource detection
* has finished.
*/
waitForAsyncAttributes(): Promise<void>;
/**
* Returns a new, merged {@link Resource} by merging the current Resource

@@ -40,4 +57,4 @@ * with the other Resource. In case of a collision, other Resource takes

*/
merge(other: Resource | null): Resource;
merge(other: IResource | null): IResource;
}
//# sourceMappingURL=Resource.d.ts.map

@@ -16,2 +16,3 @@ /*

*/
import { diag } from '@opentelemetry/api';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

@@ -31,4 +32,15 @@ import { SDK_INFO } from '@opentelemetry/core';

*/
attributes) {
this.attributes = attributes;
_attributes, asyncAttributesPromise) {
this._attributes = _attributes;
this.asyncAttributesPending = asyncAttributesPromise != null;
this._syncAttributes = _attributes;
this._asyncAttributesPromise = asyncAttributesPromise === null || asyncAttributesPromise === void 0 ? void 0 : asyncAttributesPromise.then(asyncAttributes => {
this._attributes = Object.assign({}, this._attributes, asyncAttributes);
this.asyncAttributesPending = false;
return asyncAttributes;
}, err => {
diag.debug("a resource's async attributes promise rejected: %s", err);
this.asyncAttributesPending = false;
return {};
});
}

@@ -52,3 +64,19 @@ /**

}
get attributes() {
if (this.asyncAttributesPending) {
diag.error('Accessing resource attributes before async attributes settled');
}
return this._attributes;
}
/**
* Returns a promise that will never be rejected. Resolves when all async attributes have finished being added to
* this Resource's attributes. This is useful in exporters to block until resource detection
* has finished.
*/
async waitForAsyncAttributes() {
if (this.asyncAttributesPending) {
await this._asyncAttributesPromise;
}
}
/**
* Returns a new, merged {@link Resource} by merging the current Resource

@@ -62,7 +90,19 @@ * with the other Resource. In case of a collision, other Resource takes

merge(other) {
if (!other || !Object.keys(other.attributes).length)
var _a;
if (!other)
return this;
// SpanAttributes from resource overwrite attributes from other resource.
const mergedAttributes = Object.assign({}, this.attributes, other.attributes);
return new Resource(mergedAttributes);
// SpanAttributes from other resource overwrite attributes from this resource.
const mergedSyncAttributes = Object.assign(Object.assign({}, this._syncAttributes), ((_a = other._syncAttributes) !== null && _a !== void 0 ? _a : other.attributes));
if (!this._asyncAttributesPromise &&
!other._asyncAttributesPromise) {
return new Resource(mergedSyncAttributes);
}
const mergedAttributesPromise = Promise.all([
this._asyncAttributesPromise,
other._asyncAttributesPromise,
]).then(([thisAsyncAttributes, otherAsyncAttributes]) => {
var _a;
return Object.assign(Object.assign(Object.assign(Object.assign({}, this._syncAttributes), thisAsyncAttributes), ((_a = other._syncAttributes) !== null && _a !== void 0 ? _a : other.attributes)), otherAsyncAttributes);
});
return new Resource(mergedSyncAttributes, mergedAttributesPromise);
}

@@ -69,0 +109,0 @@ }

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

import { Resource } from './Resource';
import { ResourceDetectionConfig } from './config';
import { SpanAttributes } from '@opentelemetry/api';
import { IResource } from './IResource';
/**

@@ -11,8 +11,14 @@ * Interface for Resource attributes.

/**
* Interface for a Resource Detector. In order to detect resources in parallel
* a detector returns a Promise containing a Resource.
* @deprecated please use {@link DetectorSync}
*/
export interface Detector {
detect(config?: ResourceDetectionConfig): Promise<Resource>;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}
/**
* Interface for a synchronous Resource Detector. In order to detect attributes asynchronously, a detector
* can pass a Promise as the second parameter to the Resource constructor.
*/
export interface DetectorSync {
detect(config?: ResourceDetectionConfig): IResource;
}
//# sourceMappingURL=types.d.ts.map

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

export declare const VERSION = "1.9.1";
export declare const VERSION = "1.10.0";
//# sourceMappingURL=version.d.ts.map

@@ -17,3 +17,3 @@ /*

// this is autogenerated file, see scripts/version-update.js
export const VERSION = '1.9.1';
export const VERSION = '1.10.0';
//# sourceMappingURL=version.js.map

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

import type { Detector } from './types';
import type { Detector, DetectorSync } from './types';
/**

@@ -6,4 +6,4 @@ * ResourceDetectionConfig provides an interface for configuring resource auto-detection.

export interface ResourceDetectionConfig {
detectors?: Array<Detector>;
detectors?: Array<Detector | DetectorSync>;
}
//# sourceMappingURL=config.d.ts.map

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

import { Detector, Resource, ResourceDetectionConfig } from '..';
import { Detector, IResource, ResourceDetectionConfig } from '..';
/**

@@ -6,11 +6,3 @@ * 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;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -17,0 +9,0 @@ export declare const browserDetector: BrowserDetector;

@@ -19,4 +19,2 @@ "use strict";

exports.browserDetector = void 0;
const api_1 = require("@opentelemetry/api");
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const __1 = require("..");

@@ -27,32 +25,7 @@ /**

class BrowserDetector {
async detect(config) {
const isBrowser = typeof navigator !== '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]: navigator.userAgent,
};
return this._getResourceAttributes(browserResource, config);
detect(config) {
return Promise.resolve(__1.browserDetectorSync.detect(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

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

import { Resource } from '../Resource';
import { Detector } from '../types';
import { ResourceDetectionConfig } from '../config';
import { IResource } from '../IResource';
/**

@@ -9,7 +9,2 @@ * EnvDetector can be used to detect the presence of and create a Resource

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;
/**

@@ -22,35 +17,3 @@ * Returns a {@link Resource} populated with attributes from the

*/
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 _isBaggageOctetString;
/**
* 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;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -57,0 +20,0 @@ export declare const envDetector: EnvDetector;

@@ -19,6 +19,3 @@ "use strict";

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");
const EnvDetectorSync_1 = require("./EnvDetectorSync");
/**

@@ -29,16 +26,2 @@ * EnvDetector can be used to detect the presence of and create a Resource

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.';
}
/**

@@ -51,91 +34,7 @@ * Returns a {@link Resource} populated with attributes from the

*/
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);
detect(config) {
return Promise.resolve(EnvDetectorSync_1.envDetectorSync.detect(config));
}
/**
* 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] = decodeURIComponent(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._isBaggageOctetString(name);
}
// https://www.w3.org/TR/baggage/#definition
_isBaggageOctetString(str) {
for (let i = 0; i < str.length; i++) {
const ch = str.charCodeAt(i);
if (ch < 0x21 || ch === 0x2c || ch === 0x3b || ch === 0x5c || ch > 0x7e) {
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
export * from './BrowserDetector';
export * from './EnvDetector';
export * from './ProcessDetector';
export * from './BrowserDetectorSync';
export * from './EnvDetectorSync';
export * from './ProcessDetectorSync';
//# sourceMappingURL=index.d.ts.map

@@ -31,2 +31,5 @@ "use strict";

__exportStar(require("./ProcessDetector"), exports);
__exportStar(require("./BrowserDetectorSync"), exports);
__exportStar(require("./EnvDetectorSync"), exports);
__exportStar(require("./ProcessDetectorSync"), exports);
//# sourceMappingURL=index.js.map

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

import { Resource } from '../Resource';
import { Detector } from '../types';
import { IResource } from '../IResource';
export declare class NoopDetector implements Detector {
detect(): Promise<Resource>;
detect(): Promise<IResource>;
}
export declare const noopDetector: NoopDetector;
//# sourceMappingURL=NoopDetector.d.ts.map

@@ -19,6 +19,6 @@ "use strict";

exports.noopDetector = exports.NoopDetector = void 0;
const Resource_1 = require("../Resource");
const NoopDetectorSync_1 = require("./NoopDetectorSync");
class NoopDetector {
async detect() {
return new Resource_1.Resource({});
detect() {
return Promise.resolve(NoopDetectorSync_1.noopDetectorSync.detect());
}

@@ -25,0 +25,0 @@ }

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

import { Resource } from '../Resource';
import { Detector } from '../types';
import { ResourceDetectionConfig } from '../config';
import { IResource } from '../IResource';
/**

@@ -9,11 +9,3 @@ * ProcessDetector will be used to detect the resources related current process running

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;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -20,0 +12,0 @@ export declare const processDetector: ProcessDetector;

@@ -19,5 +19,3 @@ "use strict";

exports.processDetector = void 0;
const api_1 = require("@opentelemetry/api");
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const Resource_1 = require("../Resource");
const ProcessDetectorSync_1 = require("./ProcessDetectorSync");
/**

@@ -28,42 +26,7 @@ * ProcessDetector will be used to detect the resources related current process running

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);
detect(config) {
return Promise.resolve(ProcessDetectorSync_1.processDetectorSync.detect(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
export * from './Resource';
export * from './IResource';
export * from './platform';

@@ -6,2 +7,3 @@ export * from './types';

export * from './detectors';
export * from './detect-resources';
//# sourceMappingURL=index.d.ts.map

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

__exportStar(require("./Resource"), exports);
__exportStar(require("./IResource"), exports);
__exportStar(require("./platform"), exports);

@@ -34,2 +35,3 @@ __exportStar(require("./types"), exports);

__exportStar(require("./detectors"), exports);
__exportStar(require("./detect-resources"), exports);
//# sourceMappingURL=index.js.map
export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.d.ts.map

@@ -29,5 +29,6 @@ "use strict";

__exportStar(require("./default-service-name"), exports);
__exportStar(require("./detect-resources"), exports);
__exportStar(require("./HostDetector"), exports);
__exportStar(require("./OSDetector"), exports);
__exportStar(require("./HostDetectorSync"), exports);
__exportStar(require("./OSDetectorSync"), exports);
//# sourceMappingURL=index.js.map

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

import { Resource } from '../../Resource';
import { Detector } from '../../types';
import { ResourceDetectionConfig } from '../../config';
import { IResource } from '../../IResource';
/**

@@ -9,4 +9,3 @@ * HostDetector detects the resources related to the host current process is

declare class HostDetector implements Detector {
detect(_config?: ResourceDetectionConfig): Promise<Resource>;
private _normalizeArch;
detect(_config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -13,0 +12,0 @@ export declare const hostDetector: HostDetector;

@@ -19,5 +19,3 @@ "use strict";

exports.hostDetector = void 0;
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const Resource_1 = require("../../Resource");
const os_1 = require("os");
const HostDetectorSync_1 = require("./HostDetectorSync");
/**

@@ -28,25 +26,7 @@ * HostDetector detects the resources related to the host current process is

class HostDetector {
async detect(_config) {
const attributes = {
[semantic_conventions_1.SemanticResourceAttributes.HOST_NAME]: (0, os_1.hostname)(),
[semantic_conventions_1.SemanticResourceAttributes.HOST_ARCH]: this._normalizeArch((0, os_1.arch)()),
};
return new Resource_1.Resource(attributes);
detect(_config) {
return Promise.resolve(HostDetectorSync_1.hostDetectorSync.detect(_config));
}
_normalizeArch(nodeArchString) {
// Maps from https://nodejs.org/api/os.html#osarch to arch values in spec:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/host.md
switch (nodeArchString) {
case 'arm':
return 'arm32';
case 'ppc':
return 'ppc32';
case 'x64':
return 'amd64';
default:
return nodeArchString;
}
}
}
exports.hostDetector = new HostDetector();
//# sourceMappingURL=HostDetector.js.map
export * from './default-service-name';
export * from './detect-resources';
export * from './HostDetector';
export * from './OSDetector';
export * from './HostDetectorSync';
export * from './OSDetectorSync';
//# sourceMappingURL=index.d.ts.map

@@ -29,5 +29,6 @@ "use strict";

__exportStar(require("./default-service-name"), exports);
__exportStar(require("./detect-resources"), exports);
__exportStar(require("./HostDetector"), exports);
__exportStar(require("./OSDetector"), exports);
__exportStar(require("./HostDetectorSync"), exports);
__exportStar(require("./OSDetectorSync"), exports);
//# sourceMappingURL=index.js.map

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

import { Resource } from '../../Resource';
import { Detector } from '../../types';
import { ResourceDetectionConfig } from '../../config';
import { IResource } from '../../IResource';
/**

@@ -9,4 +9,3 @@ * OSDetector detects the resources related to the operating system (OS) on

declare class OSDetector implements Detector {
detect(_config?: ResourceDetectionConfig): Promise<Resource>;
private _normalizeType;
detect(_config?: ResourceDetectionConfig): Promise<IResource>;
}

@@ -13,0 +12,0 @@ export declare const osDetector: OSDetector;

@@ -19,5 +19,3 @@ "use strict";

exports.osDetector = void 0;
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const Resource_1 = require("../../Resource");
const os_1 = require("os");
const OSDetectorSync_1 = require("./OSDetectorSync");
/**

@@ -28,23 +26,7 @@ * OSDetector detects the resources related to the operating system (OS) on

class OSDetector {
async detect(_config) {
const attributes = {
[semantic_conventions_1.SemanticResourceAttributes.OS_TYPE]: this._normalizeType((0, os_1.platform)()),
[semantic_conventions_1.SemanticResourceAttributes.OS_VERSION]: (0, os_1.release)(),
};
return new Resource_1.Resource(attributes);
detect(_config) {
return Promise.resolve(OSDetectorSync_1.osDetectorSync.detect(_config));
}
_normalizeType(nodePlatform) {
// Maps from https://nodejs.org/api/os.html#osplatform to arch values in spec:
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/os.md
switch (nodePlatform) {
case 'sunos':
return 'solaris';
case 'win32':
return 'windows';
default:
return nodePlatform;
}
}
}
exports.osDetector = new OSDetector();
//# sourceMappingURL=OSDetector.js.map
import { ResourceAttributes } from './types';
import { IResource } from './IResource';
/**

@@ -6,3 +7,3 @@ * A Resource describes the entity for which a signals (metrics or trace) are

*/
export declare class Resource {
export declare class Resource implements IResource {
/**

@@ -13,12 +14,21 @@ * A dictionary of attributes with string keys and values that provide

*/
readonly attributes: ResourceAttributes;
private _attributes;
static readonly EMPTY: Resource;
private _syncAttributes;
private _asyncAttributesPromise;
/**
* Check if async attributes have resolved. This is useful to avoid awaiting
* waitForAsyncAttributes (which will introduce asynchronous behavior) when not necessary.
*
* @returns true if the resource "attributes" property is not yet settled to its final value
*/
asyncAttributesPending: boolean;
/**
* Returns an empty Resource
*/
static empty(): Resource;
static empty(): IResource;
/**
* Returns a Resource that identifies the SDK in use.
*/
static default(): Resource;
static default(): IResource;
constructor(

@@ -30,4 +40,11 @@ /**

*/
attributes: ResourceAttributes);
_attributes: ResourceAttributes, asyncAttributesPromise?: Promise<ResourceAttributes>);
get attributes(): ResourceAttributes;
/**
* Returns a promise that will never be rejected. Resolves when all async attributes have finished being added to
* this Resource's attributes. This is useful in exporters to block until resource detection
* has finished.
*/
waitForAsyncAttributes(): Promise<void>;
/**
* Returns a new, merged {@link Resource} by merging the current Resource

@@ -40,4 +57,4 @@ * with the other Resource. In case of a collision, other Resource takes

*/
merge(other: Resource | null): Resource;
merge(other: IResource | null): IResource;
}
//# sourceMappingURL=Resource.d.ts.map

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

exports.Resource = void 0;
const api_1 = require("@opentelemetry/api");
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");

@@ -34,4 +35,15 @@ const core_1 = require("@opentelemetry/core");

*/
attributes) {
this.attributes = attributes;
_attributes, asyncAttributesPromise) {
this._attributes = _attributes;
this.asyncAttributesPending = asyncAttributesPromise != null;
this._syncAttributes = _attributes;
this._asyncAttributesPromise = asyncAttributesPromise === null || asyncAttributesPromise === void 0 ? void 0 : asyncAttributesPromise.then(asyncAttributes => {
this._attributes = Object.assign({}, this._attributes, asyncAttributes);
this.asyncAttributesPending = false;
return asyncAttributes;
}, err => {
api_1.diag.debug("a resource's async attributes promise rejected: %s", err);
this.asyncAttributesPending = false;
return {};
});
}

@@ -55,3 +67,19 @@ /**

}
get attributes() {
if (this.asyncAttributesPending) {
api_1.diag.error('Accessing resource attributes before async attributes settled');
}
return this._attributes;
}
/**
* Returns a promise that will never be rejected. Resolves when all async attributes have finished being added to
* this Resource's attributes. This is useful in exporters to block until resource detection
* has finished.
*/
async waitForAsyncAttributes() {
if (this.asyncAttributesPending) {
await this._asyncAttributesPromise;
}
}
/**
* Returns a new, merged {@link Resource} by merging the current Resource

@@ -65,7 +93,19 @@ * with the other Resource. In case of a collision, other Resource takes

merge(other) {
if (!other || !Object.keys(other.attributes).length)
var _a;
if (!other)
return this;
// SpanAttributes from resource overwrite attributes from other resource.
const mergedAttributes = Object.assign({}, this.attributes, other.attributes);
return new Resource(mergedAttributes);
// SpanAttributes from other resource overwrite attributes from this resource.
const mergedSyncAttributes = Object.assign(Object.assign({}, this._syncAttributes), ((_a = other._syncAttributes) !== null && _a !== void 0 ? _a : other.attributes));
if (!this._asyncAttributesPromise &&
!other._asyncAttributesPromise) {
return new Resource(mergedSyncAttributes);
}
const mergedAttributesPromise = Promise.all([
this._asyncAttributesPromise,
other._asyncAttributesPromise,
]).then(([thisAsyncAttributes, otherAsyncAttributes]) => {
var _a;
return Object.assign(Object.assign(Object.assign(Object.assign({}, this._syncAttributes), thisAsyncAttributes), ((_a = other._syncAttributes) !== null && _a !== void 0 ? _a : other.attributes)), otherAsyncAttributes);
});
return new Resource(mergedSyncAttributes, mergedAttributesPromise);
}

@@ -72,0 +112,0 @@ }

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

import { Resource } from './Resource';
import { ResourceDetectionConfig } from './config';
import { SpanAttributes } from '@opentelemetry/api';
import { IResource } from './IResource';
/**

@@ -11,8 +11,14 @@ * Interface for Resource attributes.

/**
* Interface for a Resource Detector. In order to detect resources in parallel
* a detector returns a Promise containing a Resource.
* @deprecated please use {@link DetectorSync}
*/
export interface Detector {
detect(config?: ResourceDetectionConfig): Promise<Resource>;
detect(config?: ResourceDetectionConfig): Promise<IResource>;
}
/**
* Interface for a synchronous Resource Detector. In order to detect attributes asynchronously, a detector
* can pass a Promise as the second parameter to the Resource constructor.
*/
export interface DetectorSync {
detect(config?: ResourceDetectionConfig): IResource;
}
//# sourceMappingURL=types.d.ts.map

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

export declare const VERSION = "1.9.1";
export declare const VERSION = "1.10.0";
//# sourceMappingURL=version.d.ts.map

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

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '1.9.1';
exports.VERSION = '1.10.0';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/resources",
"version": "1.9.1",
"version": "1.10.0",
"description": "OpenTelemetry SDK resources",

@@ -65,2 +65,3 @@ "main": "build/src/index.js",

"@opentelemetry/api": ">=1.0.0 <1.5.0",
"@opentelemetry/resources_1.9.0": "npm:@opentelemetry/resources@1.9.0",
"@types/mocha": "10.0.0",

@@ -93,8 +94,8 @@ "@types/node": "18.6.5",

"dependencies": {
"@opentelemetry/core": "1.9.1",
"@opentelemetry/semantic-conventions": "1.9.1"
"@opentelemetry/core": "1.10.0",
"@opentelemetry/semantic-conventions": "1.10.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-resources",
"sideEffects": false,
"gitHead": "279458e7ddf16f7ddca5fe60c78672e05fafce66"
"gitHead": "56e6b1bb890f844b8963a146780d0b9cfa8abd0d"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc