Skip to content

Commit

Permalink
concise metrics output (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjvans authored Oct 23, 2023
1 parent 208d159 commit 3b4f2b5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/metrics/CDSConsoleMetricsExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const cds = require('@sap/cds')
const LOG = cds.log('otel', { label: 'otel:metrics' })

const { ExportResultCode } = require('@opentelemetry/core')
const { ExportResultCode, hrTimeToTimeStamp } = require('@opentelemetry/core')
const { ConsoleMetricExporter } = require('@opentelemetry/sdk-metrics')

class CDSConsoleMetricsExporter extends ConsoleMetricExporter {
Expand All @@ -18,9 +18,13 @@ class CDSConsoleMetricsExporter extends ConsoleMetricExporter {

static _sendMetrics(metrics, done) {
for (const scopeMetrics of metrics.scopeMetrics) {
const tenant = scopeMetrics.metrics[0].dataPoints[0].attributes['sap.tenancy.tenant_id']
const timestamp = hrTimeToTimeStamp(scopeMetrics.metrics[0].dataPoints[0].startTime)
let toLog = `db.pool of tenant "${tenant}" at ${timestamp}:`
for (const metric of scopeMetrics.metrics) {
LOG.info(`OTEL Metric ${metric.descriptor.name} | Data Points:`, metric.dataPoints)
toLog += `\n |- ${metric.descriptor.name.replace('db.pool.', '')}: ${metric.dataPoints[0].value}`
}
LOG.info(toLog)
}
done({ code: ExportResultCode.SUCCESS })
}
Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/db-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const cds = require('@sap/cds')
const LOG = cds.log('otel', { label: 'otel:metrics' })

// REVISIT: instanceof cds.DatabaseService doesn't work with @cap-js databases
const _kinds = new Set('sqlite', 'hana', 'postgres')
const _kinds = new Set(['sqlite', 'hana', 'postgres'])

const _initialized = new Set()

Expand Down

0 comments on commit 3b4f2b5

Please sign in to comment.