Skip to content

Commit 4919fd1

Browse files
authored
feat(exporter-metrics-otlp-proto): Support to protobuf in browser metrics (#5710)
1 parent a9fc600 commit 4919fd1

File tree

14 files changed

+482
-6
lines changed

14 files changed

+482
-6
lines changed

experimental/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
1010

1111
### :rocket: Features
1212

13+
* feat(exporter-metrics-otlp-proto): Support to protobuf in browser metrics. [#5710](https://github.com/open-telemetry/opentelemetry-js/pull/5710) @YangJonghun
14+
1315
### :bug: Bug Fixes
1416

1517
### :books: Documentation

experimental/packages/opentelemetry-exporter-metrics-otlp-proto/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
"mocha": true,
44
"commonjs": true,
55
"node": true,
6+
"browser": true
67
},
78
...require('../../../eslint.base.js')
89
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const karmaWebpackConfig = require('../../../karma.webpack');
18+
const karmaBaseConfig = require('../../../karma.base');
19+
20+
module.exports = config => {
21+
config.set(
22+
Object.assign({}, karmaBaseConfig, {
23+
webpack: karmaWebpackConfig,
24+
files: ['test/browser/index-webpack.ts'],
25+
preprocessors: { 'test/browser/index-webpack.ts': ['webpack'] },
26+
})
27+
);
28+
};

experimental/packages/opentelemetry-exporter-metrics-otlp-proto/package.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
"esnext": "build/esnext/index.js",
88
"types": "build/src/index.d.ts",
99
"repository": "open-telemetry/opentelemetry-js",
10+
"browser": {
11+
"./src/platform/index.ts": "./src/platform/browser/index.ts",
12+
"./build/esm/platform/index.js": "./build/esm/platform/browser/index.js",
13+
"./build/esnext/platform/index.js": "./build/esnext/platform/browser/index.js",
14+
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
15+
},
1016
"scripts": {
1117
"prepublishOnly": "npm run compile",
1218
"compile": "tsc --build tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
@@ -15,6 +21,7 @@
1521
"lint:fix": "eslint . --ext .ts --fix",
1622
"tdd": "npm run test -- --watch-extensions ts --watch",
1723
"test": "nyc mocha 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'",
24+
"test:browser": "karma start --single-run",
1825
"version": "node ../../../scripts/version-update.js",
1926
"watch": "tsc --build --watch tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
2027
"precompile": "cross-var lerna run version --scope $npm_package_name --include-dependencies",
@@ -55,17 +62,30 @@
5562
"access": "public"
5663
},
5764
"devDependencies": {
65+
"@babel/core": "7.27.1",
66+
"@babel/preset-env": "7.27.2",
5867
"@opentelemetry/api": "1.9.0",
5968
"@types/mocha": "10.0.10",
6069
"@types/node": "18.6.5",
6170
"@types/sinon": "17.0.4",
71+
"@types/webpack-env": "1.16.3",
72+
"babel-loader": "10.0.0",
73+
"babel-plugin-istanbul": "7.0.0",
6274
"cross-var": "1.1.0",
75+
"karma": "6.4.4",
76+
"karma-chrome-launcher": "3.1.0",
77+
"karma-coverage": "2.2.1",
78+
"karma-mocha": "2.0.1",
79+
"karma-spec-reporter": "0.0.36",
80+
"karma-webpack": "5.0.1",
6381
"lerna": "6.6.2",
6482
"mocha": "11.1.0",
6583
"nyc": "17.1.0",
6684
"sinon": "15.1.2",
6785
"ts-loader": "9.5.2",
68-
"typescript": "5.0.4"
86+
"typescript": "5.0.4",
87+
"webpack": "5.99.9",
88+
"webpack-cli": "6.0.1"
6989
},
7090
"peerDependencies": {
7191
"@opentelemetry/api": "^1.3.0"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
* limitations under the License.
1515
*/
1616

17-
export { OTLPMetricExporter } from './OTLPMetricExporter';
17+
export { OTLPMetricExporter } from './platform';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { OTLPMetricExporterOptions } from '@opentelemetry/exporter-metrics-otlp-http';
18+
import { OTLPMetricExporterBase } from '@opentelemetry/exporter-metrics-otlp-http';
19+
import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base';
20+
import { ProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer';
21+
import { createLegacyOtlpBrowserExportDelegate } from '@opentelemetry/otlp-exporter-base/browser-http';
22+
23+
export class OTLPMetricExporter extends OTLPMetricExporterBase {
24+
constructor(
25+
config: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions = {}
26+
) {
27+
super(
28+
createLegacyOtlpBrowserExportDelegate(
29+
config,
30+
ProtobufMetricsSerializer,
31+
'v1/metrics',
32+
{ 'Content-Type': 'application/x-protobuf' }
33+
),
34+
config
35+
);
36+
}
37+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export { OTLPMetricExporter } from './OTLPMetricExporter';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export { OTLPMetricExporter } from './node';

experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts renamed to experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/platform/node/OTLPMetricExporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { OTLPMetricExporterOptions } from '@opentelemetry/exporter-metrics-otlp-
1818
import { OTLPMetricExporterBase } from '@opentelemetry/exporter-metrics-otlp-http';
1919
import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base';
2020
import { ProtobufMetricsSerializer } from '@opentelemetry/otlp-transformer';
21-
import { VERSION } from './version';
21+
import { VERSION } from '../../version';
2222
import {
2323
convertLegacyHttpOptions,
2424
createOtlpHttpExportDelegate,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export { OTLPMetricExporter } from './OTLPMetricExporter';

0 commit comments

Comments
 (0)