Anaconda OpenTelemetry for Typescript
    Preparing search index...

    Class ResourceAttributes

    Represents the configuration for resource attributes used in telemetry.

    Manages common attributes initialized at startup and dynamic attributes added thereafter. Provides validation, default value population, and protection for readonly fields.

    The class enforces specific validation rules:

    • serviceName and serviceVersion must match the regex pattern ^[a-zA-Z0-9._-]{1,30}$
    • environment must be one of: "", "test", "development", "staging", "production"
    • Readonly fields (clientSdkVersion, schemaVersion) cannot be modified after initialization
    const attributes = new ResourceAttributes("my-service", "1.0.0");
    attributes.setAttributes({
    environment: "production",
    userId: "user123",
    custom_metric: "value",
    tags: ["tag1", "tag2", "tag3"], // Will be stored as '["tag1","tag2","tag3"]'
    metadata: { region: "us-west" }, // Will be stored as '{"region":"us-west"}'
    active: true, // Will be stored as "true"
    request_count: 42 // Will be stored as "42"
    });
    Index

    Constructors

    Methods

    Constructors

    • Constructs a new instance of ResourceAttributes with required service information.

      Parameters

      • serviceName: string

        Name of the client service. Required. Must match regex ^[a-zA-Z0-9._-]{1,30}$

      • serviceVersion: string

        Version of the client service. Required. Must match regex ^[a-zA-Z0-9._-]{1,30}$

      • osType: string = ""

        Operating system type of client machine. Defaults to system value.

      • osVersion: string = ""

        Operating system version of client machine. Defaults to system value.

      • nodeVersion: string = ""

        Node.js version of the client. Defaults to process.version.

      • hostname: string = ""

        Hostname of client machine. Defaults to system hostname.

      • platform: string = ""

        Infrastructure on which the software is provided.

      • environment: string = ""

        Environment the software is running in.

      • userId: string = ""

        String denoting a user of a client application.

      Returns ResourceAttributes

      If serviceName or serviceVersion don't match the required pattern.

    Methods

    • Sets attributes according to key-value pairs passed to this function. Will overwrite existing attributes, unless they are readonly. All values are converted to strings internally.

      Parameters

      • attributes: { [key: string]: any }

        Object containing attribute key-value pairs. Common attributes include:

        • serviceName: Name of client service
        • serviceVersion: Version of client service
        • osType: Operating system type of client machine
        • osVersion: Operating system version of client machine
        • nodeVersion: Node.js version of the client
        • hostname: Hostname of client machine
        • platform: Infrastructure on which the software runs
        • environment: Environment of the software ("", "test", "development", "staging", "production")
        • userId: String denoting a user of a client application

        Any other keys will be stored in the parameters collection. Complex values (objects, arrays) will be JSON stringified.

      Returns this

      The current instance for method chaining.