Skip to content

Commit

Permalink
[ci-visibility] Fix appClosing telemetry event (#4023)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez authored and tlhunter committed Feb 14, 2024
1 parent 7e60788 commit c700299
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
1 change: 0 additions & 1 deletion packages/datadog-plugin-cypress/test/app-10/CODEOWNERS

This file was deleted.

1 change: 0 additions & 1 deletion packages/datadog-plugin-cypress/test/app/CODEOWNERS

This file was deleted.

2 changes: 1 addition & 1 deletion packages/datadog-plugin-cypress/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ describe('Plugin', function () {
[TEST_TYPE]: 'browser',
[ORIGIN_KEY]: CI_APP_ORIGIN,
[TEST_IS_RUM_ACTIVE]: 'true',
[TEST_CODE_OWNERS]: JSON.stringify(['@datadog']),
[LIBRARY_VERSION]: ddTraceVersion,
[COMPONENT]: 'cypress'
})
expect(passedTestSpan.meta[TEST_CODE_OWNERS]).to.contain('@DataDog')
expect(passedTestSpan.meta[TEST_FRAMEWORK_VERSION]).not.to.be.undefined
expect(passedTestSpan.metrics[TEST_SOURCE_START]).to.exist

Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/telemetry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ function appStarted (config) {
}

function appClosing () {
if (!config?.telemetry?.enabled) {
return
}
const { reqType, payload } = createPayload('app-closing')
sendData(config, application, host, reqType, payload)
// we flush before shutting down. Only in CI Visibility
Expand Down
32 changes: 25 additions & 7 deletions packages/dd-trace/test/telemetry/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ describe('telemetry', () => {
})
})

// TODO: make this work regardless of the test runner
// it.skip('should send app-closing', () => {
// process.emit('beforeExit')
// return testSeq(5, 'app-closing', payload => {
// expect(payload).to.deep.equal({})
// })
// })
// TODO: test it's called on beforeExit instead of calling directly
it('should send app-closing', () => {
telemetry.appClosing()
return testSeq(5, 'app-closing', payload => {
expect(payload).to.deep.equal({})
})
})

it('should do nothing when not enabled', (done) => {
telemetry.stop()
Expand All @@ -187,6 +187,24 @@ describe('telemetry', () => {
clearTimeout()
})
})

it('should not send app-closing if telemetry is not enabled', () => {
const sendDataStub = sinon.stub()
const notEnabledTelemetry = proxyquire('../../src/telemetry', {
'./send-data': {
sendData: sendDataStub
}
})
notEnabledTelemetry.start({
telemetry: { enabled: false, heartbeatInterval: DEFAULT_HEARTBEAT_INTERVAL },
appsec: { enabled: false },
profiling: { enabled: false }
}, {
_pluginsByName: pluginsByName
})
notEnabledTelemetry.appClosing()
expect(sendDataStub.called).to.be.false
})
})

describe('telemetry app-heartbeat', () => {
Expand Down

0 comments on commit c700299

Please sign in to comment.