Skip to content

Commit

Permalink
feat: add the w3c test script and server (#1380)
Browse files Browse the repository at this point in the history
* 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
srjames90 and mayurkale22 authored Aug 10, 2020
1 parent d4d6e1d commit 87a049a
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/w3c-integration-test.yml
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 integration-tests/propagation-validation-server/package.json
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"
}
}
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}!`)
);
26 changes: 26 additions & 0 deletions integration-tests/tracecontext-integration-test.sh
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
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"packages": [
"benchmark/*",
"metapackages/*",
"packages/*"
"packages/*",
"integration-tests/*"
],
"version": "0.10.2",
"changelog": {
Expand Down

0 comments on commit 87a049a

Please sign in to comment.