Socket
Socket
Sign inDemoInstall

@opentelemetry/resources

Package Overview
Dependencies
Maintainers
4
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opentelemetry/resources - npm Package Compare versions

Comparing version 0.10.2 to 0.10.3-alpha.28

2

build/src/config.d.ts
import { Logger } from '@opentelemetry/api';
import type { Detector } from './types';
/**

@@ -8,2 +9,3 @@ * ResourceDetectionConfig provides an interface for configuring resource auto-detection.

logger?: Logger;
detectors?: Array<Detector>;
}

@@ -10,0 +12,0 @@ /**

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

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

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

__exportStar(require("./types"), exports);
__exportStar(require("./config"), exports);
//# sourceMappingURL=index.js.map

22

build/src/platform/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
/*

@@ -28,3 +17,14 @@ * Copyright The OpenTelemetry Authors

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./node"), exports);
//# sourceMappingURL=index.js.map

@@ -20,6 +20,4 @@ "use strict";

const Resource_1 = require("../../Resource");
const detectors_1 = require("./detectors");
const util = require("util");
const core_1 = require("@opentelemetry/core");
const DETECTORS = [detectors_1.envDetector, detectors_1.awsEc2Detector, detectors_1.gcpDetector];
/**

@@ -35,7 +33,11 @@ * Runs all resource detectors and returns the results merged into a single

}, config);
const resources = await Promise.all(DETECTORS.map(d => {
const resources = await Promise.all((internalConfig.detectors || []).map(async (d) => {
var _a, _b;
try {
return d.detect(internalConfig);
const resource = await d.detect(internalConfig);
(_a = config.logger) === null || _a === void 0 ? void 0 : _a.debug(`${d.constructor.name} found resource.`, resource);
return resource;
}
catch (_a) {
catch (e) {
(_b = config.logger) === null || _b === void 0 ? void 0 : _b.debug(`${d.constructor.name} failed: ${e.message}`);
return Resource_1.Resource.empty();

@@ -57,6 +59,6 @@ }

const logResources = (logger, resources) => {
resources.forEach((resource, index) => {
resources.forEach(resource => {
// Print only populated resources
if (Object.keys(resource.labels).length > 0) {
const resourceDebugString = util.inspect(resource.labels, {
if (Object.keys(resource.attributes).length > 0) {
const resourceDebugString = util.inspect(resource.attributes, {
depth: 2,

@@ -67,6 +69,2 @@ breakLength: Infinity,

});
const detectorName = DETECTORS[index].constructor
? DETECTORS[index].constructor.name
: 'Unknown detector';
logger.debug(`${detectorName} found resource.`);
logger.debug(resourceDebugString);

@@ -73,0 +71,0 @@ }

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

import { Resource } from '../../../Resource';
import { Detector } from '../../../types';
import { ResourceDetectionConfigWithLogger } from '../../../config';
import { Detector, Resource, ResourceDetectionConfigWithLogger } from '../../../';
/**
* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_LABELS environment variable.
* from the OTEL_RESOURCE_ATTRIBUTES environment variable.
*/

