UNPKG

appdynamics

Version:

Performance Profiler and Monitor

65 lines (57 loc) 2.1 kB
/* Copyright (c) AppDynamics, Inc., and its affiliates 2015 All Rights Reserved */ const { Resource } = require('@opentelemetry/resources'); module.exports = OtelConfig; function OtelConfig(opts) { this.resourceAttributes = this.parseResourceAtributes(); this.tierName = opts.tierName || process.env.APPDYNAMICS_AGENT_TIER_NAME; this.applicationName = opts.applicationName || process.env.APPDYNAMICS_AGENT_APPLICATION_NAME; this.accountName = opts.accountName || process.env.APPDYNAMICS_AGENT_ACCOUNT_NAME; this.DEPLOYMENT_ENVIRONMENT_NAME = "deployment.environment.name"; this.SERVICE_NAME = "service.name"; this.SERVICE_NAMESPACE = "service.namespace"; } OtelConfig.prototype.parseResourceAtributes = function() { let resourceAttributes = {}; if(process.env.OTEL_RESOURCE_ATTRIBUTES != null) { let parseResourceAttrs = process.env.OTEL_RESOURCE_ATTRIBUTES.split(','); for(const attr of parseResourceAttrs) { let pairs = attr.split('='); if(pairs.length == 2) { resourceAttributes[pairs[0]] = pairs[1]; } } } return resourceAttributes; }; OtelConfig.prototype.configResource = function() { let resource = {}; this.updateServiceNamespace(this.resourceAttributes, resource); this.updateServiceName(this.resourceAttributes, resource); this.updateDeploymentEnviromentName(this.resourceAttributes, resource); return new Resource(resource); }; OtelConfig.prototype.updateServiceNamespace = function(attrs, resource) { if(attrs[this.SERVICE_NAMESPACE] != null) { return; } else { resource[this.SERVICE_NAMESPACE] = this.applicationName; } }; OtelConfig.prototype.updateServiceName = function(attrs, resource) { if(process.env['OTEL_SERVICE_NAME'] != null || attrs[this.SERVICE_NAME] != null) { return; } else { resource[this.SERVICE_NAME] = this.tierName; } }; OtelConfig.prototype.updateDeploymentEnviromentName = function(attrs, resource) { if(attrs[this.DEPLOYMENT_ENVIRONMENT_NAME] != null) { return; } else { resource[this.DEPLOYMENT_ENVIRONMENT_NAME] = this.accountName; } };