Skip to content

Commit

Permalink
better output from this test for failure (failing with node 18 in CI,…
Browse files Browse the repository at this point in the history
… but not locally for me)
  • Loading branch information
trentm committed Nov 3, 2023
1 parent dfd4ae1 commit 40ef62e
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions metapackages/auto-instrumentations-node/test/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,38 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { promisify } from 'util';
import * as childProcess from 'child_process';
import * as assert from 'assert';

const exec = promisify(childProcess.exec);
import { spawnSync } from 'child_process';
import * as assert from 'assert';

describe('Register', function () {
this.timeout(5000);
it('can load auto instrumentation from command line', async () => {
process.env.OTEL_NODE_RESOURCE_DETECTORS = 'none';
process.env.OTEL_TRACES_EXPORTER = 'console';

const { stdout } = await exec(
'node --require ./build/src/register.js ./test/test-app/app.js'
const proc = spawnSync(
process.execPath,
['--require', '../build/src/register.js', './test-app/app.js'],
{
cwd: __dirname,
timeout: 5000,
env: Object.assign(
{},
process.env,
{
OTEL_NODE_RESOURCE_DETECTORS: 'none',
OTEL_TRACES_EXPORTER: 'console',
}
)
}
);

console.log('XXX proc: status=%s stdout=--\n%s\n-- stderr=--\n%s\n--', proc.status, proc.stdout, proc.stderr);
assert.ifError(proc.error);
assert.ok(
stdout.includes(
proc.stdout.includes(
'OpenTelemetry automatic instrumentation started successfully'
)
);

//Check a span has been generated for the GET request done in app.js
assert.ok(stdout.includes("name: 'GET'"));

delete process.env.OTEL_NODE_RESOURCE_DETECTORS;
delete process.env.OTEL_TRACES_EXPORTER;
// Check a span has been generated for the GET request done in app.js
assert.ok(proc.stdout.includes("name: 'GET'"));
});
});

0 comments on commit 40ef62e

Please sign in to comment.