Skip to content

Commit 24ac55e

Browse files
committed
fix: don't export classes
1 parent 74d6c96 commit 24ac55e

File tree

21 files changed

+271
-472
lines changed

21 files changed

+271
-472
lines changed

examples/opentelemetry-web/examples/metrics-proto/index.html

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55
<meta charset="utf-8">
66
<title>Metrics Example</title>
77
<base href="/">
8-
9-
<!--
10-
https://www.w3.org/TR/trace-context/
11-
Set the `traceparent` in the server's HTML template code. It should be
12-
dynamically generated server side to have the server's request trace Id,
13-
a parent span Id that was set on the server's request span, and the trace
14-
flags to indicate the server's sampling decision
15-
(01 = sampled, 00 = notsampled).
16-
'{version}-{traceId}-{spanId}-{sampleDecision}'
17-
-->
18-
<!-- <meta name="traceparent" content="00-ab42124a3c573678d4d8b21ba52df3bf-d21f7bc17caa5aba-01">-->
19-
208
<meta name="viewport" content="width=device-width, initial-scale=1">
219
</head>
2210

@@ -28,7 +16,7 @@
2816
<button id="stopBtn">Stop metrics</button>
2917
<br/>
3018

31-
If you run the collector from example "opentelemetry-exporter-otlp-proto" you should see traces at: <br/>
19+
If you run the collector from this example, you should see metrics at: <br/>
3220
<a href="http://localhost:9090/graph?g0.range_input=1m&g0.expr=requests&g0.tab=0/" target="_blank">http://localhost:9090/</a>
3321

3422
</body>

examples/opentelemetry-web/examples/metrics-proto/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ function startMetrics() {
2121
const meterProvider = new MeterProvider();
2222

2323
meterProvider.addMetricReader(new PeriodicExportingMetricReader({
24-
exporter: createMetricsExporter({
25-
headers: {'x-my-test': 'header'},
26-
}),
24+
exporter: createMetricsExporter({}),
2725
exportIntervalMillis: 1000
2826
}));
2927

experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@
1717
// Legacy exporter kept for compatibility, scheduled for removal in 2.0
1818
export { OTLPMetricExporter } from './legacy/OTLPMetricExporter';
1919

20-
// New exporter factory function
21-
export { createMetricsExporter } from './platform';
20+
export {
21+
// New exporter factory function and config.
22+
createMetricsExporter,
23+
OtlpHttpProtoMetricsConfiguration,
24+
// Scheduled for removal in 2.0
25+
LegacyConfig,
26+
} from './platform';

experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/legacy/OTLPMetricExporter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import {
2121
AggregationTemporalitySelector,
2222
InstrumentType,
2323
} from '@opentelemetry/sdk-metrics';
24+
import { AggregationTemporalityPreference } from '@opentelemetry/exporter-metrics-otlp-http';
2425
import {
25-
AggregationTemporalityPreference,
2626
DeltaTemporalitySelector,
2727
CumulativeTemporalitySelector,
2828
LowMemoryTemporalitySelector,
29-
} from '@opentelemetry/exporter-metrics-otlp-http';
30-
29+
} from '@opentelemetry/otlp-metrics-exporter-base';
3130
import { ExportResult } from '@opentelemetry/core';
31+
3232
import { LegacyConfig, createMetricsExporter } from '../platform';
3333

3434
/**

experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/platform/browser/exporter-factory.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import { OtlpHttpProtoMetricsConfiguration } from './configuration';
1919
import {
2020
createMetricsPartialSuccessHandler,
2121
createOtlpMetricsExporter,
22-
DefaultingMetricsConfigurationProvider,
22+
mergeMetricsConfigurationWithDefaults,
2323
} from '@opentelemetry/otlp-metrics-exporter-base';
2424
import {
2525
DEFAULT_COMPRESSION,
2626
DEFAULT_CONCURRENCY_LIMIT,
2727
DEFAULT_TIMEOUT,
28-
DefaultingOtlpHttpConfigurationProvider,
28+
mergeOtlpHttpConfigurationWithDefaults,
2929
OtlpHttpConfiguration,
3030
} from '@opentelemetry/otlp-http-exporter-base';
3131
import {
@@ -56,16 +56,16 @@ const DEFAULTS: OtlpHttpConfiguration = {
5656
export function createMetricsExporter(
5757
options: Partial<OtlpHttpProtoMetricsConfiguration>
5858
): PushMetricExporter {
59-
const metricsConfiguration = new DefaultingMetricsConfigurationProvider(
59+
const metricsConfiguration = mergeMetricsConfigurationWithDefaults(
6060
options,
6161
{}
62-
).provide();
62+
);
6363

64-
const httpConfiguration = new DefaultingOtlpHttpConfigurationProvider(
64+
const httpConfiguration = mergeOtlpHttpConfigurationWithDefaults(
6565
options,
6666
{},
6767
DEFAULTS
68-
).provide();
68+
);
6969

7070
const useXHR =
7171
!!options.headers || typeof navigator.sendBeacon !== 'function';

experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/platform/node/exporter-factory.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,31 @@
1515
*/
1616

1717
import { PushMetricExporter } from '@opentelemetry/sdk-metrics';
18-
import { createExportPromiseQueue } from '@opentelemetry/otlp-exporter-base';
19-
import { createRetryingTransport } from '@opentelemetry/otlp-exporter-base';
20-
import { createOtlpExportDelegate } from '@opentelemetry/otlp-exporter-base';
21-
import { createOtlpMetricsExporter } from '@opentelemetry/otlp-metrics-exporter-base';
18+
import {
19+
createExportPromiseQueue,
20+
createRetryingTransport,
21+
createOtlpExportDelegate,
22+
} from '@opentelemetry/otlp-exporter-base';
23+
import {
24+
createOtlpMetricsExporter,
25+
createMetricsPartialSuccessHandler,
26+
getMetricsConfigurationFromEnvironment,
27+
mergeMetricsConfigurationWithDefaults,
28+
} from '@opentelemetry/otlp-metrics-exporter-base';
2229

