Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

pass stats instance to plugin loader #386

Merged

Conversation

mayurkale22
Copy link
Member

Allow a way to pass stats instance to PluginLoader class, this will help users to collect stats for HTTP and GRPC plugin with automatic tracing.

Also, I have updated the HTTP instrumentation example to capture traces without manually enabling the plugin. I think this is the recommended and straightforward way for users to enable tracing on supported plugins/frameworks.

@codecov-io
Copy link

codecov-io commented Mar 4, 2019

Codecov Report

Merging #386 into master will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #386      +/-   ##
==========================================
- Coverage    94.7%   94.65%   -0.06%     
==========================================
  Files         150      150              
  Lines        9785     9594     -191     
  Branches      739      720      -19     
==========================================
- Hits         9267     9081     -186     
+ Misses        518      513       -5
Impacted Files Coverage Δ
test/test-tracecontext-format.ts 95.45% <0%> (-3.62%) ⬇️
test/test-jaeger-format.ts 93.75% <0%> (-1.64%) ⬇️
src/tracecontext-format.ts 95% <0%> (-1.43%) ⬇️
src/common-utils.ts 95.23% <0%> (-0.6%) ⬇️
test/test-prometheus-stats.ts 100% <0%> (ø) ⬆️
src/validators.ts 100% <0%> (ø) ⬆️
src/stackdriver-monitoring.ts 82.29% <0%> (+2.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cbd1d99...9764cc6. Read the comment docs.

Copy link
Contributor

@draffensperger draffensperger left a comment

Choose a reason for hiding this comment

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

LGTM with just some style nits and a question

@@ -21,7 +21,6 @@
},
"dependencies": {
"@opencensus/exporter-zipkin": "^0.0.9",
"@opencensus/instrumentation-http": "^0.0.9",
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why is this no longer needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are two ways to instrument supported plugins. 1) Manual approach: include respective dependency and use plugin.enable(...) interface. 2) Allow the library to instrument plugins automatically, for this start the trace instance as the first module in your application.

The changed the HTTP example to work with second (I think recommended) approach.

@@ -49,9 +51,10 @@ export class PluginLoader {
* Constructs a new PluginLoader instance.
* @param tracer The tracer.
*/
constructor(logger: Logger, tracer: Tracer) {
constructor(logger: Logger, tracer: Tracer, stats: Stats|undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just have it be stats?: Stats?

@@ -140,8 +142,14 @@ export class PluginLoader {
try {
const plugin: Plugin = require(moduleName as string).plugin;
this.plugins.push(plugin);
return plugin.enable(
exports, this.tracer, version, moduleConfig, basedir);
if (this.stats) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing the type signature above to make stats optional would also allow collapsing down the two branches of this if

@@ -94,7 +94,7 @@ describe('Plugin Loader', () => {
});

it('should load a plugin and patch the target modules', () => {
const pluginLoader = new PluginLoader(log, tracer);
const pluginLoader = new PluginLoader(log, tracer, undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes to pass undefined would also be unnecessary with it being optional.

@mayurkale22 mayurkale22 merged commit 27de0b1 into census-instrumentation:master Apr 1, 2019
@mayurkale22 mayurkale22 deleted the automatic_tracing branch April 1, 2019 22:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants