npm.io
3.1.1 • Published 5d ago

@opentelemetry/resources

Licence
Apache-2.0
Version
3.1.1
Deps
2
Size
234 kB
Vulns
0
Weekly
0
Stars
3.5K

OpenTelemetry Resources Util

NPM Published Version Apache License

This package provides support for working with OpenTelemetry Resource objects, e.g. `resourceFromAttributes(), and includes a number of resource detectors which gather resource attributes from the environment. (Other resource detectors, e.g. for cloud providers, are available in "resource-detector-*" packages in the opentelemetry-js-contrib.git repository.

This document defines standard attributes for resources which are accessible via @opentelemetry/semantic-conventions.

Installation

npm install --save @opentelemetry/resources

Usage

import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import { resourceFromAttributes } from '@opentelemetry/resources';

const resource = resourceFromAttributes({
    [ATTR_SERVICE_NAME]: 'api-service',
});

const anotherResource = resourceFromAttributes({
    'service.version': '2.0.0',
    'service.group': 'instrumentation-group'
});
const mergedResource = resource.merge(anotherResource);

Resource detectors

import { detectResources, processDetector, hostDetector } from '@opentelemetry/resources';

const resource = detectResources({
  detectors: [ processDetector, hostDetector ],
});

Included resource detectors:

License

Apache 2.0 - See LICENSE for more information.

Keywords