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

refactor: remove "export *" in favor of explicit named exports #4880

Merged
merged 15 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 1 addition & 1 deletion api/src/platform/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './globalThis';
export { _globalThis } from './globalThis';
2 changes: 1 addition & 1 deletion api/src/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './node';
export { _globalThis } from './node';
2 changes: 1 addition & 1 deletion api/src/platform/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './globalThis';
export { _globalThis } from './globalThis';
1 change: 1 addition & 0 deletions eslint.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = {
}
}],
"@typescript-eslint/no-shadow": ["warn"],
"no-restricted-syntax": ["error", "ExportAllDeclaration"],
"prefer-rest-params": "off",
}
},
Expand Down
8 changes: 4 additions & 4 deletions experimental/packages/api-events/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

export * from './types/EventLogger';
export * from './types/EventLoggerProvider';
export * from './types/Event';
export * from './types/EventLoggerOptions';
export { EventLogger } from './types/EventLogger';
export { EventLoggerProvider } from './types/EventLoggerProvider';
export { Event } from './types/Event';
export { EventLoggerOptions } from './types/EventLoggerOptions';

import { EventsAPI } from './api/events';
export const events = EventsAPI.getInstance();
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './globalThis';
export { _globalThis } from './globalThis';
2 changes: 1 addition & 1 deletion experimental/packages/api-events/src/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './node';
export { _globalThis } from './node';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './globalThis';
export { _globalThis } from './globalThis';
19 changes: 12 additions & 7 deletions experimental/packages/api-logs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
* limitations under the License.
*/

export * from './types/Logger';
export * from './types/LoggerProvider';
export * from './types/LogRecord';
export * from './types/LoggerOptions';
export * from './types/AnyValue';
export * from './NoopLogger';
export * from './NoopLoggerProvider';
export { Logger } from './types/Logger';
export { LoggerProvider } from './types/LoggerProvider';
export {
LogAttributes,
LogBody,
LogRecord,
SeverityNumber,
} from './types/LogRecord';
export { LoggerOptions } from './types/LoggerOptions';
export { AnyValue, AnyValueMap } from './types/AnyValue';
export { NOOP_LOGGER, NoopLogger } from './NoopLogger';
export { NOOP_LOGGER_PROVIDER, NoopLoggerProvider } from './NoopLoggerProvider';

import { LogsAPI } from './api/logs';
export const logs = LogsAPI.getInstance();
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './globalThis';
export { _globalThis } from './globalThis';
2 changes: 1 addition & 1 deletion experimental/packages/api-logs/src/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './node';
export { _globalThis } from './node';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './globalThis';
export { _globalThis } from './globalThis';
3 changes: 3 additions & 0 deletions experimental/packages/exporter-logs-otlp-grpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './OTLPLogExporter';
3 changes: 3 additions & 0 deletions experimental/packages/exporter-trace-otlp-grpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './OTLPTraceExporter';
3 changes: 3 additions & 0 deletions experimental/packages/exporter-trace-otlp-http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './platform';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './OTLPTraceExporter';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './node';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './OTLPTraceExporter';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './BrowserDetector';
export { browserDetector } from './BrowserDetector';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './OTLPMetricExporter';
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './platform';
export * from './OTLPMetricExporterOptions';
export * from './OTLPMetricExporterBase';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './OTLPMetricExporter';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './node';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './OTLPMetricExporter';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './OTLPMetricExporter';
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

export * from './PrometheusExporter';
export * from './PrometheusSerializer';
export * from './export/types';
export { PrometheusExporter } from './PrometheusExporter';
export { PrometheusSerializer } from './PrometheusSerializer';
export { ExporterConfig } from './export/types';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
* limitations under the License.
*/

export * from './fetch';
export {
FetchCustomAttributeFunction,
FetchInstrumentation,
FetchInstrumentationConfig,
} from './fetch';
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,49 @@
* limitations under the License.
*/

export * from './http';
export * from './types';
export * from './utils';
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,
isIgnored,
isValidOptionsType,
parseResponseStatus,
satisfiesPattern,
setAttributesFromHttpKind,
setRequestContentLengthAttribute,
setResponseContentLengthAttribute,
setSpanWithError,
} from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
* limitations under the License.
*/

export * from './xhr';
export {
XHRCustomAttributeFunction,
XMLHttpRequestInstrumentation,
XMLHttpRequestInstrumentationConfig,
} from './xhr';
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ export { registerInstrumentations } from './autoLoader';
export { InstrumentationBase } from './platform/index';
export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition';
export { InstrumentationNodeModuleFile } from './instrumentationNodeModuleFile';
export * from './types';
export * from './types_internal';
export * from './utils';
export {
Instrumentation,
InstrumentationConfig,
InstrumentationModuleDefinition,
InstrumentationModuleFile,
ShimWrapped,
SpanCustomizationHook,
} from './types';
export { AutoLoaderOptions, AutoLoaderResult } from './types_internal';
export {
isWrapped,
safeExecuteInTheMiddle,
safeExecuteInTheMiddleAsync,
} from './utils';
7 changes: 5 additions & 2 deletions experimental/packages/opentelemetry-sdk-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * as api from '@opentelemetry/api';
export * as contextBase from '@opentelemetry/api';
export * as core from '@opentelemetry/core';
Expand All @@ -22,5 +25,5 @@ export * as metrics from '@opentelemetry/sdk-metrics';
export * as node from '@opentelemetry/sdk-trace-node';
export * as resources from '@opentelemetry/resources';
export * as tracing from '@opentelemetry/sdk-trace-base';
export * from './sdk';
export * from './types';
export { LoggerProviderConfig, MeterProviderConfig, NodeSDK } from './sdk';
export { NodeSDKConfiguration } from './types';
4 changes: 4 additions & 0 deletions experimental/packages/otlp-exporter-base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint no-restricted-syntax: ["warn", "ExportAllDeclaration"] --
* TODO: Replace export * with named exports before next major version
*/
export * from './platform';
export { OTLPExporterBase } from './OTLPExporterBase';
export {
Expand Down
1 change: 1 addition & 0 deletions integration-tests/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"devDependencies": {
"@opentelemetry/api": "^1.0.0",
"@opentelemetry/core": "^1.0.0",
"@types/mocha": "10.0.7",
"@types/node": "18.6.5",
"codecov": "3.8.3",
Expand Down
38 changes: 38 additions & 0 deletions integration-tests/api/test/core-entries.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/

const assert = require('assert');

// TypeScript v4.4.4 doesn't support `node16` or `nodenext` in
// [Module Resolution](https://www.typescriptlang.org/tsconfig#moduleResolution)
// which is required for typescript to resolve the `package.json#exports`
// entries.
// Additionally, using `node16` or `nodenext` in `tsconfig.json#moduleResolution`
// requires the TypeScript to generate ESModule outputs. This is a breaking
// change for CJS users.
// So we have to use plain JavaScript to verity the `package.json#exports` here.

describe('@opentelemetry/core entries', () => {
it('should import baggage utils under named const', async () => {
const mod = await import('@opentelemetry/core');
assert.ok(mod.baggageUtils.getKeyPairs != null);
});

it('should require baggage utils under named const', () => {
const mod = require('@opentelemetry/core');
assert.ok(mod.baggageUtils.getKeyPairs != null);
});
});
Loading
Loading