Skip to content

Commit

Permalink
Merge branch 'master' into minor
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Nov 11, 2019
2 parents 7d4191e + 3d01be6 commit 948f3c0
Show file tree
Hide file tree
Showing 34 changed files with 1,653 additions and 43 deletions.
7 changes: 5 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ jobs:
steps:
- checkout
- run:
name: Install modules and dependencies.
command: yarn install
name: Install minimal doc and lint modules globally
command: yarn global add lerna typedoc linkinator typescript gts tslint-consistent-codestyle tslint-microsoft-contrib
- run:
name: Symlink global modules into all lerna packages
command: lerna exec 'ln -s $(yarn global dir)/node_modules node_modules'
- run:
name: Check code style and linting
command: yarn run check
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ OpenTelemetry is vendor-agnostic and can upload data to any backend with various

OpenTelemetry can collect tracing data automatically using plugins. Vendors/Users can also create and use their own. Currently, OpenTelemetry supports automatic tracing for:

#### Node Plugins
- [@opentelemetry/plugin-http](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-http)
- [@opentelemetry/plugin-grpc](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-grpc)
- [@opentelemetry/plugin-https](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-https)
- [@opentelemetry/plugin-dns](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-dns)
- [@opentelemetry/plugin-mongodb](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-mongodb) - WIP
- [@opentelemetry/plugin-postgres](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-postgres) - WIP

#### Web Plugins
- [@opentelemetry/plugin-document-load](https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-plugin-document-load)

To request automatic tracing support for a module not on this list, please [file an issue](https://github.com/open-telemetry/opentelemetry-js/issues). Alternatively, you can [write a plugin yourself](https://github.com/open-telemetry/opentelemetry-js/blob/master/doc/plugin-guide.md).

### Shims
Expand Down
3 changes: 3 additions & 0 deletions examples/tracer-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<body>
Example of using Web Tracer with document load plugin and console exporter
<script type="text/javascript" src="/bundle.js"></script>
<br/>
<button id="button1">Test WebTracer with ZoneScopeManager - async</button>

</body>

</html>
74 changes: 73 additions & 1 deletion examples/tracer-web/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,83 @@
import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
import { WebTracer } from '@opentelemetry/web';
import { DocumentLoad } from '@opentelemetry/plugin-document-load';
import { ZoneScopeManager } from '@opentelemetry/scope-zone';

const webTracer = new WebTracer({
plugins: [
new DocumentLoad()
]
});

webTracer.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));

const webTracerWithZone = new WebTracer({
scopeManager: new ZoneScopeManager(),
plugins: [
new DocumentLoad()
]
});
webTracerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));

console.log('Current span is window', webTracerWithZone.getCurrentSpan() === window);

// example of keeping track of scope between async operations
const prepareClickEvent = () => {
const url1 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/package.json';
const url2 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/master/packages/opentelemetry-web/package.json';

const element = document.getElementById('button1');
let mainSpan = webTracerWithZone.startSpan('main-span');
webTracerWithZone.bind(element, mainSpan);

const onClick = () => {
const span1 = webTracerWithZone.startSpan(`files-series-info-1`, {
parent: webTracerWithZone.getCurrentSpan()
});

const span2 = webTracerWithZone.startSpan(`files-series-info-2`, {
parent: webTracerWithZone.getCurrentSpan()
});

webTracerWithZone.withSpan(span1, () => {
getData(url1).then((data) => {
console.log('current span is span1', webTracerWithZone.getCurrentSpan() === span1);
console.log('info from package.json', data.description, data.version);
webTracerWithZone.getCurrentSpan().addEvent('fetching-span1-completed');
span1.end();
});
});

webTracerWithZone.withSpan(span2, () => {
getData(url2).then((data) => {
setTimeout(() => {
console.log('current span is span2', webTracerWithZone.getCurrentSpan() === span2);
console.log('info from package.json', data.description, data.version);
webTracerWithZone.getCurrentSpan().addEvent('fetching-span2-completed');
span2.end();
}, 100);
});
});
};
element.addEventListener('click', onClick);
};

