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.9.0 to 0.10.0

build/src/config.d.ts

5

build/src/platform/node/detect-resources.d.ts
import { Resource } from '../../Resource';
import { ResourceDetectionConfig } from '../../config';
/**
* Runs all resource detectors and returns the results merged into a single
* Resource.
*
* @param config Configuration for resource detection
*/
export declare const detectResources: () => Promise<Resource>;
export declare const detectResources: (config?: ResourceDetectionConfig) => Promise<Resource>;
//# sourceMappingURL=detect-resources.d.ts.map

39

build/src/platform/node/detect-resources.js

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

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];

@@ -26,7 +28,12 @@ /**

* Resource.
*
* @param config Configuration for resource detection
*/
exports.detectResources = async () => {
exports.detectResources = async (config = {}) => {
const internalConfig = Object.assign({
logger: new core_1.NoopLogger(),
}, config);
const resources = await Promise.all(DETECTORS.map(d => {
try {
return d.detect();
return d.detect(internalConfig);
}

@@ -37,4 +44,32 @@ catch (_a) {

}));
// Log Resources only if there is a user-provided logger
if (config.logger) {
logResources(config.logger, resources);
}
return resources.reduce((acc, resource) => acc.merge(resource), Resource_1.Resource.createTelemetrySDKResource());
};
/**
* Writes debug information about the detected resources to the logger defined in the resource detection config, if one is provided.
*
* @param logger The {@link Logger} to write the debug information to.
* @param resources The array of {@link Resource} that should be logged. Empty entried will be ignored.
*/
const logResources = (logger, resources) => {
resources.forEach((resource, index) => {
// Print only populated resources
if (Object.keys(resource.labels).length > 0) {
const resourceDebugString = util.inspect(resource.labels, {
depth: 2,
breakLength: Infinity,
sorted: true,
compact: false,
});
const detectorName = DETECTORS[index].constructor
? DETECTORS[index].constructor.name
: 'Unknown detector';
logger.debug(`${detectorName} found resource.`);
logger.debug(resourceDebugString);
}
});
};
//# sourceMappingURL=detect-resources.js.map
import { Resource } from '../../../Resource';
import { Detector } from '../../../types';
import { ResourceDetectionConfigWithLogger } from '../../../config';
/**

@@ -20,4 +21,6 @@ * The AwsEc2Detector can be used to detect if a process is running in AWS EC2

* document fails.
*
* @param config The resource detection config with a required logger
*/
detect(): Promise<Resource>;
detect(config: ResourceDetectionConfigWithLogger): Promise<Resource>;
/**

@@ -24,0 +27,0 @@ * Establishes an HTTP connection to AWS instance identity document url.

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

* document fails.
*
* @param config The resource detection config with a required logger
*/
async detect() {
async detect(config) {
try {

@@ -55,3 +57,4 @@ const { accountId, instanceId, instanceType, region, availabilityZone, } = await this._awsMetadataAccessor();

}
catch (_a) {
catch (e) {
config.logger.debug(`AwsEc2Detector failed: ${e.message}`);
return Resource_1.Resource.empty();

@@ -58,0 +61,0 @@ }

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

@@ -17,4 +18,6 @@ * EnvDetector can be used to detect the presence of and create a Resource

* to conform to the Detector interface.
*
* @param config The resource detection config with a required logger
*/
detect(): Promise<Resource>;
detect(config: ResourceDetectionConfigWithLogger): Promise<Resource>;
/**

@@ -21,0 +24,0 @@ * Creates a label map from the OTEL_RESOURCE_LABELS environment variable.

@@ -43,12 +43,17 @@ "use strict";

* to conform to the Detector interface.
*
* @param config The resource detection config with a required logger
*/
async detect() {
async detect(config) {
try {
const labelString = process.env.OTEL_RESOURCE_LABELS;
if (!labelString)
if (!labelString) {
config.logger.debug('EnvDetector failed: Environment variable "OTEL_RESOURCE_LABELS" is missing.');
return Resource_1.Resource.empty();
}
const labels = this._parseResourceLabels(process.env.OTEL_RESOURCE_LABELS);
return new Resource_1.Resource(labels);
}
catch (_a) {
catch (e) {
config.logger.debug(`EnvDetector failed: ${e.message}`);
return Resource_1.Resource.empty();

@@ -55,0 +60,0 @@ }

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

@@ -9,3 +10,11 @@ * The GcpDetector can be used to detect if a process is running in the Google

declare class GcpDetector implements Detector {
detect(): Promise<Resource>;
/**
* Attempts to connect and obtain instance configuration data from the GCP metadata service.
* If the connection is succesful it returns a promise containing a {@link Resource}
* populated with instance metadata as labels. Returns a promise containing an
* empty {@link Resource} if the connection or parsing of the metadata fails.
*
* @param config The resource detection config with a required logger
*/
detect(config: ResourceDetectionConfigWithLogger): Promise<Resource>;
/** Add resource labels for K8s */

@@ -12,0 +21,0 @@ private _addK8sLabels;

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

class GcpDetector {
async detect() {
if (!(await gcpMetadata.isAvailable()))
/**
* Attempts to connect and obtain instance configuration data from the GCP metadata service.
* If the connection is succesful it returns a promise containing a {@link Resource}
* populated with instance metadata as labels. Returns a promise containing an
* empty {@link Resource} if the connection or parsing of the metadata fails.
*
* @param config The resource detection config with a required logger
*/
async detect(config) {
if (!(await gcpMetadata.isAvailable())) {
config.logger.debug('GcpDetector failed: GCP Metadata unavailable.');
return Resource_1.Resource.empty();
}
const [projectId, instanceId, zoneId, clusterName] = await Promise.all([

@@ -34,0 +44,0 @@ this._getProjectId(),

import { Resource } from './Resource';
import { ResourceDetectionConfigWithLogger } from './config';
/** Interface for Resource labels */

@@ -11,4 +12,4 @@ export interface ResourceLabels {

export interface Detector {
detect(): Promise<Resource>;
detect(config: ResourceDetectionConfigWithLogger): Promise<Resource>;
}
//# sourceMappingURL=types.d.ts.map

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

export declare const VERSION = "0.9.0";
export declare const VERSION = "0.10.0";
//# sourceMappingURL=version.d.ts.map

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

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

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

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

@@ -48,6 +49,6 @@ "doc",

"devDependencies": {
"@types/mocha": "7.0.2",
"@types/node": "14.0.13",
"@types/mocha": "8.0.0",
"@types/node": "14.0.25",
"@types/sinon": "9.0.4",
"codecov": "3.7.0",
"codecov": "3.7.2",
"gts": "2.0.2",

@@ -61,9 +62,10 @@ "mocha": "7.2.0",

"ts-node": "8.10.2",
"typescript": "3.9.5"
"typescript": "3.9.7"
},
"dependencies": {
"@opentelemetry/api": "^0.9.0",
"@opentelemetry/core": "^0.9.0",
"@opentelemetry/api": "^0.10.0",
"@opentelemetry/core": "^0.10.0",
"gcp-metadata": "^3.5.0"
}
},
"gitHead": "ab62a4d69b99b3a8c9c26100c04f3226af7859df"
}
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