Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(instrumentation-http)!: reduce public API surface by removing exports and making protected methods private #5124

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,41 @@ All notable changes to experimental packages in this project will be documented

### :boom: Breaking Change

* feat(instrumentation-http)!: reduce public API surface by removing exports and making protected methods private [#5124](https://github.com/open-telemetry/opentelemetry-js/pull/5124) @pichlermarc
* (user-facing) the following exports were intended for internal use only and have been removed without replacement
* extractHostnameAndPort
* getAbsoluteUrl
* getIncomingRequestAttributes
* getIncomingRequestAttributesOnResponse
* getIncomingRequestMetricAttributes
* getIncomingRequestMetricAttributesOnResponse
* getOutgoingRequestAttributes
* getOutgoingRequestAttributesOnResponse
* getOutgoingRequestMetricAttributes
* getOutgoingRequestMetricAttributesOnResponse
* getRequestInfo
* headerCapture
* isCompressed
* isValidOptionsType
* parseResponseStatus
* satisfiesPattern
* setAttributesFromHttpKind
* setRequestContentLengthAttribute
* setResponseContentLengthAttribute
* setSpanWithError
* RequestSignature
* RequestFunction
* ParsedRequestOptions
* IgnoreMatcher
* Https
* HttpRequestArgs
* HttpCallbackOptional
* HttpCallback
* Http
* GetFunction
* Func
* Err

### :rocket: (Enhancement)

### :bug: (Bug Fix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,7 @@ import type * as https from 'https';
import { Socket } from 'net';
import * as semver from 'semver';
import * as url from 'url';
import {
Err,
Func,
Http,
HttpInstrumentationConfig,
HttpRequestArgs,
Https,
SemconvStability,
} from './types';
import { HttpInstrumentationConfig } from './types';
import { VERSION } from './version';
import {
InstrumentationBase,
Expand Down Expand Up @@ -90,6 +82,14 @@ import {
parseResponseStatus,
setSpanWithError,
} from './utils';
import {
Err,
Func,
Http,
HttpRequestArgs,
Https,
SemconvStability,
} from './internal-types';

/**
* `node:http` and `node:https` instrumentation for OpenTelemetry
Expand Down Expand Up @@ -326,7 +326,7 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
/**
* Creates spans for incoming requests, restoring spans' context if applied.
*/
protected _getPatchIncomingRequestFunction(component: 'http' | 'https') {
private _getPatchIncomingRequestFunction(component: 'http' | 'https') {
return (
original: (event: string, ...args: unknown[]) => boolean
): ((this: unknown, event: string, ...args: unknown[]) => boolean) => {
Expand All @@ -338,13 +338,13 @@ export class HttpInstrumentation extends InstrumentationBase<HttpInstrumentation
* Creates spans for outgoing requests, sending spans' context for distributed
* tracing.
*/
protected _getPatchOutgoingRequestFunction(component: 'http' | 'https') {
private _getPatchOutgoingRequestFunction(component: 'http' | 'https') {
return (original: Func<http.ClientRequest>): Func<http.ClientRequest> => {
return this._outgoingRequestFunction(component, original);
};
}

protected _getPatchOutgoingGetFunction(
private _getPatchOutgoingGetFunction(
clientRequest: (
options: http.RequestOptions | string | url.URL,
...args: HttpRequestArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,12 @@

export { HttpInstrumentation } from './http';
export {
Err,
Func,
GetFunction,
Http,
HttpCallback,
HttpCallbackOptional,
HttpCustomAttributeFunction,
HttpInstrumentationConfig,
HttpRequestArgs,
HttpRequestCustomAttributeFunction,
HttpResponseCustomAttributeFunction,
Https,
IgnoreIncomingRequestFunction,
IgnoreMatcher,
IgnoreOutgoingRequestFunction,
ParsedRequestOptions,
RequestFunction,
RequestSignature,
StartIncomingSpanCustomAttributeFunction,
StartOutgoingSpanCustomAttributeFunction,
} from './types';
export {
extractHostnameAndPort,
getAbsoluteUrl,
getIncomingRequestAttributes,
getIncomingRequestAttributesOnResponse,
getIncomingRequestMetricAttributes,
getIncomingRequestMetricAttributesOnResponse,
getOutgoingRequestAttributes,
getOutgoingRequestAttributesOnResponse,
getOutgoingRequestMetricAttributes,
getOutgoingRequestMetricAttributesOnResponse,
getRequestInfo,
headerCapture,
isCompressed,
isValidOptionsType,
parseResponseStatus,
satisfiesPattern,
setAttributesFromHttpKind,
setRequestContentLengthAttribute,
setResponseContentLengthAttribute,
setSpanWithError,
} from './utils';
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type * as http from 'http';
import type * as https from 'https';
import { get, IncomingMessage, request } from 'http';
import * as url from 'url';

export type IgnoreMatcher = string | RegExp | ((url: string) => boolean);
export type HttpCallback = (res: IncomingMessage) => void;
export type RequestFunction = typeof request;
export type GetFunction = typeof get;

export type HttpCallbackOptional = HttpCallback | undefined;

// from node 10+
export type RequestSignature = [http.RequestOptions, HttpCallbackOptional] &
HttpCallback;

export type HttpRequestArgs = Array<HttpCallbackOptional | RequestSignature>;

export type ParsedRequestOptions =
| (http.RequestOptions & Partial<url.UrlWithParsedQuery>)
| http.RequestOptions;
export type Http = typeof http;
export type Https = typeof https;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Func<T> = (...args: any[]) => T;

export interface Err extends Error {
errno?: number;
code?: string;
path?: string;
syscall?: string;
stack?: string;
}

/**
* Tracks whether this instrumentation emits old experimental,
* new stable, or both semantic conventions.
*
* Enum values chosen such that the enum may be used as a bitmask.
*/
export const enum SemconvStability {
/** Emit only stable semantic conventions */
STABLE = 0x1,
/** Emit only old semantic convetions */
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
OLD = 0x2,
/** Emit both stable and old semantic convetions */
pichlermarc marked this conversation as resolved.
Show resolved Hide resolved
DUPLICATE = 0x1 | 0x2,
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,14 @@
* limitations under the License.
*/
import { Span, Attributes } from '@opentelemetry/api';
import type * as http from 'http';
import type * as https from 'https';
import {
ClientRequest,
get,
IncomingMessage,
request,
ServerResponse,
RequestOptions,
} from 'http';
import * as url from 'url';
import { InstrumentationConfig } from '@opentelemetry/instrumentation';

export type IgnoreMatcher = string | RegExp | ((url: string) => boolean);
export type HttpCallback = (res: IncomingMessage) => void;
export type RequestFunction = typeof request;
export type GetFunction = typeof get;

export type HttpCallbackOptional = HttpCallback | undefined;

// from node 10+
export type RequestSignature = [http.RequestOptions, HttpCallbackOptional] &
HttpCallback;

export type HttpRequestArgs = Array<HttpCallbackOptional | RequestSignature>;

export type ParsedRequestOptions =
| (http.RequestOptions & Partial<url.UrlWithParsedQuery>)
| http.RequestOptions;
export type Http = typeof http;
export type Https = typeof https;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Func<T> = (...args: any[]) => T;

export interface HttpCustomAttributeFunction {
(
span: Span,
Expand Down Expand Up @@ -114,26 +88,3 @@ export interface HttpInstrumentationConfig extends InstrumentationConfig {
server?: { requestHeaders?: string[]; responseHeaders?: string[] };
};
}

export interface Err extends Error {
errno?: number;
code?: string;
path?: string;
syscall?: string;
stack?: string;
}

/**
* Tracks whether this instrumentation emits old experimental,
* new stable, or both semantic conventions.
*
* Enum values chosen such that the enum may be used as a bitmask.
*/
export const enum SemconvStability {
/** Emit only stable semantic conventions */
STABLE = 0x1,
/** Emit only old semantic convetions */
OLD = 0x2,
/** Emit both stable and old semantic convetions */
DUPLICATE = 0x1 | 0x2,
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import {
IgnoreMatcher,
ParsedRequestOptions,
SemconvStability,
} from './types';
} from './internal-types';
import forwardedParse = require('forwarded-parse');

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import * as assert from 'assert';
import * as nock from 'nock';
import * as path from 'path';
import { HttpInstrumentation } from '../../src/http';
import { HttpInstrumentationConfig, SemconvStability } from '../../src/types';
import { HttpInstrumentationConfig } from '../../src/types';
import { assertSpan } from '../utils/assertSpan';
import { DummyPropagation } from '../utils/DummyPropagation';
import { httpRequest } from '../utils/httpRequest';
Expand All @@ -88,6 +88,7 @@ instrumentation.disable();
import * as http from 'http';
import { AttributeNames } from '../../src/enums/AttributeNames';
import { getRemoteClientAddress } from '../../src/utils';
import { SemconvStability } from '../../src/internal-types';

const applyCustomAttributesOnSpanErrorMessage =
'bad applyCustomAttributesOnSpan function';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ instrumentation.enable();
instrumentation.disable();

import * as http from 'http';
import { SemconvStability } from '../../src/types';
import { SemconvStability } from '../../src/internal-types';
import { getRPCMetadata, RPCType } from '@opentelemetry/core';
import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
IgnoreMatcher,
ParsedRequestOptions,
SemconvStability,
} from '../../src/types';
} from '../../src/internal-types';
import * as utils from '../../src/utils';
import { AttributeNames } from '../../src/enums/AttributeNames';
import { RPCType, setRPCMetadata } from '@opentelemetry/core';
Expand Down
Loading