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 all 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
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ browsers_unit_tests: &browsers_unit_tests
- run:
name: Unit tests
command: yarn test:browser
- run:
name: report coverage
command: yarn codecov:browser

jobs:
lint:
Expand Down
17 changes: 17 additions & 0 deletions examples/tracer-web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>JS Example</title>
<base href="/">

<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
Testing, debugging in development
<script type="text/javascript" src="/bundle.js"></script>
</body>

</html>
38 changes: 38 additions & 0 deletions examples/tracer-web/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { WebTracer } from '@opentelemetry/tracer-web';

import * as shimmer from 'shimmer';

class Tester {
constructor() {
}
add(name) {
console.log('calling add', name);
}
}

const tester = new Tester();

const webTracer = new WebTracer();
const span = webTracer.startSpan('span1');

shimmer.wrap(Tester.prototype, 'add', (originalFunction) => {
return function patchedFunction() {
try {
span.addEvent('start');
} catch (e) {
console.log('error', e);
} finally {
const result = originalFunction.apply(this, arguments);
span.addEvent('after call');
span.end();
return result;
}
};
});

webTracer.withSpan(span, function () {
console.log(this === span);
});

tester.add('foo');
console.log(span);
41 changes: 41 additions & 0 deletions examples/tracer-web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "web-tracer-example",
"private": true,
"version": "0.1.0",
"description": "Example of using @opentelemetry/tracer-web in browser",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server -d --progress --colors --port 8090 --config webpack.config.js --hot --inline --host 0.0.0.0"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/open-telemetry/opentelemetry-js.git"
},
"keywords": [
"opentelemetry",
"tracing",
"web"
],
"engines": {
"node": ">=8"
},
"author": "OpenTelemetry Authors",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@types/shimmer": "^1.0.1",
"babel-loader": "^8.0.6",
"shimmer": "^1.2.0",
"webpack": "^4.35.2",
"webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.8.1",
"webpack-merge": "^4.2.2"
},
"dependencies": {
"@opentelemetry/tracer-web": "^0.1.0"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme"
}
63 changes: 63 additions & 0 deletions examples/tracer-web/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const path = require('path');
const mainPath = path.resolve('');
const directory = path.resolve(__dirname);

const common = {
mode: 'development',
entry: 'index.js',
target: 'web',
module: {
rules: [
{
test: /\.js[x]?$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.ts$/,
exclude: /(node_modules)/,
use: {
loader: 'ts-loader'
}
}
]
},
plugins: [
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery'
})
],
resolve: {
modules: [
path.resolve(mainPath, 'src'),
path.resolve(directory),
'node_modules'
],
extensions: ['.ts', '.js', '.jsx', '.json']
}
};

module.exports = webpackMerge(common, {
devtool: 'eval-source-map',
output: {
filename: 'bundle.js',
sourceMapFilename: '[file].map'
},
devServer: {
contentBase: path.resolve(__dirname),
// contentBase: path.resolve('.'),
// historyApiFallback: true
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
]
});
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 }
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"scripts": {
"clean": "lerna run clean",
"fix": "lerna run fix",
"postinstall": "yarn run bootstrap",
"compile": "lerna run compile",
Expand All @@ -13,6 +14,7 @@
"bootstrap": "lerna bootstrap",
"bump": "lerna publish",
"codecov": "lerna run codecov",
"codecov:browser": "lerna run codecov:browser",
"check": "lerna run check",
"predocs-test": "yarn docs",
"docs-test": "lerna run docs-test",
Expand Down
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 } }
]
}
};
24 changes: 24 additions & 0 deletions packages/opentelemetry-tracer-basic/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) => {
config.set(Object.assign({}, karmaBaseConfig, {
webpack: webpackConfig
}))
};
Loading