Skip to content
6 changes: 6 additions & 0 deletions lib/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function _getExporter() {
credentials
} = cds.env.requires.telemetry

cds.log('otel-debug').debug('Configured credentials: ', credentials)
Comment thread
PDT42 marked this conversation as resolved.
Outdated

// for kind telemetry-to-otlp based on env vars
if (metricsExporter === 'env') {
const cstm_env = getEnvWithoutDefaults()
Expand All @@ -48,6 +50,8 @@ function _getExporter() {
throw new Error(`Unknown metrics exporter "${metricsExporter.class}" in module "${metricsExporter.module}"`)
const config = { ...(metricsExporter.config || {}) }

cds.log('otel-debug').debug('Metrics exporter kind:', kind)

if (kind.match(/to-dynatrace$/)) {
if (!credentials) credentials = getCredsForDTAsUPS()
if (!credentials) throw new Error('No Dynatrace credentials found.')
Expand All @@ -63,6 +67,8 @@ function _getExporter() {
}

if (kind.match(/to-cloud-logging$/)) {
cds.log('otel-debug').debug('Getting credentials?', !!credentials)

if (!credentials) credentials = getCredsForCLSAsUPS()
if (!credentials) throw new Error('No SAP Cloud Logging credentials found.')
augmentCLCreds(credentials)
Expand Down
5 changes: 5 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ function getResource() {
LOG._info && LOG.info('Unable to require package.json to resolve app name and version due to error:', err)
}

// TODO: If we let PKG.name override the VCAP_APPLICATION.name
// TODO: We end up with my-app, while the name in the standarad deployment is my-app-srv
const name = PKG?.name || VCAP_APPLICATION?.name || 'CAP Application'
const version = PKG?.version || VCAP_APPLICATION?.application_version || '1.0.0'

Expand Down Expand Up @@ -116,6 +118,9 @@ function getCredsForCLSAsUPS() {
const vcap = JSON.parse(process.env.VCAP_SERVICES)
let ups

cds.log('otel-debug').debug('Trying to find credentials for Cloud Logging in VCAP SERVICES')
cds.log('otel-debug').debug('VCAP SERVICES:', JSON.stringify(vcap, null, 2))

// to support connection via user-provided services, the instance must have either tag "cloud-logging" or "Cloud Logging"
ups = vcap['user-provided']?.find(e => e.tags.includes('cloud-logging') || e.tags.includes('Cloud Logging'))
if (ups) return ups.credentials
Expand Down
Loading