import { Detector , Resource , ResourceAttributes , } from '@opentelemetry/resources' ; /**
 * The GitHubDetector can be used to detect GitHub Actions environment variables and returns
 *  a  Resource populated with GitHub-specific metadata that exists
 * in GitHub Actions environments.
 *
 * More information about GitHub Action environment variables is available here:
 * https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables
 *
 * Returns an empty Resource if detection fails.
  class GitHubDetector implements Detector { private _attributes : ResourceAttributes = { } ; param key param value private addAttributeIfExists ( key , value ) { if ( typeof value === 'string' && value . length > 0 ) { this . _attributes [ key ] = value ; } } /**
     * Attempts to obtain GitHub repository information from GitHub Actions
     * environment variables:
     * https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables
     *
     * If succesful it returns a promise containing a  Resource * populated with GitHub metadata. Returns a promise containing an
     * empty  Resource if the connection fails.
     *
      async detect ( ) { this . _attributes = { } ; this . addAttributeIfExists ( 'github.workflow' , process . env . GITHUB_WORKFLOW ) ; this . addAttributeIfExists ( 'github.run_id' , process . env . GITHUB_RUN_ID ) ; this . addAttributeIfExists ( 'github.run_number' , process . env . GITHUB_RUN_NUMBER ) ; this . addAttributeIfExists ( 'github.actor' , process . env . GITHUB_ACTOR ) ; this . addAttributeIfExists ( 'github.sha' , process . env . GITHUB_SHA ) ; this . addAttributeIfExists ( 'github.ref' , process . env . GITHUB_REF ) ; this . addAttributeIfExists ( 'github.head_ref' , process . env . GITHUB_HEAD_REF ) ; this . addAttributeIfExists ( 'github.base_ref' , process . env . GITHUB_BASE_REF ) ; return new Resource ( this . _attributes ) ; } } export const gitHubDetector = new GitHubDetector ( ) ;