Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracer web #334

Merged
merged 42 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d9d152d
feat(tracer-web): adding tracer web
obecny Sep 24, 2019
ab74943
feat(basic-tracer): adding karma tests
obecny Sep 24, 2019
8cfea09
feat(tracer-web): adding some example for easier debugging in browser…
obecny Sep 24, 2019
873a287
fix: conflicts with master
obecny Sep 24, 2019
9e37fb9
fix: lint
obecny Sep 24, 2019
d10fbdd
fix: creating base for karma
obecny Sep 25, 2019
62965ad
fix: fixing problem with target for browser, cleanup tests
obecny Sep 25, 2019
354930d
Merge branch 'master' into tracer-web
danielkhan Sep 27, 2019
e8b7503
refactor: moving polyfills for node karma tests to one file
obecny Sep 30, 2019
117c10f
fix: adding missing package
obecny Sep 30, 2019
d5129ca
refactor: removing unneeded file
obecny Sep 30, 2019
8eca21f
refactor: prefixing privates, cleanup
obecny Sep 30, 2019
74941c1
fix: duplicate package
obecny Sep 30, 2019
a7616f1
refactor: aligning tslint with other tslint packages
obecny Sep 30, 2019
62406aa
refactor: cleanups, adding comments for class
obecny Sep 30, 2019
757458c
fix: merge branch 'master' into tracer-web
obecny Sep 30, 2019
2ff8c62
Merge branch 'tracer-web' of github.com:obecny/opentelemetry-js into …
obecny Sep 30, 2019
ca873bf
fix: linting
obecny Sep 30, 2019
c8c81c1
fix: type
obecny Sep 30, 2019
446c8c7
refactor: generation of id for scope
obecny Sep 30, 2019
c44c1a5
refactor: removed previous uid for scope as originally it was meant t…
obecny Sep 30, 2019
a430a4f
chore: adding test for restoring scope
obecny Sep 30, 2019
a0fd67f
Merge branch 'master' into tracer-web
obecny Sep 30, 2019
a2db249
fix: lint
obecny Sep 30, 2019
41a4d27
refactor: simplifying the stack scope manager
obecny Oct 2, 2019
28614f2
chore: updating readme with basic example
obecny Oct 2, 2019
835b31b
chore: merge branch 'master' into tracer-web
obecny Oct 2, 2019
fdc3162
chore: fixes after merge
obecny Oct 2, 2019
8be9ed7
fix: updating test to accept greater or equal - fails on browser
obecny Oct 2, 2019
50ec127
refactor: moving example for web tracer
obecny Oct 2, 2019
8f6ae2c
refactor: removing WebTracerConfig to use BasicTracerConfig which cha…
obecny Oct 2, 2019
104ba4b
chore: updating types
obecny Oct 3, 2019
b0eb537
chore: spacing
obecny Oct 3, 2019
04eced8
chore: removing mocha tests for tracer-web
obecny Oct 3, 2019
e90b49f
chore: updating types and linting
obecny Oct 3, 2019
a57fdc8
chore: merge branch 'master' into tracer-web
obecny Oct 3, 2019
5df0726
chore: updating packages after merge
obecny Oct 3, 2019
61fc904
chore: adding nyc report for karma tests for browser
obecny Oct 3, 2019
d0579b9
chore: updating lerna script to run coverage for browsers
obecny Oct 3, 2019
1dfc09f
feat(tracer-web): bump version to 0.1.0
obecny Oct 4, 2019
92d5694
Merge branch 'master' into tracer-web
obecny Oct 4, 2019
3091a89
Merge branch 'master' into tracer-web
mayurkale22 Oct 7, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions karma.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

module.exports = {
listenAddress: 'localhost',
hostname: 'localhost',
browsers: ['ChromeHeadless'],
frameworks: ['mocha'],
reporters: ['spec'],
files: ['test/index-webpack.ts'],
preprocessors: { 'test/index-webpack.ts': ['webpack'] },
webpackMiddleware: { noInfo: true }
};
24 changes: 24 additions & 0 deletions packages/opentelemetry-basic-tracer/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const webpackConfig = require('./webpack/test.config.js');
const karmaBaseConfig = require('../../karma.base');

