0.29.0 • Published 7 months ago

opentelemetry-resource-detector-git v0.29.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

OpenTelemetry Service Resource Detector for Node.js

NPM version

This module provides automatic resource detector for Git Version Control System. This resource is not part of open telemetry semantic conventions specification for resources.

The detector is doing best effort to extract git info, including these cases:

  • Git info from common CI environment variables.
  • Docker environment where .git db is present (copied to image or mounted into the container) but git cli is not installed on the image.
  • Docker environment where .git db is missing, but node_modules is copied to image from source environment where .git db was available

Installation

npm install --save opentelemetry-resource-detector-git

Usage

Synchronous SDK Initialization

import { detectSyncResources } from 'opentelemetry-resource-detector-sync-api';
import { gitSyncDetector } from 'opentelemetry-resource-detector-git';

const resource = detectSyncResources({
    detectors: [gitSyncDetector, /* add other sync detectors here */],
});
const tracerProvider = new NodeTracerProvider({ resource });

Asynchronous SDK Initialization

import { detectResources } from '@opentelemetry/resources';
import { gitDetector } from 'opentelemetry-resource-detector-git';

( async () => {
    const resource = await detectResources({
        detectors: [gitDetector, /* add other async detectors here */],
    });
    const tracerProvider = new NodeTracerProvider({ resource });
    // Initialize auto instrumentation plugins and register provider.
    // Make sure you don't 'require' instrumented packages elsewhere 
    // before they are registered here
})();

Attributes

AttributeTypeSource
vcs.systemstringIf this repo is identified as git repo, this attribute will be set to constant value 'git'
vcs.commit.idstring (full SHA-1 object name)sha-1 of the current git HEAD. This value uniquely identifies the git commit of the codebase
vcs.clone.idstring (v4 UUID)Unique id for the clone of the git repo
vcs.branch.namestringname of the current active branch