forked from open-telemetry/opentelemetry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Node/browser specific code to platform folder, add browser tests (…
…open-telemetry#84) * Setup `platform` folder and add browser tests * Add @types/webpack-env to fix TS compile error * Add CHROME_BIN environment variable for CircleCI * Use the Node 12 with browsers CircleCI image
- Loading branch information
1 parent
ca9641f
commit ce8446d
Showing
11 changed files
with
260 additions
and
6 deletions.
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
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,31 @@ | ||
/** | ||
* 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'); | ||
|
||
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}, | ||
}); | ||
}; |
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
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,44 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
// IE 11 exposes `crypto` as `msCrypto`. | ||
declare type WindowWithMsCrypto = Window & { | ||
msCrypto?: Crypto; | ||
}; | ||
const cryptoLib = window.crypto || (window as WindowWithMsCrypto).msCrypto; | ||
|
||
const SPAN_ID_BYTES = 8; | ||
const spanBytesArray = new Uint8Array(SPAN_ID_BYTES); | ||
|
||
/** Returns a random 16-byte trace ID formatted as a 32-char hex string. */ | ||
export function randomTraceId(): string { | ||
return randomSpanId() + randomSpanId(); | ||
} | ||
|
||
/** Returns a random 8-byte span ID formatted as a 16-char hex string. */ | ||
export function randomSpanId(): string { | ||
let spanId = ''; | ||
cryptoLib.getRandomValues(spanBytesArray); | ||
for (let i = 0; i < SPAN_ID_BYTES; i++) { | ||
const hexStr = spanBytesArray[i].toString(16); | ||
|
||
// Zero pad bytes whose hex values are single digit. | ||
if (hexStr.length === 1) spanId += '0'; | ||
|
||
spanId += hexStr; | ||
} | ||
return spanId; | ||
} |
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,17 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
export * from './id'; |
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,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 | ||
* | ||
* 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. | ||
*/ | ||
|
||
// Use the node platform by default. The "browser" field of package.json is used | ||
// to override this file to use `./browser/index.ts` when packaged with | ||
// webpack, Rollup, etc. | ||
export * from './node'; |
File renamed without changes.
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,17 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
export * from './id'; |
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,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 | ||
* | ||
* 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. | ||
*/ | ||
|
||
// 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); |
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
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,86 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
// This is the webpack configuration for browesr Karma tests. | ||
module.exports = { | ||
mode: 'development', | ||
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, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |