Skip to content

Commit

Permalink
Merge branch 'main' into replace_otlp_http_port
Browse files Browse the repository at this point in the history
  • Loading branch information
secustor authored Jan 19, 2022
2 parents 56bc313 + 8bda25c commit df83311
Show file tree
Hide file tree
Showing 136 changed files with 2,230 additions and 654 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ If you are a library author looking to build OpenTelemetry into your library, pl
### Node Support

Automated tests are run using the latest release of each currently active version of Node.JS.
While Node.JS v8 is no longer supported by the Node.JS team, the latest version of Node.JS v8 is still included in our testing suite.
While Node.JS v8 and v10 are no longer supported by the Node.JS team, the latest versions of Node.JS v8 and v10 are still included in our testing suite.
Please note that versions of Node.JS v8 prior to `v8.5.0` will NOT work, because OpenTelemetry Node depends on the `perf_hooks` module introduced in `v8.5.0`

### Browser Support
Expand Down Expand Up @@ -178,7 +178,6 @@ We have a weekly SIG meeting! See the [community page](https://github.com/open-t

Approvers ([@open-telemetry/js-approvers](https://github.com/orgs/open-telemetry/teams/javascript-approvers)):

- [Chengzhong Wu](https://github.com/legendecas), Alibaba
- [Gerhard Stöbich](https://github.com/Flarna), Dynatrace
- [John Bley](https://github.com/johnbley), Splunk
- [Mark Wolff](https://github.com/markwolff), Microsoft
Expand All @@ -192,7 +191,10 @@ Approvers ([@open-telemetry/js-approvers](https://github.com/orgs/open-telemetry

Maintainers ([@open-telemetry/js-maintainers](https://github.com/orgs/open-telemetry/teams/javascript-maintainers)):

- [Amir Blum](https://github.com/blumamir), Aspecto
- [Chengzhong Wu](https://github.com/legendecas), Alibaba
- [Daniel Dyla](https://github.com/dyladan), Dynatrace
- [Rauno Viskus](https://github.com/Rauno56), Splunk
- [Valentin Marchaud](https://github.com/vmarchaud), Open Source Contributor

*Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer).*
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = {
"project": "./tsconfig.json"
},
rules: {
"no-trailing-spaces": "error",
"eol-last": "error",
"quotes": [2, "single", { "avoidEscape": true }],
"@typescript-eslint/no-floating-promises": 2,
"@typescript-eslint/no-this-alias": "off",
Expand Down Expand Up @@ -40,6 +42,7 @@ module.exports = {
}
}],
"@typescript-eslint/no-shadow": ["warn"],
"@typescript-eslint/semi": "error",
"arrow-parens": ["error", "as-needed"],
"node/no-deprecated-api": ["warn"],
"header/header": [2, "block", [{
Expand Down
1 change: 0 additions & 1 deletion experimental/lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"lerna": "3.13.4",
"version": "0.27.0",
"npmClient": "npm",
"packages": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"lint:fix": "eslint . --ext .ts --fix",
"version": "node ../../../scripts/version-update.js",
"watch": "tsc --build --watch tsconfig.all.json",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "node ../../../scripts/version-update.js"
},
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@ import { Attributes } from './Metric';
* Interface that is being used in callback function for Observable Metric
*/
export interface ObservableResult {
/**
* Observe a measurement of the value associated with the given attributes.
*
* @param value The value to be observed.
* @param attributes The attributes associated with the value. If more than
* one values associated with the same attributes values, SDK may pick the
* last one or simply drop the entire observable result.
*/
observe(value: number, attributes?: Attributes): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"version": "node ../../../scripts/version-update.js",
"watch": "npm run protos:copy && tsc -w",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "npm run precompile"
},
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http';
import { toOTLPExportMetricServiceRequest } from '@opentelemetry/exporter-metrics-otlp-http'
import { toOTLPExportMetricServiceRequest } from '@opentelemetry/exporter-metrics-otlp-http';
import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base';
import {
OTLPExporterConfigNode,
Expand Down Expand Up @@ -45,7 +45,7 @@ export class OTLPMetricExporter
const headers = baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS);
this.metadata ||= new Metadata();
for (const [k, v] of Object.entries(headers)) {
this.metadata.set(k, v)
this.metadata.set(k, v);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"test:browser": "nyc karma start --single-run",
"version": "node ../../../scripts/version-update.js",
"watch": "tsc --build --watch tsconfig.all.json",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "npm run precompile"
},
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { MetricRecord, MetricExporter } from '@opentelemetry/sdk-metrics-base';
import {
import {
OTLPExporterNodeBase,
OTLPExporterNodeConfigBase,
otlpTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"version": "node ../../../scripts/version-update.js",
"watch": "npm run protos:copy && tsc -w",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "npm run precompile"
},
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint:fix": "eslint . --ext .ts --fix",
"version": "node ../../../scripts/version-update.js",
"watch": "tsc --build --watch",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "npm run precompile"
},
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"tdd": "karma start",
"test:browser": "nyc karma start --single-run",
"watch": "tsc --build --watch tsconfig.all.json",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "node ../../../scripts/version-update.js"
},
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"version": "node ../../../scripts/version-update.js",
"watch": "tsc --build --watch",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "node ../../../scripts/version-update.js"
},
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ Http instrumentation has few options available to choose from. You can set the f
| [`responseHook`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L95) | `HttpResponseCustomAttributeFunction` | Function for adding custom attributes before response is handled |
| [`startIncomingSpanHook`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L97) | `StartIncomingSpanCustomAttributeFunction` | Function for adding custom attributes before a span is started in incomingRequest |
| [`startOutgoingSpanHook`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L99) | `StartOutgoingSpanCustomAttributeFunction` | Function for adding custom attributes before a span is started in outgoingRequest |
| [`ignoreIncomingPaths`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L87) | `IgnoreMatcher[]` | Http instrumentation will not trace all incoming requests that match paths |
| [`ignoreOutgoingUrls`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L89) | `IgnoreMatcher[]` | Http instrumentation will not trace all outgoing requests that match urls |
| `ignoreIncomingRequestHook` | `IgnoreIncomingRequestFunction` | Http instrumentation will not trace all incoming requests that matched with custom function |
| `ignoreOutgoingRequestHook` | `IgnoreOutgoingRequestFunction` | Http instrumentation will not trace all outgoing requests that matched with custom function |
| [`serverName`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L101) | `string` | The primary server name of the matched virtual host. |
| [`requireParentforOutgoingSpans`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L103) | Boolean | Require that is a parent span to create new span for outgoing requests. |
| [`requireParentforIncomingSpans`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L105) | Boolean | Require that is a parent span to create new span for incoming requests. |
| [`headersToSpanAttributes`](https://github.com/open-telemetry/opentelemetry-js/blob/main/experimental/packages/opentelemetry-instrumentation-http/src/types.ts#L107) | `object` | List of case insensitive HTTP headers to convert to span attributes. Client (outgoing requests, incoming responses) and server (incoming requests, outgoing responses) headers will be converted to span attributes in the form of `http.{request\|response}.header.header_name`, e.g. `http.response.header.content_length` |

The following options are deprecated:

| Options | Type | Description |
| ------- | ---- | ----------- |
| `ignoreIncomingPaths` | `IgnoreMatcher[]` | Http instrumentation will not trace all incoming requests that match paths |
| `ignoreOutgoingUrls` | `IgnoreMatcher[]` | Http instrumentation will not trace all outgoing requests that match urls |

## Useful links

- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../",
"version": "node ../../../scripts/version-update.js",
"watch": "tsc --build --watch",
"precompile": "lerna run version --scope $(npm pkg get name) --include-filtered-dependencies",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "node ../../../scripts/version-update.js"
},
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,16 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
utils.isIgnored(
pathname,
instrumentation._getConfig().ignoreIncomingPaths,
(e: Error) => instrumentation._diag.error('caught ignoreIncomingPaths error: ', e)
(e: unknown) => instrumentation._diag.error('caught ignoreIncomingPaths error: ', e)
) ||
safeExecuteInTheMiddle(
() => instrumentation._getConfig().ignoreIncomingRequestHook?.(request),
(e: unknown) => {
if (e != null) {
instrumentation._diag.error('caught ignoreIncomingRequestHook error: ', e);
}
},
true
)
) {
return context.with(suppressTracing(context.active()), () => {
Expand Down Expand Up @@ -534,7 +543,16 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
utils.isIgnored(
origin + pathname,
instrumentation._getConfig().ignoreOutgoingUrls,
(e: Error) => instrumentation._diag.error('caught ignoreOutgoingUrls error: ', e)
(e: unknown) => instrumentation._diag.error('caught ignoreOutgoingUrls error: ', e)
) ||
safeExecuteInTheMiddle(
() => instrumentation._getConfig().ignoreOutgoingRequestHook?.(optionsParsed),
(e: unknown) => {
if (e != null) {
instrumentation._diag.error('caught ignoreOutgoingRequestHook error: ', e);
}
},
true
)
) {
return original.apply(this, [optionsParsed, ...args]);
Expand Down Expand Up @@ -685,6 +703,6 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
captureRequestHeaders: utils.headerCapture('request', config.headersToSpanAttributes?.server?.requestHeaders ?? []),
captureResponseHeaders: utils.headerCapture('response', config.headersToSpanAttributes?.server?.responseHeaders ?? []),
}
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
import {
Span,
SpanAttributes,
} from '@opentelemetry/api';
Expand Down Expand Up @@ -63,6 +63,14 @@ export interface HttpCustomAttributeFunction {
): void;
}

export interface IgnoreIncomingRequestFunction {
(request: IncomingMessage ): boolean;
}

export interface IgnoreOutgoingRequestFunction {
(request: RequestOptions ): boolean;
}

export interface HttpRequestCustomAttributeFunction {
(span: Span, request: ClientRequest | IncomingMessage): void;
}
Expand All @@ -83,10 +91,20 @@ export interface StartOutgoingSpanCustomAttributeFunction {
* Options available for the HTTP instrumentation (see [documentation](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-http#http-instrumentation-options))
*/
export interface HttpInstrumentationConfig extends InstrumentationConfig {
/** Not trace all incoming requests that match paths */
/**
* Not trace all incoming requests that match paths
* @deprecated use `ignoreIncomingRequestHook` instead
*/
ignoreIncomingPaths?: IgnoreMatcher[];
/** Not trace all outgoing requests that match urls */
/** Not trace all incoming requests that matched with custom function */
ignoreIncomingRequestHook?: IgnoreIncomingRequestFunction;
/**
* Not trace all outgoing requests that match urls
* @deprecated use `ignoreOutgoingRequestHook` instead
*/
ignoreOutgoingUrls?: IgnoreMatcher[];
/** Not trace all outgoing requests that matched with custom function */
ignoreOutgoingRequestHook?: IgnoreOutgoingRequestFunction;
/** Function for adding custom attributes after response is handled */
applyCustomAttributesOnSpan?: HttpCustomAttributeFunction;
/** Function for adding custom attributes before request is handled */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,6 @@ export const parseResponseStatus = (
return { code: SpanStatusCode.ERROR };
};

/**
* Returns whether the Expect header is on the given options object.
* @param options Options for http.request.
*/
export const hasExpectHeader = (options: RequestOptions): boolean => {
if (!options.headers) {
return false;
}

const keys = Object.keys(options.headers);
return !!keys.find(key => key.toLowerCase() === 'expect');
};

/**
* Check whether the given obj match pattern
* @param constant e.g URL of request
Expand Down Expand Up @@ -129,7 +116,7 @@ export const satisfiesPattern = (
export const isIgnored = (
constant: string,
list?: IgnoreMatcher[],
onException?: (error: Error) => void
onException?: (error: unknown) => void
): boolean => {
if (!list) {
// No ignored urls - trace everything
Expand Down Expand Up @@ -304,18 +291,18 @@ export const getRequestInfo = (
}`;
}

if (hasExpectHeader(optionsParsed)) {
optionsParsed.headers = Object.assign({}, optionsParsed.headers);
} else if (!optionsParsed.headers) {
optionsParsed.headers = {};
}
const headers = optionsParsed.headers ?? {};
optionsParsed.headers = Object.keys(headers).reduce((normalizedHeader, key) => {
normalizedHeader[key.toLowerCase()] = headers[key];
return normalizedHeader;
}, {} as OutgoingHttpHeaders);
// some packages return method in lowercase..
// ensure upperCase for consistency
const method = optionsParsed.method
? optionsParsed.method.toUpperCase()
: 'GET';

return { origin, pathname, method, optionsParsed };
return { origin, pathname, method, optionsParsed, };
};

/**
Expand Down Expand Up @@ -501,7 +488,7 @@ export function headerCapture(type: 'request' | 'response', headers: string[]) {
return (span: Span, getHeader: (key: string) => undefined | string | string[] | number) => {
for (const [capturedHeader, normalizedHeader] of normalizedHeaders) {
const value = getHeader(capturedHeader);

if (value === undefined) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('HttpInstrumentation', () => {
describe('disable()', () => {
let provider: TracerProvider;
let startSpanStub: sinon.SinonStub;

before(() => {
provider = {
getTracer: () => {
Expand Down
Loading

0 comments on commit df83311

Please sign in to comment.