Skip to content

Commit bb5fa49

Browse files
authored
fix: telemetry for test optimization auto instrument provider (#8135)
* fix: telemetry for test optimization auto instrument provider Also add test cases for the worker environment variables to work as expected. This just increases coverage. The string is working as a simple existence check.
1 parent 0ad631d commit bb5fa49

9 files changed

Lines changed: 88 additions & 9 deletions

File tree

packages/datadog-plugin-cucumber/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class CucumberPlugin extends CiPlugin {
117117
finishAllTraceSpans(this.testSessionSpan)
118118
this.telemetry.count(TELEMETRY_TEST_SESSION, {
119119
provider: this.ciProviderName,
120-
autoInjected: this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
120+
autoInjected: !!this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
121121
})
122122

123123
this.libraryConfig = null

packages/datadog-plugin-jest/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class JestPlugin extends CiPlugin {
166166

167167
this.telemetry.count(TELEMETRY_TEST_SESSION, {
168168
provider: this.ciProviderName,
169-
autoInjected: this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
169+
autoInjected: !!this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
170170
})
171171

172172
appClosingTelemetry()

packages/datadog-plugin-mocha/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class MochaPlugin extends CiPlugin {
405405
finishAllTraceSpans(this.testSessionSpan)
406406
this.telemetry.count(TELEMETRY_TEST_SESSION, {
407407
provider: this.ciProviderName,
408-
autoInjected: this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
408+
autoInjected: !!this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
409409
})
410410
}
411411
this.libraryConfig = null

packages/datadog-plugin-playwright/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class PlaywrightPlugin extends CiPlugin {
107107
finishAllTraceSpans(this.testSessionSpan)
108108
this.telemetry.count(TELEMETRY_TEST_SESSION, {
109109
provider: this.ciProviderName,
110-
autoInjected: this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
110+
autoInjected: !!this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
111111
})
112112
appClosingTelemetry()
113113
this.tracer._exporter.flush(onDone)

packages/datadog-plugin-vitest/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ class VitestPlugin extends CiPlugin {
423423
finishAllTraceSpans(this.testSessionSpan)
424424
this.telemetry.count(TELEMETRY_TEST_SESSION, {
425425
provider: this.ciProviderName,
426-
autoInjected: this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
426+
autoInjected: !!this._tracerConfig.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER,
427427
})
428428
this.tracer._exporter.flush(onFinish)
429429
})

packages/dd-trace/src/config/generated-config-types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export interface GeneratedConfig {
7878
DD_AZURE_RESOURCE_GROUP: string | undefined;
7979
DD_CIVISIBILITY_AGENTLESS_ENABLED: boolean;
8080
DD_CIVISIBILITY_AGENTLESS_URL: string | undefined;
81-
DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER: boolean;
81+
DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER: string | undefined;
8282
DD_CIVISIBILITY_DANGEROUSLY_FORCE_COVERAGE: boolean;
8383
DD_CIVISIBILITY_DANGEROUSLY_FORCE_TEST_SKIPPING: boolean;
8484
DD_CIVISIBILITY_ENABLED: boolean;

packages/dd-trace/src/config/supported-configurations.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@
446446
],
447447
"DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER": [
448448
{
449-
"implementation": "B",
450-
"type": "boolean",
451-
"default": "false"
449+
"implementation": "A",
450+
"type": "string",
451+
"default": null
452452
}
453453
],
454454
"DD_CIVISIBILITY_DANGEROUSLY_FORCE_COVERAGE": [

packages/dd-trace/test/ci-visibility/exporters/test-worker/exporter.spec.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const {
1212
JEST_WORKER_COVERAGE_PAYLOAD_CODE,
1313
CUCUMBER_WORKER_TRACE_PAYLOAD_CODE,
1414
MOCHA_WORKER_TRACE_PAYLOAD_CODE,
15+
PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE,
16+
VITEST_WORKER_TRACE_PAYLOAD_CODE,
1517
} = require('../../../../src/plugins/util/test')
1618

1719
describe('CI Visibility Test Worker Exporter', () => {
@@ -122,4 +124,73 @@ describe('CI Visibility Test Worker Exporter', () => {
122124
sinon.assert.notCalled(send)
123125
})
124126
})
127+
128+
context('when the process is a playwright worker', () => {
129+
beforeEach(() => {
130+
process.env.DD_PLAYWRIGHT_WORKER = '1'
131+
})
132+
afterEach(() => {
133+
delete process.env.DD_PLAYWRIGHT_WORKER
134+
})
135+
136+
it('can export traces', () => {
137+
const trace = [{ type: 'test' }]
138+
const traceSecond = [{ type: 'test', name: 'other' }]
139+
const playwrightWorkerExporter = new TestWorkerCiVisibilityExporter()
140+
playwrightWorkerExporter.export(trace)
141+
playwrightWorkerExporter.export(traceSecond)
142+
playwrightWorkerExporter.flush()
143+
sinon.assert.calledWith(send, [PLAYWRIGHT_WORKER_TRACE_PAYLOAD_CODE, JSON.stringify([trace, traceSecond])])
144+
})
145+
146+
it('does not break if process.send is undefined', () => {
147+
delete process.send
148+
const trace = [{ type: 'test' }]
149+
const playwrightWorkerExporter = new TestWorkerCiVisibilityExporter()
150+
playwrightWorkerExporter.export(trace)
151+
playwrightWorkerExporter.flush()
152+
sinon.assert.notCalled(send)
153+
})
154+
})
155+
156+
context('when the process is a vitest worker', () => {
157+
afterEach(() => {
158+
delete process.env.DD_VITEST_WORKER
159+
delete process.env.TINYPOOL_WORKER_ID
160+
})
161+
162+
it('can export traces (vitest >=4)', () => {
163+
process.env.DD_VITEST_WORKER = '1'
164+
const trace = [{ type: 'test' }]
165+
const traceSecond = [{ type: 'test', name: 'other' }]
166+
const vitestWorkerExporter = new TestWorkerCiVisibilityExporter()
167+
vitestWorkerExporter.export(trace)
168+
vitestWorkerExporter.export(traceSecond)
169+
vitestWorkerExporter.flush()
170+
sinon.assert.calledWith(send, [VITEST_WORKER_TRACE_PAYLOAD_CODE, JSON.stringify([trace, traceSecond])])
171+
})
172+
173+
it('wraps the payload for legacy tinypool workers (vitest <4)', () => {
174+
process.env.TINYPOOL_WORKER_ID = '1'
175+
const trace = [{ type: 'test' }]
176+
const vitestWorkerExporter = new TestWorkerCiVisibilityExporter()
177+
vitestWorkerExporter.export(trace)
178+
vitestWorkerExporter.flush()
179+
sinon.assert.calledWith(send, {
180+
__tinypool_worker_message__: true,
181+
interprocessCode: VITEST_WORKER_TRACE_PAYLOAD_CODE,
182+
data: JSON.stringify([trace]),
183+
})
184+
})
185+
186+
it('does not break if process.send is undefined', () => {
187+
process.env.DD_VITEST_WORKER = '1'
188+
delete process.send
189+
const trace = [{ type: 'test' }]
190+
const vitestWorkerExporter = new TestWorkerCiVisibilityExporter()
191+
vitestWorkerExporter.export(trace)
192+
vitestWorkerExporter.flush()
193+
sinon.assert.notCalled(send)
194+
})
195+
})
125196
})

packages/dd-trace/test/config/index.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,6 +3040,14 @@ describe('Config', () => {
30403040
})
30413041
})
30423042
})
3043+
3044+
it('should accept all values for DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER', () => {
3045+
for (const provider of ['github', 'gitlab', 'circleci', 'jenkins']) {
3046+
process.env.DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER = provider
3047+
assert.strictEqual(getConfig(options).DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER, provider)
3048+
}
3049+
})
3050+
30433051
it('disables telemetry if inside a jest worker', () => {
30443052
process.env.JEST_WORKER_ID = '1'
30453053
const config = getConfig(options)

0 commit comments

Comments
 (0)