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

Commit 52c304e

Browse files
whsjustindsmith
authored andcommitted
Add configuration support to tracing instrumentation (#160)
* 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.
1 parent f639c4d commit 52c304e

30 files changed

Lines changed: 336 additions & 135 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.
66
- Add Metrics API.
77
- Add Resource API.
88
- Add Gauges (`DoubleGauge`, `LongGauge`, `DerivedDoubleGauge`, `DerivedLongGauge`) APIs.
9+
- Add support for supplying instrumentation configuration via tracing option. Option argument added to instrumentation interface.
10+
- Add ignoreIncomingPaths and ignoreOutgoingUrls support to the http and https tracing instrumentations.
911

1012
## 0.0.8 - 2018-12-14
1113
**Contains API breaking changes for stats/metrics implementations**

package-lock.json

Lines changed: 79 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-core/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-core/src/trace/config/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export interface BufferConfig {
3333
export interface TracerConfig {
3434
/** Determines the sampling rate. Ranges from 0.0 to 1.0 */
3535
samplingRate?: number;
36-
/** Determines the ignored (or blacklisted) URLs */
37-
ignoreUrls?: Array<string|RegExp>;
3836
/** A logger object */
3937
logger?: Logger;
4038
/** A propagation instance */

packages/opencensus-core/src/trace/instrumentation/base-plugin.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export abstract class BasePlugin implements types.Plugin {
4747
protected internalFilesExports: ModuleExportsMapping;
4848
/** module directory - used to load internal files */
4949
protected basedir: string;
50+
/** plugin options */
51+
protected options: types.PluginConfig;
5052

5153
/**
5254
* Constructs a new BasePlugin instance.
@@ -61,17 +63,19 @@ export abstract class BasePlugin implements types.Plugin {
6163
* @param moduleExports nodejs module exports to set as context
6264
* @param tracer tracer relating to context
6365
* @param version module version description
66+
* @param options plugin options
6467
* @param basedir module absolute path
6568
*/
6669
private setPluginContext(
6770
// tslint:disable-next-line:no-any
6871
moduleExports: any, tracer: modelTypes.Tracer, version: string,
69-
basedir?: string) {
72+
options: types.PluginConfig, basedir?: string) {
7073
this.moduleExports = moduleExports;
7174
this.tracer = tracer;
7275
this.version = version;
7376
this.basedir = basedir;
7477
this.logger = tracer.logger;
78+
this.options = options;
7579
this.internalFilesExports = this.loadInternalFiles();
7680
}
7781

@@ -85,13 +89,14 @@ export abstract class BasePlugin implements types.Plugin {
8589
* @param moduleExports nodejs module exports from the module to patch
8690
* @param tracer a tracer instance
8791
* @param version version of the current instaled module to patch
92+
* @param options plugin options
8893
* @param basedir module absolute path
8994
*/
9095
enable<T>(
9196
// tslint:disable-next-line:no-any
9297
moduleExports: T, tracer: modelTypes.Tracer, version: string,
93-
basedir: string) {
94-
this.setPluginContext(moduleExports, tracer, version, basedir);
98+
options: types.PluginConfig, basedir: string) {
99+
this.setPluginContext(moduleExports, tracer, version, options, basedir);
95100
return this.applyPatch();
96101
}
97102

@@ -146,7 +151,7 @@ export abstract class BasePlugin implements types.Plugin {
146151
* Load internal files from a module and set internalFilesExports
147152
*/
148153
private loadInternalModuleFiles(
149-
extraModulesList: types.PluginNames,
154+
extraModulesList: types.PluginInternalFilesVersion,
150155
basedir: string): ModuleExportsMapping {
151156
const extraModules: ModuleExportsMapping = {};
152157
if (extraModulesList) {

packages/opencensus-core/src/trace/instrumentation/types.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,45 @@ export interface Plugin {
2424
* @param moduleExports nodejs module exports from the module to patch
2525
* @param tracer a tracer instance
2626
* @param version version of the current instaled module to patch
27+
* @param options plugin options
2728
* @param basedir module absolute path
2829
*/
2930
enable(
3031
// tslint:disable-next-line:no-any
3132
moduleExports: any, tracer: Tracer, version: string,
33+
options: PluginConfig,
3234
// tslint:disable-next-line:no-any
3335
basedir?: string): any;
3436
/** Method to disable the instrumentation */
3537
disable(): void;
3638
}
3739

40+
export type PluginConfig = {
41+
// tslint:disable-next-line:no-any
42+
[key: string]: any;
43+
};
44+
45+
export type NamedPluginConfig = {
46+
module: string; config: PluginConfig;
47+
};
3848

3949
/**
4050
* Type PluginNames: each key should be the name of the module to trace,
4151
* and its value should be the name of the package which has the
4252
* plugin implementation.
4353
*/
4454
export type PluginNames = {
45-
[pluginName: string]: string;
55+
[pluginName: string]: string|NamedPluginConfig;
56+
};
57+
58+
export type PluginInternalFilesVersion = {
59+
[pluginName: string]: string
4660
};
4761

4862
/**
4963
* Each key should be the name of the module to trace, and its value
5064
* a mapping of a property name to a internal plugin file name.
5165
*/
5266
export type PluginInternalFiles = {
53-
[versions: string]: PluginNames;
67+
[versions: string]: PluginInternalFilesVersion;
5468
};

packages/opencensus-core/src/trace/model/tracer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ export class CoreTracer implements types.Tracer {
123123
}
124124
}
125125
const aRoot = new RootSpan(this, options);
126-
const sampleDecision: boolean = propagatedSample ?
127-
propagatedSample :
128-
this.sampler.shouldSample(aRoot.traceId);
126+
127+
let sampleDecision: boolean = propagatedSample;
128+
if (!sampleDecision) {
129+
sampleDecision = this.sampler.shouldSample(aRoot.traceId);
130+
}
129131

130132
if (sampleDecision) {
131133
this.currentRootSpan = aRoot;

packages/opencensus-exporter-instana/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-exporter-prometheus/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-exporter-stackdriver/package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)