-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the w3c test script and server (#1380)
* feat: add the w3c test script and server * fix: manually instrument * fix: dependencies and propagator * fix: increase timeout * fix: package and script issues * refactor: move files into integration-tests * refactor: use extract defaults * fix: remove unneeded dependency * refactor: use AsyncHooksContextManager * fix: BasicTracerProvider instantiation Co-authored-by: Mayur Kale <mayurkale@google.com> Co-authored-by: Mayur Kale <mayurkale@google.com>
- Loading branch information
1 parent
d4d6e1d
commit 87a049a
Showing
5 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Run w3c tests on push | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install and Build 🔧 | ||
run: | | ||
npm install --ignore-scripts | ||
npx lerna bootstrap --scope=propagation-validation-server --include-dependencies | ||
- name: Run W3C Test harness | ||
run: ./integration-tests/tracecontext-integration-test.sh |
19 changes: 19 additions & 0 deletions
19
integration-tests/propagation-validation-server/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "propagation-validation-server", | ||
"version": "0.10.2", | ||
"description": "server for w3c tests", | ||
"main": "validation_server.js", | ||
"private": true, | ||
"repository": "open-telemetry/opentelemetry-js", | ||
"author": "OpenTelemetry Authors", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@opentelemetry/api": "^0.10.2", | ||
"@opentelemetry/context-async-hooks": "^0.10.2", | ||
"@opentelemetry/core": "^0.10.2", | ||
"@opentelemetry/tracing": "^0.10.2", | ||
"axios": "^0.19.2", | ||
"body-parser": "^1.19.0", | ||
"express": "^4.17.1" | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
integration-tests/propagation-validation-server/validation-server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const axios = require("axios"); | ||
const { HttpTraceContext } = require("@opentelemetry/core"); | ||
const { BasicTracerProvider } = require("@opentelemetry/tracing"); | ||
const { context, propagation, trace } = require("@opentelemetry/api"); | ||
const { | ||
AsyncHooksContextManager, | ||
} = require("@opentelemetry/context-async-hooks"); | ||
const bodyParser = require("body-parser"); | ||
|
||
// set global propagator | ||
propagation.setGlobalPropagator(new HttpTraceContext()); | ||
|
||
// set global context manager | ||
context.setGlobalContextManager(new AsyncHooksContextManager()); | ||
|
||
// Create a provider for activating and tracking spans | ||
const tracerProvider = new BasicTracerProvider(); | ||
|
||
// Register the tracer | ||
tracerProvider.register(); | ||
|
||
// Get a tracer | ||
const tracer = trace.getTracer("w3c-tests"); | ||
|
||
// --- Simple Express app setup | ||
const express = require("express"); | ||
const port = 5000; | ||
const app = express(); | ||
|
||
app.use(bodyParser.json()); | ||
|
||
// Mount our demo route | ||
app.post("/verify-tracecontext", (req, res) => { | ||
context.with(propagation.extract(req.headers), () => { | ||
Promise.all( | ||
req.body.map((action) => { | ||
const span = tracer.startSpan("propagate-w3c"); | ||
let promise; | ||
tracer.withSpan(span, () => { | ||
const headers = {}; | ||
propagation.inject(headers); | ||
promise = axios | ||
.post( | ||
action.url, | ||
|
||
[...action.arguments], | ||
|
||
{ | ||
headers, | ||
timeout: 10, | ||
} | ||
) | ||
.finally(() => { | ||
span.end(); | ||
}); | ||
}); | ||
return promise; | ||
}) | ||
) | ||
.then(() => res.send("hello")) | ||
.catch((err) => res.status(500).send(err)); | ||
}); | ||
}); | ||
|
||
// Start the server | ||
app.listen(port, () => | ||
console.log(`W3c test server listening on port ${port}!`) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
#!/bin/sh | ||
set -e | ||
# hard-coding the git tag to ensure stable builds. | ||
TRACECONTEXT_GIT_TAG="98f210efd89c63593dce90e2bae0a1bdcb986f51" | ||
# clone w3c tracecontext tests | ||
mkdir -p target | ||
rm -rf ./target/trace-context | ||
git clone https://github.com/w3c/trace-context ./target/trace-context | ||
cd ./target/trace-context && git checkout $TRACECONTEXT_GIT_TAG && cd - | ||
pip3 install setuptools; | ||
pip3 install aiohttp; | ||
node ./integration-tests/propagation-validation-server/validation-server.js 1>&2 & | ||
EXAMPLE_SERVER_PID=$! | ||
# give the app server a little time to start up. Not adding some sort | ||
# of delay would cause many of the tracecontext tests to fail being | ||
# unable to connect. | ||
sleep 1 | ||
onshutdown() | ||
{ | ||
kill $EXAMPLE_SERVER_PID | ||
} | ||
trap onshutdown EXIT | ||
export STRICT_LEVEL=1 | ||
cd ./target/trace-context/test | ||
python3 test.py http://127.0.0.1:5000/verify-tracecontext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters