or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdresource-detection.mdresource-management.md
tile.json

tessl/npm-opentelemetry--resources

OpenTelemetry SDK resources for representing immutable entities that produce telemetry data

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@opentelemetry/resources@2.1.x

To install, run

npx @tessl/cli install tessl/npm-opentelemetry--resources@2.1.0

index.mddocs/

OpenTelemetry Resources

OpenTelemetry Resources provides utilities for representing immutable entities that produce telemetry data. It includes resource detection capabilities for automatically discovering environment-specific information like host details, process information, and service metadata across Node.js and browser environments.

Package Information

  • Package Name: @opentelemetry/resources
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @opentelemetry/resources

Core Imports

import { 
  Resource, 
  detectResources, 
  resourceFromAttributes, 
  resourceFromDetectedResource,
  defaultResource,
  emptyResource,
  envDetector,
  hostDetector,
  osDetector,
  processDetector,
  serviceInstanceIdDetector,
  noopDetector,
  defaultServiceName
} from "@opentelemetry/resources";

For CommonJS:

const { 
  detectResources, 
  resourceFromAttributes, 
  resourceFromDetectedResource,
  defaultResource,
  emptyResource,
  envDetector,
  hostDetector,
  osDetector,
  processDetector,
  serviceInstanceIdDetector,
  noopDetector,
  defaultServiceName
} = require("@opentelemetry/resources");

Basic Usage

import { 
  detectResources, 
  resourceFromAttributes, 
  resourceFromDetectedResource,
  envDetector, 
  hostDetector 
} from "@opentelemetry/resources";

// Automatic resource detection
const autoDetectedResource = detectResources({
  detectors: [envDetector, hostDetector]
});

// Manual resource creation
const manualResource = resourceFromAttributes({
  "service.name": "my-service",
  "service.version": "1.0.0",
  "host.name": "production-server"
});

// Create resource from DetectedResource object
const detectedResourceObj = {
  attributes: {
    "deployment.environment": "production",
    "service.instance.id": "instance-123"
  }
};
const resourceFromDetected = resourceFromDetectedResource(detectedResourceObj);

// Merge resources
const combinedResource = autoDetectedResource.merge(manualResource).merge(resourceFromDetected);

// Access resource attributes 
console.log(combinedResource.attributes);

Architecture

OpenTelemetry Resources is built around several key components:

  • Resource Interface: Immutable representation of telemetry-producing entities with merge capabilities
  • Resource Detection System: Pluggable detector architecture for automatic environment discovery
  • Platform Abstractions: Environment-specific implementations for Node.js and browser contexts
  • Built-in Detectors: Ready-to-use detectors for common resource attributes (environment variables, host info, process details)

Capabilities

Resource Management

Core functionality for creating, manipulating, and accessing resource information.

interface Resource {
  readonly asyncAttributesPending?: boolean;
  readonly attributes: Attributes;
  readonly schemaUrl?: string;
  waitForAsyncAttributes?(): Promise<void>;
  merge(other: Resource | null): Resource;
  getRawAttributes(): RawResourceAttribute[];
}

function resourceFromAttributes(
  attributes: DetectedResourceAttributes, 
  options?: ResourceOptions
): Resource;

function resourceFromDetectedResource(
  detectedResource: DetectedResource,
  options?: ResourceOptions
): Resource;

function defaultResource(): Resource;

function emptyResource(): Resource;

function defaultServiceName(): string;

Resource Management

Resource Detection

Automatic resource discovery system with built-in detectors for environment variables, host information, operating system details, and process metadata.

function detectResources(config?: ResourceDetectionConfig): Resource;

interface ResourceDetectionConfig {
  detectors?: ResourceDetector[];
}

interface ResourceDetector {
  detect(config?: ResourceDetectionConfig): DetectedResource | Promise<DetectedResource>;
}

Resource Detection

Types

interface ResourceOptions {
  schemaUrl?: string;
}

type DetectedResource = {
  attributes?: DetectedResourceAttributes;
  schemaUrl?: string;
};

type DetectedResourceAttributes = Record<string, AttributeValue | Promise<AttributeValue> | undefined>;

type RawResourceAttribute = [string, MaybePromise<AttributeValue | undefined>];

type MaybePromise<T> = T | Promise<T>;

type AttributeValue = 
  | string 
  | number 
  | boolean 
  | Array<null | undefined | string> 
  | Array<null | undefined | number> 
  | Array<null | undefined | boolean>;

type Attributes = Record<string, AttributeValue>;