@@ -15,5 +13,5 @@ declare class EnvDetector implements Detector {

/**
* Returns a {@link Resource} populated with labels from the
* OTEL_RESOURCE_LABELS environment variable. Note this is an async function
* to conform to the Detector interface.
* Returns a {@link Resource} populated with attributes from the
* OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async
* function to conform to the Detector interface.
*

@@ -24,14 +22,16 @@ * @param config The resource detection config with a required logger

/**
* Creates a label map from the OTEL_RESOURCE_LABELS environment variable.
* Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment
* variable.
*
* OTEL_RESOURCE_LABELS: A comma-separated list of labels describing the
* source in more detail, e.g. “key1=val1,key2=val2”. Domain names and paths
* are accepted as label keys. Values may be quoted or unquoted in general. If
* a value contains whitespaces, =, or " characters, it must always be quoted.
* 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 rawEnvLabels The resource labels as a comma-seperated list
* @param rawEnvAttributes The resource attributes as a comma-seperated list
* of key/value pairs.
* @returns The sanitized resource labels.
* @returns The sanitized resource attributes.
*/
private _parseResourceLabels;
private _parseResourceAttributes;
/**

@@ -38,0 +38,0 @@ * Determines whether the given String is a valid printable ASCII string with

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

exports.envDetector = void 0;
const Resource_1 = require("../../../Resource");
const __1 = require("../../../");
/**
* EnvDetector can be used to detect the presence of and create a Resource
* from the OTEL_RESOURCE_LABELS environment variable.
* from the OTEL_RESOURCE_ATTRIBUTES environment variable.
*/
class EnvDetector {
constructor() {
// Type, label keys, and label values should not exceed 256 characters.
// Type, attribute keys, and attribute values should not exceed 256 characters.
this._MAX_LENGTH = 255;
// OTEL_RESOURCE_LABELS is a comma-separated list of labels.
// OTEL_RESOURCE_ATTRIBUTES is a comma-separated list of attributes.
this._COMMA_SEPARATOR = ',';
// OTEL_RESOURCE_LABELS contains key value pair separated by '='.
// OTEL_RESOURCE_ATTRIBUTES contains key value pair separated by '='.
this._LABEL_KEY_VALUE_SPLITTER = '=';

@@ -41,5 +41,5 @@ this._ERROR_MESSAGE_INVALID_CHARS = 'should be a ASCII string with a length greater than 0 and not exceed ' +

/**
* Returns a {@link Resource} populated with labels from the
* OTEL_RESOURCE_LABELS environment variable. Note this is an async function
* to conform to the Detector interface.
* Returns a {@link Resource} populated with attributes from the
* OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async
* function to conform to the Detector interface.
*

@@ -50,34 +50,36 @@ * @param config The resource detection config with a required logger

try {
const labelString = process.env.OTEL_RESOURCE_LABELS;
if (!labelString) {
config.logger.debug('EnvDetector failed: Environment variable "OTEL_RESOURCE_LABELS" is missing.');
return Resource_1.Resource.empty();
const rawAttributes = process.env.OTEL_RESOURCE_ATTRIBUTES;
if (!rawAttributes) {
config.logger.debug('EnvDetector failed: Environment variable "OTEL_RESOURCE_ATTRIBUTES" is missing.');
return __1.Resource.empty();
}
const labels = this._parseResourceLabels(process.env.OTEL_RESOURCE_LABELS);
return new Resource_1.Resource(labels);
const attributes = this._parseResourceAttributes(rawAttributes);
return new __1.Resource(attributes);
}
catch (e) {
config.logger.debug(`EnvDetector failed: ${e.message}`);
return Resource_1.Resource.empty();
return __1.Resource.empty();
}
}
/**
* Creates a label map from the OTEL_RESOURCE_LABELS environment variable.
* Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment
* variable.
*
* OTEL_RESOURCE_LABELS: A comma-separated list of labels describing the
* source in more detail, e.g. “key1=val1,key2=val2”. Domain names and paths
* are accepted as label keys. Values may be quoted or unquoted in general. If
* a value contains whitespaces, =, or " characters, it must always be quoted.
* 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 rawEnvLabels The resource labels as a comma-seperated list
* @param rawEnvAttributes The resource attributes as a comma-seperated list
* of key/value pairs.
* @returns The sanitized resource labels.
* @returns The sanitized resource attributes.
*/
_parseResourceLabels(rawEnvLabels) {
if (!rawEnvLabels)
_parseResourceAttributes(rawEnvAttributes) {
if (!rawEnvAttributes)
return {};
const labels = {};
const rawLabels = rawEnvLabels.split(this._COMMA_SEPARATOR, -1);
for (const rawLabel of rawLabels) {
const keyValuePair = rawLabel.split(this._LABEL_KEY_VALUE_SPLITTER, -1);
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) {

@@ -91,10 +93,10 @@ continue;

if (!this._isValidAndNotEmpty(key)) {
throw new Error(`Label key ${this._ERROR_MESSAGE_INVALID_CHARS}`);
throw new Error(`Attribute key ${this._ERROR_MESSAGE_INVALID_CHARS}`);
}
if (!this._isValid(value)) {
throw new Error(`Label value ${this._ERROR_MESSAGE_INVALID_VALUE}`);
throw new Error(`Attribute value ${this._ERROR_MESSAGE_INVALID_VALUE}`);
}
labels[key] = value;
attributes[key] = value;
}
return labels;
return attributes;
}

@@ -101,0 +103,0 @@ /**

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

export { awsEc2Detector } from './AwsEc2Detector';
export { envDetector } from './EnvDetector';
export { gcpDetector } from './GcpDetector';
export * from './EnvDetector';
//# sourceMappingURL=index.d.ts.map

@@ -17,9 +17,14 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
var AwsEc2Detector_1 = require("./AwsEc2Detector");
Object.defineProperty(exports, "awsEc2Detector", { enumerable: true, get: function () { return AwsEc2Detector_1.awsEc2Detector; } });
var EnvDetector_1 = require("./EnvDetector");
Object.defineProperty(exports, "envDetector", { enumerable: true, get: function () { return EnvDetector_1.envDetector; } });
var GcpDetector_1 = require("./GcpDetector");
Object.defineProperty(exports, "gcpDetector", { enumerable: true, get: function () { return GcpDetector_1.gcpDetector; } });
__exportStar(require("./EnvDetector"), exports);
//# sourceMappingURL=index.js.map
export * from './detect-resources';
export * from './detectors';
//# sourceMappingURL=index.d.ts.map

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

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

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

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

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

/**
* A dictionary of labels with string keys and values that provide information
* about the entity as numbers, strings or booleans
* TODO: Consider to add check/validation on labels.
* A dictionary of attributes with string keys and values that provide
* information about the entity as numbers, strings or booleans
* TODO: Consider to add check/validation on attributes.
*/
readonly labels: ResourceLabels;
readonly attributes: ResourceAttributes;
static readonly EMPTY: Resource;

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

/**
* A dictionary of labels with string keys and values that provide information
* about the entity as numbers, strings or booleans
* TODO: Consider to add check/validation on labels.
* A dictionary of attributes with string keys and values that provide
* information about the entity as numbers, strings or booleans
* TODO: Consider to add check/validation on attributes.
*/
labels: ResourceLabels);
attributes: ResourceAttributes);
/**

@@ -32,0 +32,0 @@ * Returns a new, merged {@link Resource} by merging the current Resource

@@ -28,8 +28,8 @@ "use strict";

/**
* A dictionary of labels with string keys and values that provide information
* about the entity as numbers, strings or booleans
* TODO: Consider to add check/validation on labels.
* A dictionary of attributes with string keys and values that provide
* information about the entity as numbers, strings or booleans
* TODO: Consider to add check/validation on attributes.
*/
labels) {
this.labels = labels;
attributes) {
this.attributes = attributes;
}

@@ -61,7 +61,7 @@ /**

merge(other) {
if (!other || !Object.keys(other.labels).length)
if (!other || !Object.keys(other.attributes).length)
return this;
// Labels from resource overwrite labels from other resource.
const mergedLabels = Object.assign({}, other.labels, this.labels);
return new Resource(mergedLabels);
// Attributes from resource overwrite attributes from other resource.
const mergedAttributes = Object.assign({}, other.attributes, this.attributes);
return new Resource(mergedAttributes);
}

@@ -68,0 +68,0 @@ }

import { Resource } from './Resource';
import { ResourceDetectionConfigWithLogger } from './config';
/** Interface for Resource labels */
export interface ResourceLabels {
/** Interface for Resource attributes */
export interface ResourceAttributes {
[key: string]: number | string | boolean;

@@ -6,0 +6,0 @@ }

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

export declare const VERSION = "0.10.2";
export declare const VERSION = "0.10.3-alpha.28+d68ff0f";
//# sourceMappingURL=version.d.ts.map

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

// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '0.10.2';
exports.VERSION = '0.10.3-alpha.28+d68ff0f';
//# sourceMappingURL=version.js.map
{
"name": "@opentelemetry/resources",
"version": "0.10.2",
"version": "0.10.3-alpha.28+d68ff0f",
"description": "OpenTelemetry SDK resources",

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

"devDependencies": {
"@types/mocha": "8.0.0",
"@types/mocha": "8.0.2",
"@types/node": "14.0.27",

@@ -58,3 +58,3 @@ "@types/sinon": "9.0.4",

"rimraf": "3.0.2",
"sinon": "9.0.2",
"sinon": "9.0.3",
"ts-mocha": "7.0.0",

@@ -66,6 +66,5 @@ "ts-node": "8.10.2",

"@opentelemetry/api": "^0.10.2",
"@opentelemetry/core": "^0.10.2",
"gcp-metadata": "^3.5.0"
"@opentelemetry/core": "^0.10.2"
},
"gitHead": "b247e69034a7888a842fe75e0a5ff06f8bea44a8"
"gitHead": "d68ff0fb7594f6a367cb7a5057cfb2875e8c082f"
}

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc