|
3 | 3 | const assert = require('node:assert') |
4 | 4 | const os = require('node:os') |
5 | 5 |
|
6 | | -const { describe, it, before, afterEach } = require('mocha') |
| 6 | +const { describe, it, before, beforeEach, afterEach } = require('mocha') |
7 | 7 | const sinon = require('sinon') |
8 | 8 |
|
9 | 9 | require('./setup/core') |
@@ -80,6 +80,9 @@ describe('startup logging', () => { |
80 | 80 | assert.strictEqual(logObj.debug, true) |
81 | 81 | assert.strictEqual(logObj.appsec_enabled, true) |
82 | 82 | assert.strictEqual(logObj.data_streams_enabled, true) |
| 83 | + assert.strictEqual('otlp_traces_export_enabled' in logObj, true) |
| 84 | + assert.strictEqual('otlp_metrics_export_enabled' in logObj, true) |
| 85 | + assert.strictEqual('otlp_logs_export_enabled' in logObj, true) |
83 | 86 | }) |
84 | 87 |
|
85 | 88 | it('logIntegrations should output loaded integrations', () => { |
@@ -121,6 +124,9 @@ describe('startup logging', () => { |
121 | 124 | integrations_loaded: ['http', 'fs', 'semver'], |
122 | 125 | appsec_enabled: true, |
123 | 126 | data_streams_enabled: true, |
| 127 | + otlp_traces_export_enabled: false, |
| 128 | + otlp_metrics_export_enabled: false, |
| 129 | + otlp_logs_export_enabled: false, |
124 | 130 | }) |
125 | 131 | }) |
126 | 132 | }) |
@@ -314,3 +320,70 @@ describe('profiling_enabled', () => { |
314 | 320 | }) |
315 | 321 | }) |
316 | 322 | }) |
| 323 | + |
| 324 | +describe('otlp export flags', () => { |
| 325 | + function clearOtlpEnv () { |
| 326 | + delete process.env.OTEL_TRACES_EXPORTER |
| 327 | + delete process.env.OTEL_METRICS_EXPORTER |
| 328 | + delete process.env.OTEL_LOGS_EXPORTER |
| 329 | + delete process.env.DD_METRICS_OTEL_ENABLED |
| 330 | + delete process.env.DD_LOGS_OTEL_ENABLED |
| 331 | + } |
| 332 | + |
| 333 | + // Datadog-instrumented dev shells export the OTEL_*_EXPORTER selectors: a leaked |
| 334 | + // OTEL_TRACES_EXPORTER=otlp corrupts the default-state assertion, and OTEL_METRICS_EXPORTER=none |
| 335 | + // makes config force DD_METRICS_OTEL_ENABLED back to false, breaking the metrics positive case. |
| 336 | + beforeEach(clearOtlpEnv) |
| 337 | + afterEach(clearOtlpEnv) |
| 338 | + |
| 339 | + function startupLogObj (configOptions) { |
| 340 | + sinon.stub(console, 'warn') |
| 341 | + delete require.cache[require.resolve('../src/startup-log')] |
| 342 | + const { |
| 343 | + setStartupLogConfig, |
| 344 | + startupLog, |
| 345 | + } = require('../src/startup-log') |
| 346 | + process.env.DD_TRACE_STARTUP_LOGS = 'true' |
| 347 | + setStartupLogConfig(getConfigFresh(configOptions)) |
| 348 | + startupLog() |
| 349 | + /* eslint-disable-next-line no-console */ |
| 350 | + const warnStub = /** @type {sinon.SinonStub} */ (console.warn) |
| 351 | + const logObj = JSON.parse(warnStub.firstCall.args[0].replace('DATADOG TRACER CONFIGURATION - ', '')) |
| 352 | + warnStub.restore() |
| 353 | + return logObj |
| 354 | + } |
| 355 | + |
| 356 | + it('should default to false when no OTLP env vars are set', () => { |
| 357 | + const logObj = startupLogObj() |
| 358 | + assert.strictEqual(logObj.otlp_traces_export_enabled, false) |
| 359 | + assert.strictEqual(logObj.otlp_metrics_export_enabled, false) |
| 360 | + assert.strictEqual(logObj.otlp_logs_export_enabled, false) |
| 361 | + }) |
| 362 | + |
| 363 | + it('otlp_traces_export_enabled should be true when OTEL_TRACES_EXPORTER is otlp', () => { |
| 364 | + process.env.OTEL_TRACES_EXPORTER = 'otlp' |
| 365 | + assert.strictEqual(startupLogObj().otlp_traces_export_enabled, true) |
| 366 | + }) |
| 367 | + |
| 368 | + it('otlp_traces_export_enabled should be false when OTEL_TRACES_EXPORTER is none', () => { |
| 369 | + process.env.OTEL_TRACES_EXPORTER = 'none' |
| 370 | + assert.strictEqual(startupLogObj().otlp_traces_export_enabled, false) |
| 371 | + }) |
| 372 | + |
| 373 | + it('otlp_traces_export_enabled should be false in Test Optimization mode even when exporter is otlp', () => { |
| 374 | + // Test Optimization keeps test spans on the citestcycle endpoint, so the OTLP |
| 375 | + // trace exporter is not used regardless of OTEL_TRACES_EXPORTER (see opentracing/tracer.js). |
| 376 | + process.env.OTEL_TRACES_EXPORTER = 'otlp' |
| 377 | + assert.strictEqual(startupLogObj({ isCiVisibility: true }).otlp_traces_export_enabled, false) |
| 378 | + }) |
| 379 | + |
| 380 | + it('otlp_metrics_export_enabled should be true when DD_METRICS_OTEL_ENABLED is true', () => { |
| 381 | + process.env.DD_METRICS_OTEL_ENABLED = 'true' |
| 382 | + assert.strictEqual(startupLogObj().otlp_metrics_export_enabled, true) |
| 383 | + }) |
| 384 | + |
| 385 | + it('otlp_logs_export_enabled should be true when DD_LOGS_OTEL_ENABLED is true', () => { |
| 386 | + process.env.DD_LOGS_OTEL_ENABLED = 'true' |
| 387 | + assert.strictEqual(startupLogObj().otlp_logs_export_enabled, true) |
| 388 | + }) |
| 389 | +}) |
0 commit comments