2330
import {
2431
DEFAULT_COMPRESSION,
2532
DEFAULT_CONCURRENCY_LIMIT,
2633
DEFAULT_TIMEOUT,
27-
DefaultingOtlpHttpConfigurationProvider,
34+
mergeOtlpHttpConfigurationWithDefaults,
2835
OtlpHttpConfiguration,
2936
} from '@opentelemetry/otlp-http-exporter-base';
3037

31-
import { DefaultingMetricsConfigurationProvider } from '@opentelemetry/otlp-metrics-exporter-base';
32-
import { createMetricsPartialSuccessHandler } from '@opentelemetry/otlp-metrics-exporter-base';
33-
import { EnvironmentOtlpMetricsConfigurationProvider } from '@opentelemetry/otlp-metrics-exporter-base';
34-
35-
import { createHttpExporterTransport } from '@opentelemetry/otlp-http-exporter-node-base';
36-
import { DefaultingNodeHttpConfigurationProvider } from '@opentelemetry/otlp-http-exporter-node-base';
37-
import { EnvironmentOtlpHttpConfigurationProvider } from '@opentelemetry/otlp-http-exporter-node-base';
38+
import {
39+
createHttpExporterTransport,
40+
getHttpConfigurationFromEnvironment,
41+
mergeNodeHttpConfigurationWithDefaults,
42+
} from '@opentelemetry/otlp-http-exporter-node-base';
3843

3944
import { OtlpHttpProtoMetricsConfiguration } from './configuration';
4045
import { createProtobufMetricsSerializer } from '../../internal/metrics-serializer';
@@ -53,32 +58,32 @@ const DEFAULTS: OtlpHttpConfiguration = {
5358
timeoutMillis: DEFAULT_TIMEOUT,
5459
};
5560

61+
/**
62+
* Creates an OTLP (http/protobuf) Metrics Exporter using the provided configuration, and configuration via the environment.
63+
* Falls back to defaults if neither are configured.
64+
*
65+
* @param options
66+
*/
5667
export function createMetricsExporter(
5768
options: Partial<OtlpHttpProtoMetricsConfiguration>
5869
): PushMetricExporter {
59-
const httpEnvironmentConfiguration =
60-
new EnvironmentOtlpHttpConfigurationProvider(
61-
'METRICS',
62-
'v1/metrics'
63-
).provide();
64-
65-
const metricsEnvironmentConfiguration =
66-
new EnvironmentOtlpMetricsConfigurationProvider().provide();
70+
const httpEnvironmentConfiguration = getHttpConfigurationFromEnvironment(
71+
'METRICS',
72+
'v1/metrics'
73+
);
6774

68-
const metricsConfiguration = new DefaultingMetricsConfigurationProvider(
75+
const metricsConfiguration = mergeMetricsConfigurationWithDefaults(
6976
options,
70-
metricsEnvironmentConfiguration
71-
).provide();
77+
getMetricsConfigurationFromEnvironment()
78+
);
7279

73-
const httpConfiguration = new DefaultingOtlpHttpConfigurationProvider(
80+
const httpConfiguration = mergeOtlpHttpConfigurationWithDefaults(
7481
options,
7582
httpEnvironmentConfiguration,
7683
DEFAULTS
77-
).provide();
84+
);
7885

79-
const nodeHttpConfiguration = new DefaultingNodeHttpConfigurationProvider(
80-
options
81-
).provide();
86+
const nodeHttpConfiguration = mergeNodeHttpConfigurationWithDefaults(options);
8287

8388
const transport = createHttpExporterTransport({
8489
url: httpConfiguration.url,

experimental/packages/otlp-http-exporter-base/src/configuration/defaulting-provider.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const DEFAULT_CONCURRENCY_LIMIT = 30;
2929
// Specification defines OTLP/HTTP default URL to be http://localhost:4318
3030
export const DEFAULT_COMPRESSION = 'none';
3131

32-
export class DefaultingOtlpHttpConfigurationProvider
32+
class DefaultingOtlpHttpConfigurationProvider
3333
implements IConfigurationProvider<OtlpHttpConfiguration>
3434
{
3535
/**
@@ -115,3 +115,15 @@ export class DefaultingOtlpHttpConfigurationProvider
115115
};
116116
}
117117
}
118+
119+
export function mergeOtlpHttpConfigurationWithDefaults(
120+
userProvidedConfiguration: Partial<OtlpHttpConfiguration>,
121+
fallbackConfiguration: Partial<OtlpHttpConfiguration>,
122+
defaultConfiguration: OtlpHttpConfiguration
123+
): OtlpHttpConfiguration {
124+
return new DefaultingOtlpHttpConfigurationProvider(
125+
userProvidedConfiguration,
126+
fallbackConfiguration,
127+
defaultConfiguration
128+
).provide();
129+
}

experimental/packages/otlp-http-exporter-base/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
export { OtlpHttpConfiguration } from './configuration/configuration';
1818
export {
19-
DefaultingOtlpHttpConfigurationProvider,
19+
mergeOtlpHttpConfigurationWithDefaults,
2020
DEFAULT_COMPRESSION,
2121
DEFAULT_TIMEOUT,
2222
DEFAULT_CONCURRENCY_LIMIT,

0 commit comments

Comments
 (0)