module.exports = (config) => {
obecny marked this conversation as resolved.
Show resolved Hide resolved
config.set(Object.assign({}, karmaBaseConfig, {
webpack: webpackConfig
}))
};
19 changes: 16 additions & 3 deletions packages/opentelemetry-basic-tracer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
"version": "0.0.1",
"description": "OpenTelemetry Basic Tracer",
"main": "build/src/index.js",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts",
obecny marked this conversation as resolved.
Show resolved Hide resolved
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
},
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json test/**/**/*.ts",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.ts' --exclude 'test/index-webpack.ts'",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have already excluded test/index-webpack.ts in .nycrc. https://github.com/open-telemetry/opentelemetry-js/blob/master/.nycrc#L11

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I remove it then it doesn't work

"test:browser": "karma start --single-run",
"tdd": "yarn test -- --watch-extensions ts --watch",
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"clean": "rimraf build/*",
Expand Down Expand Up @@ -40,16 +45,24 @@
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^12.6.8",
"@types/webpack-env": "1.13.9",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"karma": "^4.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"karma-spec-reporter": "^0.0.32",
"karma-webpack": "^4.0.2",
"mocha": "^6.1.0",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
"tslint-consistent-codestyle":"^1.15.1",
"tslint-microsoft-contrib": "^6.2.0",
OlivierAlbertini marked this conversation as resolved.
Show resolved Hide resolved
"tslint-consistent-codestyle": "^1.15.1",
"ts-loader": "^6.0.4",
"ts-mocha": "^6.0.0",
"ts-node": "^8.0.0",
"typescript": "^3.4.5"
"typescript": "^3.4.5",
"webpack": "^4.35.2"
},
"dependencies": {
"@opentelemetry/core": "^0.0.1",
Expand Down
15 changes: 11 additions & 4 deletions packages/opentelemetry-basic-tracer/test/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import * as assert from 'assert';
import { performance } from 'perf_hooks';
import { Span } from '../src/Span';
import {
SpanKind,
Expand All @@ -25,11 +24,14 @@ import {
} from '@opentelemetry/types';
import { BasicTracer } from '../src';
import {
hrTime,
hrTimeToNanoseconds,
hrTimeToMilliseconds,
NoopLogger,
} from '@opentelemetry/core';

const performanceTimeOrigin = hrTime();

describe('Span', () => {
const tracer = new BasicTracer({
logger: new NoopLogger(),
Expand All @@ -50,7 +52,10 @@ describe('Span', () => {

it('should have valid startTime', () => {
const span = new Span(tracer, name, spanContext, SpanKind.SERVER);
assert.ok(hrTimeToMilliseconds(span.startTime) > performance.timeOrigin);
assert.ok(
hrTimeToMilliseconds(span.startTime) >
hrTimeToMilliseconds(performanceTimeOrigin)
);
});

it('should have valid endTime', () => {
Expand All @@ -62,7 +67,8 @@ describe('Span', () => {
);

assert.ok(
hrTimeToMilliseconds(span.endTime) > performance.timeOrigin,
hrTimeToMilliseconds(span.endTime) >
hrTimeToMilliseconds(performanceTimeOrigin),
'end time must be bigger than time origin'
);
});
Expand All @@ -77,7 +83,8 @@ describe('Span', () => {
const span = new Span(tracer, name, spanContext, SpanKind.SERVER);
span.addEvent('my-event');
assert.ok(
hrTimeToMilliseconds(span.events[0].time) > performance.timeOrigin
hrTimeToMilliseconds(span.events[0].time) >
hrTimeToMilliseconds(performanceTimeOrigin)
);
});

Expand Down
20 changes: 20 additions & 0 deletions packages/opentelemetry-basic-tracer/test/index-webpack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// This file is the webpack entry point for the browser Karma tests. It requires
// all modules ending in "test" from the current folder and all its subfolders.
const testsContext = require.context('.', true, /test$/);
testsContext.keys().forEach(testsContext);
34 changes: 34 additions & 0 deletions packages/opentelemetry-basic-tracer/webpack/test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*!
* Copyright 2019, OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const webpackNodePolyfills = require('../../../webpack.node-polyfills.js');

// This is the webpack configuration for browser Karma tests.
module.exports = {
mode: 'development',
target: 'web',
output: { filename: 'bundle.js' },
resolve: { extensions: ['.ts', '.js'] },
devtool: 'inline-source-map',
module: {
rules: [
{ test: /\.ts$/, use: 'ts-loader' },
// This setting configures Node polyfills for the browser that will be
// added to the webpack bundle for Karma tests.
{ parser: { node: webpackNodePolyfills } }
]
}
};
15 changes: 4 additions & 11 deletions packages/opentelemetry-core/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@
*/

