Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

### Added

- HTTP client attributes for remote service

### Changed

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@opentelemetry/core": "^1.30",
"@opentelemetry/instrumentation": "^0.57",
"@opentelemetry/instrumentation-http": "^0.57",
"@opentelemetry/instrumentation-undici": "^0.29",
"@opentelemetry/resources": "^1.30",
"@opentelemetry/sdk-metrics": "^1.30",
"@opentelemetry/sdk-trace-base": "^1.30",
Expand Down Expand Up @@ -61,6 +62,10 @@
"http": {
"module": "@opentelemetry/instrumentation-http",
"class": "HttpInstrumentation"
},
"undici": {
"module": "@opentelemetry/instrumentation-undici",
"class": "UndiciInstrumentation"
}
},
"tracing": {
Expand Down
3 changes: 3 additions & 0 deletions test/bookshop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,8 @@
"fiori": {
"draft_deletion_timeout": false
}
},
"devDependencies": {
"@sap/cds-dk": "^9"
}
}
39 changes: 39 additions & 0 deletions test/tracing-attributes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,52 @@ process.env.cds_requires_telemetry_tracing_exporter_module = '@opentelemetry/sdk

const cds = require('@sap/cds')
const { expect, data } = cds.test().in(__dirname + '/bookshop')
const http = require('http')

describe('tracing attributes', () => {
beforeEach(data.reset)

const log = jest.spyOn(console, 'dir')
beforeEach(log.mockClear)

describe('remote', () => {
let server, port

beforeAll(done => {
server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ value: [] }))
})
server.listen(0, () => {
port = server.address().port
done()
})
})

afterAll(done => {
server.close(done)
})

test('HTTP client attributes are set on remote service span', async () => {
// skip for cds 8 due to Cloud SDK resilience module resolution issues in test environment
if (Number(cds.version.split('.')[0]) < 9) return

// configure destination URL directly on credentials
cds.env.requires.TestRemote = { kind: 'odata', credentials: { url: `http://localhost:${port}` } }
const remote = await cds.connect.to('TestRemote')

// no mock handler - let it make the actual HTTP call
await remote.send({ method: 'GET', path: '/test' })

const output = JSON.stringify(log.mock.calls)
expect(output).to.match(/"http\.request\.method":"GET"/)
expect(output).to.match(/"http\.response\.status_code":200/)
expect(output).to.match(new RegExp(`"url\\.full":"http://localhost:${port}/test"`))
expect(output).to.match(/"server\.address":"localhost"/)
expect(output).to.match(new RegExp(`"server\\.port":${port}`))
})
})

describe('db', () => {
const _db_spans = require('./_db_spans')
// prettier-ignore
Expand Down