const getData = (url) => {
return new Promise(async (resolve, reject) => {
const req = new XMLHttpRequest();
req.open('GET', url, true);
req.send();
req.onload = function () {
let json;
try {
json = JSON.parse(req.responseText);
} catch (e) {
reject(e);
}
resolve(json);
};
});
};

window.addEventListener('load', () => {
prepareClickEvent();
});
1 change: 1 addition & 0 deletions examples/tracer-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"@opentelemetry/plugin-document-load": "^0.2.0",
"@opentelemetry/scope-zone": "^0.2.0",
"@opentelemetry/tracing": "^0.2.0",
"@opentelemetry/web": "^0.2.0"
},
Expand Down
10 changes: 0 additions & 10 deletions examples/tracer-web/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ const common = {
}
]
},
plugins: [
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery'
})
],
resolve: {
modules: [
path.resolve(mainPath, 'src'),
Expand All @@ -52,8 +44,6 @@ module.exports = webpackMerge(common, {
},
devServer: {
contentBase: path.resolve(__dirname),
// contentBase: path.resolve('.'),
// historyApiFallback: true
},
plugins: [
new webpack.DefinePlugin({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class DocumentLoad extends BasePlugin<unknown> {
});
} else {
// // fallback to previous version
const perf: (typeof otperformance) & PerformanceLegacy = otperformance;
const perf: typeof otperformance & PerformanceLegacy = otperformance;
const performanceTiming = perf.timing;
if (performanceTiming) {
const keys = Object.values(PTN);
Expand Down
9 changes: 6 additions & 3 deletions packages/opentelemetry-plugin-grpc/src/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,12 @@ export class GrpcPlugin extends BasePlugin<grpc> {
parent: currentSpan || undefined,
})
.setAttribute(AttributeNames.COMPONENT, GrpcPlugin.component);
return plugin._makeGrpcClientRemoteCall(original, args, this, plugin)(
span
);
return plugin._makeGrpcClientRemoteCall(
original,
args,
this,
plugin
)(span);
};
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-http/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export class HttpPlugin extends BasePlugin<Http> {
span: Span,
execute: T,
rethrow: K
): K extends true ? ReturnType<T> : (ReturnType<T> | void);
): K extends true ? ReturnType<T> : ReturnType<T> | void;
private _safeExecute<T extends (...args: unknown[]) => ReturnType<T>>(
span: Span,
execute: T,
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-http/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type RequestSignature = [http.RequestOptions, HttpCallbackOptional] &
export type HttpRequestArgs = Array<HttpCallbackOptional | RequestSignature>;

export type ParsedRequestOptions =
| http.RequestOptions & Partial<url.UrlWithParsedQuery>
| (http.RequestOptions & Partial<url.UrlWithParsedQuery>)
| http.RequestOptions;
export type Http = typeof http;
/* tslint:disable-next-line:no-any */
Expand Down
4 changes: 3 additions & 1 deletion packages/opentelemetry-plugin-http/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export const getAbsoluteUrl = (
// it should be displayed if it's not 80 and 443 (default ports)
if (
(host as string).indexOf(':') === -1 &&
(port && port !== '80' && port !== '443')
port &&
port !== '80' &&
port !== '443'
) {
host += `:${port}`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ export class PostgresPlugin extends BasePlugin<typeof pgTypes> {
const parentSpan = plugin._tracer.getCurrentSpan();
if (typeof args[args.length - 1] === 'function') {
// Patch ParameterQuery callback
args[args.length - 1] = utils.patchCallback(span, args[
args.length - 1
] as PostgresCallback);
args[args.length - 1] = utils.patchCallback(
span,
args[args.length - 1] as PostgresCallback
);
// If a parent span exists, bind the callback
if (parentSpan) {
args[args.length - 1] = plugin._tracer.bind(
Expand Down
Loading

0 comments on commit 948f3c0

Please sign in to comment.