Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
View
} = require('@opentelemetry/sdk-metrics')

const { getDynatraceMetadata, getCredsForDTAsUPS, getCredsForCLSAsUPS, augmentCLCreds, _require } = require('../utils')
const { getDynatraceMetadata, getCredsForDTAsUPS, getCredsForCLSAsUPS, getCredsForCaaS, augmentCLCreds, augmentCaaSCreds, _require } = require('../utils')

const _protocol2module = {
grpc: '@opentelemetry/exporter-metrics-otlp-grpc',
Expand Down Expand Up @@ -70,6 +70,13 @@ function _getExporter() {
config.credentials ??= credentials.credentials
}

if (kind.match(/to-caas$/)) {
if (!credentials) credentials = getCredsForCaaS()
if (!credentials) throw new Error('No CaaS credentials found.')
augmentCaaSCreds(credentials)
config.url ??= credentials.url
}

// default to DELTA
config.temporalityPreference ??= AggregationTemporality.DELTA

Expand Down
9 changes: 9 additions & 0 deletions lib/tracing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const {
getDynatraceMetadata,
getCredsForDTAsUPS,
getCredsForCLSAsUPS,
getCredsForCaaS,
augmentCLCreds,
augmentCaaSCreds,
hasDependency,
_require
} = require('../utils')
Expand Down Expand Up @@ -125,6 +127,13 @@ function _getExporter() {
config.credentials ??= credentials.credentials
}

if (kind.match(/to-caas$/)) {
if (!credentials) credentials = getCredsForCaaS()
if (!credentials) throw new Error('No CaaS credentials found')
Comment thread
vkozyura marked this conversation as resolved.
Outdated
augmentCaaSCreds(credentials)
config.url ??= credentials.url
}

const exporter = new tracingExporterModule[tracingExporter.class](config)
LOG._debug && LOG.debug('Using trace exporter:', exporter)

Expand Down
29 changes: 29 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,33 @@ function getCredsForCLSAsUPS() {
}
}

function getCredsForCaaS() {
if (!process.env.VCAP_SERVICES) return
const vcap = JSON.parse(process.env.VCAP_SERVICES)

// look for caas-service binding
const caas = vcap['caas-service']?.[0]
if (caas) return caas.credentials
}

function augmentCaaSCreds(credentials) {
if (credentials._augmented) return
credentials._augmented = true

// check for otlp endpoints
if (!credentials.otlp?.http && !credentials.otlp?.grpc) {
throw new Error('No OTLP endpoints found in CaaS binding. Make sure the CaaS instance is properly configured.')
}

// use http endpoint by default (proto exporter)
credentials.url = credentials.otlp.http
Comment thread
vkozyura marked this conversation as resolved.

// Note: CaaS requires mTLS authentication with SAP-signed certificates
// The certificate must be provided separately via BTP Certificate Service
// For now, we just set the URL and log a warning about mTLS
LOG._warn && LOG.warn('CaaS requires mTLS authentication. Make sure the SAP-signed certificate is configured.')
}
Comment thread
vkozyura marked this conversation as resolved.

function augmentCLCreds(credentials) {
if (credentials._augmented) return
credentials._augmented = true
Expand Down Expand Up @@ -194,7 +221,9 @@ module.exports = {
getDynatraceMetadata,
getCredsForDTAsUPS,
getCredsForCLSAsUPS,
getCredsForCaaS,
augmentCLCreds,
augmentCaaSCreds,
hasDependency,
_hrnow,
_require
Expand Down
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@
"metrics": {
"exporter": "env"
}
},
"telemetry-to-caas": {
"vcap": {
"label": "caas-service"
},
"tracing": {
"exporter": {
"module": "@opentelemetry/exporter-trace-otlp-proto",
"class": "OTLPTraceExporter"
}
},
"metrics": {
"exporter": {
"module": "@opentelemetry/exporter-metrics-otlp-proto",
"class": "OTLPMetricExporter"
}
}
}
}
}
Expand Down