elastic / elastic/apm-agent-nodejs

Implement Fully Passing W3C TraceContext Test Suite

Open
#1,837 1 comment 0 reactions 0 assignees View on GitHub
agent-nodejs enhancement
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

The W3C standards body has a suite of tests that will thoroughly validate, at several levels of strictness, the W3C TraceContext functionality of an instrumented server.

The Agent's current trace parent implementation does not fully pass these tests at the full strictness level.

This issue will be considered done when every test in [the W3C test suite](https://github.com/w3c/trace-context/tree/master/test) passes.

## Running the Suite

The W3C repo contains [information on how to run these tests](https://github.com/w3c/trace-context/tree/master/test). The following is supplemental

To run the tests in the suite, python3 is required

$ python --version
Python 3.8.5

Tests are invoked as follows

$ python test.py http://127.0.0.1/test

The `http://127.0.0.1/test` is a service that we write, and this service should be instrumented by the Elastic Node Agent. The following is a minimal implementation of the service using `express` and `node-fetch`

// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({
// Override service name from package.json
// Allowed characters: a-z, A-Z, 0-9, -, _, and space
serviceName: 'W3C Test Service',

// Use if APM Server requires a token
secretToken: 'D...a',

// Set custom APM Server URL (default: http://localhost:8200)
serverUrl: 'https://...yoururl...:443'
})

const express = require('express')
const app = express()

const port = 3000
const fetch = require('node-fetch')

app.use(express.json())

app.post('/test', (req, res) => {
for(const [,post] of req.body.entries()) {
const {url, arguments} = post;
fetch(url, {
method: 'post',
body: JSON.stringify(arguments)
}).then(()=>{
res.send('done')
})
}
})

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})

The tests in `test.py` as implemented as test classes. Any method that begins with the string `test_` [is considered a test](https://github.com/w3c/trace-context/blob/master/test/test.py#L116).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.