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

Commit

Permalink
Add configuration support to tracing instrumentation (#160)
Browse files Browse the repository at this point in the history
* Add support for supplying instrumentation configuration via tracing option. Option argument added to instrumentation interface.
* Add ignoreIncomingPaths and ignoreOutgoingUrls support to the http and https tracing instrumentations.
  • Loading branch information
whs authored and justindsmith committed Dec 21, 2018
1 parent f639c4d commit 52c304e
Show file tree
Hide file tree
Showing 30 changed files with 336 additions and 135 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.
- Add Metrics API.
- Add Resource API.
- Add Gauges (`DoubleGauge`, `LongGauge`, `DerivedDoubleGauge`, `DerivedLongGauge`) APIs.
- Add support for supplying instrumentation configuration via tracing option. Option argument added to instrumentation interface.
- Add ignoreIncomingPaths and ignoreOutgoingUrls support to the http and https tracing instrumentations.

## 0.0.8 - 2018-12-14
**Contains API breaking changes for stats/metrics implementations**
Expand Down
158 changes: 79 additions & 79 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/opencensus-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions packages/opencensus-core/src/trace/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export interface BufferConfig {
export interface TracerConfig {
/** Determines the sampling rate. Ranges from 0.0 to 1.0 */
samplingRate?: number;
/** Determines the ignored (or blacklisted) URLs */
ignoreUrls?: Array<string|RegExp>;
/** A logger object */
logger?: Logger;
/** A propagation instance */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export abstract class BasePlugin implements types.Plugin {
protected internalFilesExports: ModuleExportsMapping;
/** module directory - used to load internal files */
protected basedir: string;
/** plugin options */
protected options: types.PluginConfig;

/**
* Constructs a new BasePlugin instance.
Expand All @@ -61,17 +63,19 @@ export abstract class BasePlugin implements types.Plugin {
* @param moduleExports nodejs module exports to set as context
* @param tracer tracer relating to context
* @param version module version description
* @param options plugin options
* @param basedir module absolute path
*/
private setPluginContext(
// tslint:disable-next-line:no-any
moduleExports: any, tracer: modelTypes.Tracer, version: string,
basedir?: string) {
options: types.PluginConfig, basedir?: string) {
this.moduleExports = moduleExports;
this.tracer = tracer;
this.version = version;
this.basedir = basedir;
this.logger = tracer.logger;
this.options = options;
this.internalFilesExports = this.loadInternalFiles();
}

Expand All @@ -85,13 +89,14 @@ export abstract class BasePlugin implements types.Plugin {
* @param moduleExports nodejs module exports from the module to patch
* @param tracer a tracer instance
* @param version version of the current instaled module to patch
* @param options plugin options
* @param basedir module absolute path
*/
enable<T>(
// tslint:disable-next-line:no-any
moduleExports: T, tracer: modelTypes.Tracer, version: string,
basedir: string) {
this.setPluginContext(moduleExports, tracer, version, basedir);
options: types.PluginConfig, basedir: string) {
this.setPluginContext(moduleExports, tracer, version, options, basedir);
return this.applyPatch();
}

Expand Down Expand Up @@ -146,7 +151,7 @@ export abstract class BasePlugin implements types.Plugin {
* Load internal files from a module and set internalFilesExports
*/
private loadInternalModuleFiles(
extraModulesList: types.PluginNames,
extraModulesList: types.PluginInternalFilesVersion,
basedir: string): ModuleExportsMapping {
const extraModules: ModuleExportsMapping = {};
if (extraModulesList) {
Expand Down
18 changes: 16 additions & 2 deletions packages/opencensus-core/src/trace/instrumentation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,45 @@ export interface Plugin {
* @param moduleExports nodejs module exports from the module to patch
* @param tracer a tracer instance
* @param version version of the current instaled module to patch
* @param options plugin options
* @param basedir module absolute path
*/
enable(
// tslint:disable-next-line:no-any
moduleExports: any, tracer: Tracer, version: string,
options: PluginConfig,
// tslint:disable-next-line:no-any
basedir?: string): any;
/** Method to disable the instrumentation */
disable(): void;
}

export type PluginConfig = {
// tslint:disable-next-line:no-any
[key: string]: any;
};

export type NamedPluginConfig = {
module: string; config: PluginConfig;
};

/**
* Type PluginNames: each key should be the name of the module to trace,
* and its value should be the name of the package which has the
* plugin implementation.
*/
export type PluginNames = {
[pluginName: string]: string;
[pluginName: string]: string|NamedPluginConfig;
};

export type PluginInternalFilesVersion = {
[pluginName: string]: string
};

/**
* Each key should be the name of the module to trace, and its value
* a mapping of a property name to a internal plugin file name.
*/
export type PluginInternalFiles = {
[versions: string]: PluginNames;
[versions: string]: PluginInternalFilesVersion;
};
8 changes: 5 additions & 3 deletions packages/opencensus-core/src/trace/model/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ export class CoreTracer implements types.Tracer {
}
}
const aRoot = new RootSpan(this, options);
const sampleDecision: boolean = propagatedSample ?
propagatedSample :
this.sampler.shouldSample(aRoot.traceId);

let sampleDecision: boolean = propagatedSample;
if (!sampleDecision) {
sampleDecision = this.sampler.shouldSample(aRoot.traceId);
}

if (sampleDecision) {
this.currentRootSpan = aRoot;
Expand Down
2 changes: 1 addition & 1 deletion packages/opencensus-exporter-instana/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/opencensus-exporter-prometheus/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions packages/opencensus-exporter-stackdriver/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/opencensus-exporter-zipkin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/opencensus-exporter-zpages/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/opencensus-instrumentation-grpc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/opencensus-instrumentation-grpc/test/test-grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ describe('GrpcPlugin() ', function() {
before(() => {
const basedir = path.dirname(require.resolve('grpc'));
const version = require(path.join(basedir, 'package.json')).version;
plugin.enable(grpcModule, tracer, version, basedir);
plugin.enable(grpcModule, tracer, version, {}, basedir);
tracer.registerSpanEventListener(rootSpanVerifier);
const proto = grpcModule.load(PROTO_PATH).pkg_test;
server = startServer(grpcModule, proto);
Expand Down
2 changes: 1 addition & 1 deletion packages/opencensus-instrumentation-http/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 52c304e

Please sign in to comment.