Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 0 additions & 11 deletions test/bookshop/.cdsrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,6 @@
}
}
},
"[tracing-attributes]": {
"requires": {
"telemetry": {
"tracing": {
"exporter": {
"module": "@opentelemetry/sdk-trace-node"
}
}
}
}
},
"[tracing-in-memory]": {
"requires": {
"telemetry": {
Expand Down
12 changes: 8 additions & 4 deletions test/tracing-remote-cloudsdk.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const cds = require('@sap/cds')
const { expect } = cds.test(__dirname + '/bookshop', '--profile', 'tracing-attributes')
const { expect } = cds.test(__dirname + '/bookshop', '--profile', 'tracing-in-memory')
const http = require('http')

// The tracing-in-memory profile (see test/bookshop/.cdsrc.json) configures
// MyInMemorySpanExporter as the trace exporter. We read the captured ReadableSpan
// objects directly out of its shared buffer — no console spy.
const { captured, reset } = require('./bookshop/lib/MyInMemorySpanExporter')

// Cloud SDK path: with @sap-cloud-sdk/http-client installed (as in the bookshop) and
// cds.env.remote.native_fetch NOT set, CAP routes outbound remote calls through
// getCloudSdk().executeHttpRequestWithOrigin(...). lib/tracing/cloud_sdk.js wraps that
// export so the outbound call produces a @cap-js/telemetry CLIENT span carrying
// the sap.btp.destination attribute.
describe('tracing remote via cloud sdk', () => {
const log = vi.spyOn(console, 'dir')
beforeEach(log.mockClear)
beforeEach(reset)

const getSpans = () => log.mock.calls.map(c => c[0]).filter(Boolean)
const getSpans = () => captured
const getCapSpans = () => getSpans().filter(s => s.instrumentationScope?.name === '@cap-js/telemetry')

let server, port
Expand Down
12 changes: 8 additions & 4 deletions test/tracing-remote-native.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
process.env.cds_remote_native__fetch = 'true'

const cds = require('@sap/cds')
const { expect } = cds.test(__dirname + '/bookshop', '--profile', 'tracing-attributes')
const { expect } = cds.test(__dirname + '/bookshop', '--profile', 'tracing-in-memory')
const http = require('http')

// The tracing-in-memory profile (see test/bookshop/.cdsrc.json) configures
// MyInMemorySpanExporter as the trace exporter. We read the captured ReadableSpan
// objects directly out of its shared buffer — no console spy.
const { captured, reset } = require('./bookshop/lib/MyInMemorySpanExporter')

// Native fetch path: when cds.env.remote.native_fetch === true (or no cloud sdk is
// installed), CAP routes outbound remote calls through native fetch, which is
// instrumented by @opentelemetry/instrumentation-undici. The outbound span therefore
// comes from that instrumentation scope (NOT @opentelemetry/instrumentation-http, and
// NOT our cloud_sdk wrapper) and carries the standard http.* / url.* / server.* attributes.
describe('tracing remote via native fetch', () => {
const log = vi.spyOn(console, 'dir')
beforeEach(log.mockClear)
beforeEach(reset)

const getSpans = () => log.mock.calls.map(c => c[0]).filter(Boolean)
const getSpans = () => captured

let server, port

Expand Down
19 changes: 13 additions & 6 deletions test/tracing-span-names.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
const cds = require('@sap/cds')
const { expect, data } = cds.test(__dirname + '/bookshop', '--profile', 'tracing-attributes')
const { expect, data } = cds.test(__dirname + '/bookshop', '--profile', 'tracing-in-memory')
const http = require('http')

describe('span names', () => {
beforeEach(data.reset)
// The tracing-in-memory profile (see test/bookshop/.cdsrc.json) configures
// MyInMemorySpanExporter as the trace exporter. We read the captured ReadableSpan
// objects directly out of its shared buffer — no console spy.
const { captured, reset } = require('./bookshop/lib/MyInMemorySpanExporter')

const log = vi.spyOn(console, 'dir')
beforeEach(log.mockClear)
describe('span names', () => {
beforeEach(async () => {
// data.reset is itself heavily traced (it runs DELETEs + INSERTs for the seed data) —
// run it first, THEN clear the buffer so the test only sees its own spans.
await data.reset()
reset()
})

const getSpans = () => log.mock.calls.map(c => c[0]).filter(Boolean)
const getSpans = () => captured

// Spans from our tracer only (excludes HTTP instrumentation spans)
const getCapSpans = () => getSpans().filter(s => s.instrumentationScope?.name === '@cap-js/telemetry')
Expand Down