Skip to content

Commit

Permalink
cds._telemetry instead of cds.env.requires.otel
Browse files Browse the repository at this point in the history
  • Loading branch information
sjvans committed Oct 31, 2023
1 parent d7f89a2 commit 804f1b8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module.exports = function () {

const resource = getResource()

// REVISIT: better way to make available?
cds._telemetry = {
name: resource.attributes['service.name'],
version: resource.attributes['service.version']
}

/*
* add tracing
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/metrics/db-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const _kinds = new Set(['sqlite', 'hana', 'postgres'])
const _initialized = new Set()

function init(pools) {
const meter = metrics.getMeter(`${cds.env.requires.otel.trace.name}-meter`)
// REVISIT: is "-meter" appendix the standard approach?
const meter = metrics.getMeter(`${cds._telemetry.name}-meter`)

const borrowed = meter.createObservableGauge('db.pool.borrowed', {
description: 'The number of resources that are currently acquired by userland code',
Expand Down
4 changes: 2 additions & 2 deletions lib/tracing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ module.exports = resource => {
}
}

// REVISIT: why needed?
cds._tracer = trace.getTracer(cds.env.requires.otel.trace.name, cds.env.requires.otel.trace.version)
// REVISIT: better way to set/ pass tracer?
cds._telemetry.tracer = trace.getTracer(cds._telemetry.name, cds._telemetry.version)

/*
* add CAP instrumentations
Expand Down
3 changes: 2 additions & 1 deletion lib/tracing/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ module.exports = async function trace(name, func, targetObj, args, options = {})
spanOptions.links = [{ context: parentSpan.spanContext() }]
spanOptions.parent = undefined
}
const span = cds._tracer.startSpan(spanName, spanOptions, ctx)
// REVISIT: better way to get tracer?
const span = cds._telemetry.tracer.startSpan(spanName, spanOptions, ctx)
attributeMap.forEach((value, key) => {
span.setAttribute(key, value)
})
Expand Down

0 comments on commit 804f1b8

Please sign in to comment.