Skip to content

Commit

Permalink
Merge branch 'master' into fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Jan 12, 2021
2 parents 5b0222d + 4ab9465 commit 6ae8908
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LICENSE* text
## Non-text documentation
*.html text diff=html
*.pdf binary
*.json text
*.json text eol=lf
*.rtf binary

## Git Properties
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "CodeQL Analysis"

on:
workflow_dispatch:
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '30 1 * * *'

jobs:
CodeQL-Build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: javascript

- name: Autobuild
uses: github/codeql-action/autobuild@v1

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"lerna-changelog": "1.0.1",
"markdownlint-cli": "0.25.0",
"typescript": "3.9.7",
"update-ts-references": "^1.3.0"
"update-ts-references": "2.0.0"
},
"husky": {
"hooks": {
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-instrumentation-grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"access": "public"
},
"devDependencies": {
"@grpc/grpc-js": "^1.2.2",
"@grpc/proto-loader": "^0.5.5",
"@grpc/grpc-js": "1.2.3",
"@grpc/proto-loader": "0.5.5",
"@opentelemetry/context-async-hooks": "^0.14.0",
"@opentelemetry/context-base": "^0.14.0",
"@opentelemetry/core": "^0.14.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ instrumentation.disable();
import * as http from 'http';
import { httpRequest } from '../utils/httpRequest';
import { DummyPropagation } from '../utils/DummyPropagation';
import { Socket } from 'net';

const protocol = 'http';
const serverPort = 32345;
Expand All @@ -56,6 +57,47 @@ const customAttributeFunction = (span: Span): void => {
};

describe('HttpInstrumentation Integration tests', () => {
let mockServerPort = 0;
let mockServer: http.Server;
const sockets: Array<Socket> = [];
before(done => {
mockServer = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('content-type', 'application/json');
res.write(
JSON.stringify({
success: true,
})
);
res.end();
});

mockServer.listen(0, () => {
const addr = mockServer.address();
if (addr == null) {
done(new Error('unexpected addr null'));
return;
}

if (typeof addr === 'string') {
done(new Error(`unexpected addr ${addr}`));
return;
}

if (addr.port <= 0) {
done(new Error('Could not get port'));
return;
}
mockServerPort = addr.port;
done();
});
});

after(done => {
sockets.forEach(s => s.destroy());
mockServer.close(done);
});

beforeEach(() => {
memoryExporter.reset();
context.setGlobalContextManager(new AsyncHooksContextManager().enable());
Expand Down Expand Up @@ -115,13 +157,14 @@ describe('HttpInstrumentation Integration tests', () => {
assert.strictEqual(spans.length, 0);

const result = await httpRequest.get(
`${protocol}://google.fr/?query=test`
`${protocol}://localhost:${mockServerPort}/?query=test`
);

spans = memoryExporter.getFinishedSpans();
const span = spans[0];
const span = spans.find(s => s.kind === SpanKind.CLIENT);
assert.ok(span);
const validations = {
hostname: 'google.fr',
hostname: 'localhost',
httpStatusCode: result.statusCode!,
httpMethod: 'GET',
pathname: '/',
Expand All @@ -131,7 +174,7 @@ describe('HttpInstrumentation Integration tests', () => {
component: 'http',
};

assert.strictEqual(spans.length, 1);
assert.strictEqual(spans.length, 2);
assert.strictEqual(span.name, 'HTTP GET');
assertSpan(span, SpanKind.CLIENT, validations);
});
Expand All @@ -141,13 +184,14 @@ describe('HttpInstrumentation Integration tests', () => {
assert.strictEqual(spans.length, 0);

const result = await httpRequest.get(
new url.URL(`${protocol}://google.fr/?query=test`)
new url.URL(`${protocol}://localhost:${mockServerPort}/?query=test`)
);

spans = memoryExporter.getFinishedSpans();
const span = spans[0];
const span = spans.find(s => s.kind === SpanKind.CLIENT);
assert.ok(span);
const validations = {
hostname: 'google.fr',
hostname: 'localhost',
httpStatusCode: result.statusCode!,
httpMethod: 'GET',
pathname: '/',
Expand All @@ -157,7 +201,7 @@ describe('HttpInstrumentation Integration tests', () => {
component: 'http',
};

assert.strictEqual(spans.length, 1);
assert.strictEqual(spans.length, 2);
assert.strictEqual(span.name, 'HTTP GET');
assertSpan(span, SpanKind.CLIENT, validations);
});
Expand All @@ -167,16 +211,17 @@ describe('HttpInstrumentation Integration tests', () => {
assert.strictEqual(spans.length, 0);

const result = await httpRequest.get(
new url.URL(`${protocol}://google.fr/?query=test`),
new url.URL(`${protocol}://localhost:${mockServerPort}/?query=test`),
{
headers: { 'x-foo': 'foo' },
}
);

spans = memoryExporter.getFinishedSpans();
const span = spans[0];
const span = spans.find(s => s.kind === SpanKind.CLIENT);
assert.ok(span);
const validations = {
hostname: 'google.fr',
hostname: 'localhost',
httpStatusCode: result.statusCode!,
httpMethod: 'GET',
pathname: '/',
Expand All @@ -186,7 +231,7 @@ describe('HttpInstrumentation Integration tests', () => {
component: 'http',
};

assert.strictEqual(spans.length, 1);
assert.strictEqual(spans.length, 2);
assert.strictEqual(span.name, 'HTTP GET');
assert.strictEqual(result.reqHeaders['x-foo'], 'foo');
assert.strictEqual(span.attributes[HttpAttribute.HTTP_FLAVOR], '1.1');
Expand All @@ -198,11 +243,14 @@ describe('HttpInstrumentation Integration tests', () => {
});

it('custom attributes should show up on client spans', async () => {
const result = await httpRequest.get(`${protocol}://google.fr/`);
const result = await httpRequest.get(
`${protocol}://localhost:${mockServerPort}/`
);
const spans = memoryExporter.getFinishedSpans();
const span = spans[0];
const span = spans.find(s => s.kind === SpanKind.CLIENT);
assert.ok(span);
const validations = {
hostname: 'google.fr',
hostname: 'localhost',
httpStatusCode: result.statusCode!,
httpMethod: 'GET',
pathname: '/',
Expand All @@ -211,7 +259,7 @@ describe('HttpInstrumentation Integration tests', () => {
component: 'http',
};

assert.strictEqual(spans.length, 1);
assert.strictEqual(spans.length, 2);
assert.strictEqual(span.name, 'HTTP GET');
assert.strictEqual(span.attributes['span kind'], SpanKind.CLIENT);
assertSpan(span, SpanKind.CLIENT, validations);
Expand All @@ -222,36 +270,30 @@ describe('HttpInstrumentation Integration tests', () => {
assert.strictEqual(spans.length, 0);
const options = Object.assign(
{ headers: { Expect: '100-continue' } },
url.parse(`${protocol}://google.fr/`)
url.parse(`${protocol}://localhost:${mockServerPort}/`)
);

const result = await httpRequest.get(options);
spans = memoryExporter.getFinishedSpans();
const span = spans[0];
const span = spans.find(s => s.kind === SpanKind.CLIENT);
assert.ok(span);
const validations = {
hostname: 'google.fr',
httpStatusCode: 301,
hostname: 'localhost',
httpStatusCode: 200,
httpMethod: 'GET',
pathname: '/',
resHeaders: result.resHeaders,
reqHeaders: result.reqHeaders,
component: 'http',
};

assert.strictEqual(spans.length, 1);
assert.strictEqual(spans.length, 2);
assert.strictEqual(span.name, 'HTTP GET');

try {
assertSpan(span, SpanKind.CLIENT, validations);
} catch (error) {
// temporary redirect is also correct
validations.httpStatusCode = 307;
assertSpan(span, SpanKind.CLIENT, validations);
}
assertSpan(span, SpanKind.CLIENT, validations);
});
for (const headers of [
{ Expect: '100-continue', 'user-agent': 'http-instrumentation-test' },
{ 'user-agent': 'http-instrumentation-test' },
{ Expect: '100-continue', 'user-agent': 'http-plugin-test' },
{ 'user-agent': 'http-plugin-test' },
]) {
it(`should create a span for GET requests and add propagation when using the following signature: get(url, options, callback) and following headers: ${JSON.stringify(
headers
Expand All @@ -269,7 +311,7 @@ describe('HttpInstrumentation Integration tests', () => {
assert.strictEqual(spans.length, 0);
const options = { headers };
const req = http.get(
`${protocol}://google.fr/`,
`${protocol}://localhost:${mockServerPort}/`,
options,
(resp: http.IncomingMessage) => {
const res = (resp as unknown) as http.IncomingMessage & {
Expand All @@ -281,7 +323,7 @@ describe('HttpInstrumentation Integration tests', () => {
});
resp.on('end', () => {
validations = {
hostname: 'google.fr',
hostname: 'localhost',
httpStatusCode: 301,
httpMethod: 'GET',
pathname: '/',
Expand All @@ -298,8 +340,10 @@ describe('HttpInstrumentation Integration tests', () => {

req.on('close', () => {
const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans.length, 1);
assert.strictEqual(spans[0].name, 'HTTP GET');
const span = spans.find(s => s.kind === SpanKind.CLIENT);
assert.ok(span);
assert.strictEqual(spans.length, 2);
assert.strictEqual(span.name, 'HTTP GET');
assert.ok(data);
assert.ok(validations.reqHeaders[DummyPropagation.TRACE_CONTEXT_KEY]);
assert.ok(validations.reqHeaders[DummyPropagation.SPAN_CONTEXT_KEY]);
Expand Down
Loading

0 comments on commit 6ae8908

Please sign in to comment.