Skip to content

Commit

Permalink
Merge branch 'main' into env-span-sdk-default
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud authored Apr 12, 2021
2 parents 9a22011 + 5dbe53a commit 6b57817
Show file tree
Hide file tree
Showing 32 changed files with 290 additions and 174 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,10 @@ To request automatic tracing support for a module not on this list, please [file

## Upgrade guidelines

### 0.19.0 to 1.0.0-rc.0
### 0.18.x to 0.19.0

- All plugins have been removed in favor of instrumentations.

### 0.18.0 to 0.19.0


- The `@opentelemetry/propagator-b3` package previously exported three propagators: `B3Propagator`,`B3SinglePropagator`, and `B3MultiPropagator`, but now only exports the `B3Propagator`. It extracts b3 context in single and multi-header encodings, and injects context using the single-header encoding by default, but can be configured to inject context using the multi-header endcoding during construction: `new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER })`. If you were previously using the `B3SinglePropagator` or `B3MultiPropagator` directly, you should update your code to use the `B3Propagator` with the appropriate configuration. See the [readme](./packages/opentelemetry-propagator-b3/readme.md) for full details and usage.

### 0.17.0 to 0.18.0
Expand Down
4 changes: 2 additions & 2 deletions backwards-compatability/node10/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"test:backcompat": "tsc --noEmit index.ts"
},
"dependencies": {
"@opentelemetry/sdk-node": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2"
"@opentelemetry/sdk-node": "0.18.2",
"@opentelemetry/tracing": "0.18.2"
},
"devDependencies": {
"@types/node": "10.17.56",
Expand Down
4 changes: 2 additions & 2 deletions backwards-compatability/node12/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"test:backcompat": "tsc --noEmit index.ts"
},
"dependencies": {
"@opentelemetry/sdk-node": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2"
"@opentelemetry/sdk-node": "0.18.2",
"@opentelemetry/tracing": "0.18.2"
},
"devDependencies": {
"@types/node": "12.20.7",
Expand Down
4 changes: 2 additions & 2 deletions backwards-compatability/node8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"test:backcompat": "tsc --noEmit index.ts"
},
"dependencies": {
"@opentelemetry/sdk-node": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2"
"@opentelemetry/sdk-node": "0.18.2",
"@opentelemetry/tracing": "0.18.2"
},
"devDependencies": {
"@types/node": "8.10.66",
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/propagation-validation-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"compile": "tsc --build"
},
"dependencies": {
"@opentelemetry/context-async-hooks": "^0.18.2",
"@opentelemetry/core": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2",
"@opentelemetry/context-async-hooks": "0.18.2",
"@opentelemetry/core": "0.18.2",
"@opentelemetry/tracing": "0.18.2",
"axios": "0.21.1",
"body-parser": "1.19.0",
"express": "4.17.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-context-zone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"webpack-merge": "5.7.3"
},
"dependencies": {
"@opentelemetry/context-zone-peer-dep": "^0.18.2",
"@opentelemetry/context-zone-peer-dep": "0.18.2",
"zone.js": "^0.11.0"
},
"sideEffects": true
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"devDependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/propagator-b3": "^0.18.2",
"@opentelemetry/propagator-b3": "0.18.2",
"@types/mocha": "8.2.2",
"@types/node": "14.14.37",
"@types/semver": "7.3.4",
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry-exporter-collector-grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"devDependencies": {
"@babel/core": "7.13.14",
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/api-metrics": "^0.18.2",
"@opentelemetry/api-metrics": "0.18.2",
"@types/mocha": "8.2.2",
"@types/node": "14.14.37",
"@types/sinon": "9.0.11",
Expand All @@ -68,11 +68,11 @@
},
"dependencies": {
"@grpc/proto-loader": "^0.5.4",
"@opentelemetry/core": "^0.18.2",
"@opentelemetry/exporter-collector": "^0.18.2",
"@opentelemetry/metrics": "^0.18.2",
"@opentelemetry/resources": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2",
"@opentelemetry/core": "0.18.2",
"@opentelemetry/exporter-collector": "0.18.2",
"@opentelemetry/metrics": "0.18.2",
"@opentelemetry/resources": "0.18.2",
"@opentelemetry/tracing": "0.18.2",
"grpc": "^1.24.2"
}
}
12 changes: 6 additions & 6 deletions packages/opentelemetry-exporter-collector-proto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"devDependencies": {
"@babel/core": "7.13.14",
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/api-metrics": "^0.18.2",
"@opentelemetry/api-metrics": "0.18.2",
"@types/mocha": "8.2.2",
"@types/node": "14.14.37",
"@types/sinon": "9.0.11",
Expand All @@ -68,11 +68,11 @@
},
"dependencies": {
"@grpc/proto-loader": "^0.5.4",
"@opentelemetry/core": "^0.18.2",
"@opentelemetry/exporter-collector": "^0.18.2",
"@opentelemetry/metrics": "^0.18.2",
"@opentelemetry/resources": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2",
"@opentelemetry/core": "0.18.2",
"@opentelemetry/exporter-collector": "0.18.2",
"@opentelemetry/metrics": "0.18.2",
"@opentelemetry/resources": "0.18.2",
"@opentelemetry/tracing": "0.18.2",
"protobufjs": "^6.9.0"
}
}
10 changes: 5 additions & 5 deletions packages/opentelemetry-exporter-collector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@
"@opentelemetry/api": "^1.0.0-rc.0"
},
"dependencies": {
"@opentelemetry/api-metrics": "^0.18.2",
"@opentelemetry/core": "^0.18.2",
"@opentelemetry/metrics": "^0.18.2",
"@opentelemetry/resources": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2"
"@opentelemetry/api-metrics": "0.18.2",
"@opentelemetry/core": "0.18.2",
"@opentelemetry/metrics": "0.18.2",
"@opentelemetry/resources": "0.18.2",
"@opentelemetry/tracing": "0.18.2"
}
}
6 changes: 3 additions & 3 deletions packages/opentelemetry-exporter-jaeger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"devDependencies": {
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/resources": "^0.18.2",
"@opentelemetry/resources": "0.18.2",
"@types/mocha": "8.2.2",
"@types/node": "14.14.37",
"@types/sinon": "9.0.11",
Expand All @@ -60,8 +60,8 @@
"@opentelemetry/api": "^1.0.0-rc.0"
},
"dependencies": {
"@opentelemetry/core": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2",
"@opentelemetry/core": "0.18.2",
"@opentelemetry/tracing": "0.18.2",
"jaeger-client": "^3.15.0"
}
}
6 changes: 3 additions & 3 deletions packages/opentelemetry-exporter-prometheus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"@opentelemetry/api": "^1.0.0-rc.0"
},
"dependencies": {
"@opentelemetry/api-metrics": "^0.18.2",
"@opentelemetry/core": "^0.18.2",
"@opentelemetry/metrics": "^0.18.2"
"@opentelemetry/api-metrics": "0.18.2",
"@opentelemetry/core": "0.18.2",
"@opentelemetry/metrics": "0.18.2"
}
}
6 changes: 3 additions & 3 deletions packages/opentelemetry-exporter-zipkin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
"@opentelemetry/api": "^1.0.0-rc.0"
},
"dependencies": {
"@opentelemetry/core": "^0.18.2",
"@opentelemetry/resources": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2"
"@opentelemetry/core": "0.18.2",
"@opentelemetry/resources": "0.18.2",
"@opentelemetry/tracing": "0.18.2"
}
}
8 changes: 8 additions & 0 deletions packages/opentelemetry-instrumentation-fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ fetch('http://localhost:8090/fetch.js');