const webpackConfig = require('./webpack/test.config.js');
const karmaBaseConfig = require('../../karma.base');

module.exports = (config) => {
config.set({
listenAddress: 'localhost',
hostname: 'localhost',
browsers: ['ChromeHeadless'],
frameworks: ['mocha'],
reporters: ['spec'],
files: ['test/index-webpack.ts'],
preprocessors: {'test/index-webpack.ts': ['webpack']},
webpack: webpackConfig,
webpackMiddleware: {noInfo: true},
});
config.set(Object.assign({}, karmaBaseConfig, {
webpack: webpackConfig
}))
};
3 changes: 2 additions & 1 deletion packages/opentelemetry-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "OpenTelemetry Core",
"main": "build/src/index.js",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts"
"./src/platform/index.ts": "./src/platform/browser/index.ts",
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
},
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
Expand Down
76 changes: 12 additions & 64 deletions packages/opentelemetry-core/webpack/test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,21 @@
* limitations under the License.
*/

// This is the webpack configuration for browesr Karma tests.
const webpackNodePolyfills = require('../../../webpack.node-polyfills.js');

// This is the webpack configuration for browser Karma tests.
module.exports = {
mode: 'development',
output: {filename: 'bundle.js'},
resolve: {extensions: ['.ts', '.js']},
target: 'web',
output: { filename: 'bundle.js' },
resolve: { extensions: ['.ts', '.js'] },
devtool: 'inline-source-map',
module: {
rules: [
{test: /\.ts$/, use: 'ts-loader'},
{
parser: {
// This setting configures Node polyfills for the browser that will be
// added to the webpack bundle for Karma tests.
node: {
// Enable the assert library polyfill because that is used in tests
assert: true,
// The assert polyfill from github.com/browserify/commonjs-assert
// also requires the `global` polyfill.
global: true,

// Turn off all other Node.js API polyfills for the browser tests to
// make sure that we are not attempting to use Node-specific APIs in
// the browser code. Instead, we will write browser specific
// implementations of platform functionality we need under the
// `./src/platform/browser` folder. This allows for writing browser
// optimized implementations of the specific needed functionality
// rather than bringing in (sometimes large) polyfills for the
// corresponding Node APIs.
Buffer: false,
__dirname: false,
__filename: false,
buffer: false,
child_process: false,
cluster: false,
console: false,
constants: false,
crypto: false,
dgram: false,
dns: false,
domain: false,
events: false,
fs: false,
http: false,
https: false,
module: false,
net: false,
os: false,
path: false,
process: false,
punycode: false,
querystring: false,
readline: false,
repl: false,
setImmediate: false,
stream: false,
string_decoder: false,
sys: false,
timers: false,
tls: false,
tty: false,
url: false,
util: false,
vm: false,
zlib: false,
},
},
},
],
},
{ test: /\.ts$/, use: 'ts-loader' },
// This setting configures Node polyfills for the browser that will be
// added to the webpack bundle for Karma tests.
{ parser: { node: webpackNodePolyfills } }
]
}
};
4 changes: 4 additions & 0 deletions packages/opentelemetry-tracer-web/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/bin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of opentelemetry-tracer-web, what do you think about opentelemetry-web-tracer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this name has been already decided in OpenTelem web draft I don't have strong opinion on that but personally I would keep opentelemetry-tracer-web, opentelemetry-tracer-node, opentelemetry-tracer-basic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mayurkale22 so what do you think about it ?, I'm fine for both, but I didn't propose opentelemetry-tracer-web although thinking this name to be easier as we can have then the namespace of opentelemetry-tracer-*

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with opentelemetry-tracer-web, which means we need to rename opentelemetry-basic-tracer -> opentelemetry-tracer-basic.

/coverage
/doc
/test
Loading