See [examples/tracer-web/fetch](/~https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/tracer-web) for a short example.

### Fetch Instrumentation options

Fetch instrumentation plugin has few options available to choose from. You can set the following:

| Options | Type | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------- | ------------------------------------- |
| [`applyCustomAttributesOnSpan`](/~https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-instrumentation-fetch/src/fetch.ts#L47) | `HttpCustomAttributeFunction` | Function for adding custom attributes |

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
14 changes: 7 additions & 7 deletions packages/opentelemetry-instrumentation-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"devDependencies": {
"@babel/core": "7.13.14",
"@opentelemetry/api": "^1.0.0-rc.0",
"@opentelemetry/context-zone": "^0.18.2",
"@opentelemetry/propagator-b3": "^0.18.2",
"@opentelemetry/tracing": "^0.18.2",
"@opentelemetry/context-zone": "0.18.2",
"@opentelemetry/propagator-b3": "0.18.2",
"@opentelemetry/tracing": "0.18.2",
"@types/mocha": "8.2.2",
"@types/node": "14.14.37",
"@types/shimmer": "1.0.1",
Expand Down Expand Up @@ -78,9 +78,9 @@
"@opentelemetry/api": "^1.0.0-rc.0"
},
"dependencies": {
"@opentelemetry/core": "^0.18.2",
"@opentelemetry/instrumentation": "^0.18.2",
"@opentelemetry/semantic-conventions": "^0.18.2",
"@opentelemetry/web": "^0.18.2"
"@opentelemetry/core": "0.18.2",
"@opentelemetry/instrumentation": "0.18.2",
"@opentelemetry/semantic-conventions": "0.18.2",
"@opentelemetry/web": "0.18.2"
}
}
35 changes: 35 additions & 0 deletions packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
isWrapped,
InstrumentationBase,
InstrumentationConfig,
safeExecuteInTheMiddle,
} from '@opentelemetry/instrumentation';
import * as core from '@opentelemetry/core';
import * as web from '@opentelemetry/web';
Expand All @@ -43,6 +44,14 @@ const getUrlNormalizingAnchor = () => {
return a;
};

export interface FetchCustomAttributeFunction {
(
span: api.Span,
request: Request | RequestInit,
result: Response | FetchError
): void;
}

/**
* FetchPlugin Config
*/
Expand All @@ -61,6 +70,8 @@ export interface FetchInstrumentationConfig extends InstrumentationConfig {
* also not be traced.
*/
ignoreUrls?: Array<string | RegExp>;
/** Function for adding custom attributes on the span */
applyCustomAttributesOnSpan?: FetchCustomAttributeFunction;
}

/**
Expand Down Expand Up @@ -311,6 +322,7 @@ export class FetchInstrumentation extends InstrumentationBase<
response: Response
) {
try {
plugin._applyAttributesAfterFetch(span, options, response);
if (response.status >= 200 && response.status < 400) {
plugin._endSpan(span, spanData, response);
} else {
Expand All @@ -331,6 +343,7 @@ export class FetchInstrumentation extends InstrumentationBase<
error: FetchError
) {
try {
plugin._applyAttributesAfterFetch(span, options, error);
plugin._endSpan(span, spanData, {
status: error.status || 0,
statusText: error.message,
Expand Down Expand Up @@ -360,6 +373,28 @@ export class FetchInstrumentation extends InstrumentationBase<
};
}

private _applyAttributesAfterFetch(
span: api.Span,
request: Request | RequestInit,
result: Response | FetchError
) {
const applyCustomAttributesOnSpan = this._getConfig()
.applyCustomAttributesOnSpan;
if (applyCustomAttributesOnSpan) {
safeExecuteInTheMiddle(
() => applyCustomAttributesOnSpan(span, request, result),
error => {
if (!error) {
return;
}

api.diag.error('applyCustomAttributesOnSpan', error);
},
true
);
}
}

/**
* Prepares a span data - needed later for matching appropriate network
* resources
Expand Down
Loading

0 comments on commit 6b57817

Please sign in to comment.