Skip to content

Commit 5736c49

Browse files
dyladanpichlermarc
andauthored
feat: update proto to 1.7.0 (open-telemetry#5643)
Co-authored-by: Marc Pichler <marcpi@edu.aau.at>
1 parent c193502 commit 5736c49

File tree

23 files changed

+439
-56
lines changed

23 files changed

+439
-56
lines changed

.github/workflows/e2e.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
e2e-tests:
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
node_version:
14+
- "18.19.0"
15+
- "18"
16+
- "20.6.0"
17+
- "20"
18+
- "22"
19+
- "23"
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- uses: actions/setup-node@v4
25+
with:
26+
cache: 'npm'
27+
cache-dependency-path: |
28+
package-lock.json
29+
node-version: ${{ matrix.node_version }}
30+
31+
# npm@11.0.0 drops support for Node.js v18
32+
# Install the latest npm compatible with this version of Node.js
33+
# - npm@11.1.0 supports: {"node":"^20.17.0 || >=22.9.0"}
34+
- run: npm install -g npm@"<11.0.0"
35+
if: ${{
36+
matrix.node_version == '18.19.0' ||
37+
matrix.node_version == '18' ||
38+
matrix.node_version == '20.6.0'
39+
}}
40+
- run: npm install -g npm@latest
41+
if: ${{
42+
matrix.node_version == '20' ||
43+
matrix.node_version == '22' ||
44+
matrix.node_version == '23'
45+
}}
46+
47+
- name: Bootstrap
48+
run: npm ci
49+
50+
- name: Build 🔧
51+
run: npm run compile
52+
53+
- name: Install collector
54+
run: |
55+
curl -sSL -o otelcol-contrib.tar.gz https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.126.0/otelcol-contrib_0.126.0_linux_amd64.tar.gz
56+
tar -xzf otelcol-contrib.tar.gz
57+
working-directory: e2e-tests
58+
- name: run collector in background
59+
run: |
60+
./otelcol-contrib --config collector-config.yaml &
61+
working-directory: e2e-tests
62+
- name: Export telemetry to collector
63+
run: npm run export-telemetry
64+
working-directory: e2e-tests
65+
- name: stop collector
66+
run: pkill -f otelcol-contrib
67+
working-directory: e2e-tests
68+
- name: Print output
69+
run: cat collector-output.json
70+
working-directory: e2e-tests
71+
- name: verify exported telemetry
72+
run: npm run verify
73+
working-directory: e2e-tests

e2e-tests/.eslintrc.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
module.exports = {
18+
env: {
19+
node: true,
20+
},
21+
...require('../eslint.base.js'),
22+
rules: {
23+
'no-console': 'off',
24+
},
25+
};

e2e-tests/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# collector output file
2+
collector-output.json

e2e-tests/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# OpenTelemetry JS End-to-End Tests
2+
3+
This directory contains end-to-end (E2E) tests for the OpenTelemetry JavaScript project. These tests verify the integration of OpenTelemetry components with a real OpenTelemetry Collector.
4+
5+
## Prerequisites
6+
7+
- [Node.js](https://nodejs.org/) (version as required by the root project)
8+
- [Docker](https://www.docker.com/) (for running the OpenTelemetry Collector)
9+
10+
## Installation
11+
12+
Install dependencies:
13+
14+
```sh
15+
npm install
16+
```
17+
18+
## Running Tests
19+
20+
Test can be run completely or each step can be run separately.
21+
22+
### `npm run test:e2e`
23+
24+
Runs the full E2E test workflow in sequence: prepares the output file, starts the Collector, runs the tests, stops the Collector, and verifies the results.
25+
26+
### `npm run run-collector`
27+
28+
Starts the OpenTelemetry Collector in a Docker container and mounts the output file for results. Waits 5 seconds for the Collector to be ready.
29+
30+
### `npm run stop-collector`
31+
32+
Stops the Docker container running the Collector if it’s running.
33+
34+
### `npm run verify`
35+
36+
Runs the verification script (`verify.mjs`) to check the contents of `collector-output.json` for expected results.

e2e-tests/collector-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
http:
5+
endpoint: 0.0.0.0:4318
6+
7+
exporters:
8+
file:
9+
path: ./collector-output.json
10+
11+
service:
12+
pipelines:
13+
traces:
14+
receivers: [otlp]
15+
exporters: [file]
16+
metrics:
17+
receivers: [otlp]
18+
exporters: [file]
19+
logs:
20+
receivers: [otlp]
21+
exporters: [file]

e2e-tests/package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@opentelemetry/e2e-test",
3+
"private": true,
4+
"description": "End-to-end tests for OpenTelemetry JS",
5+
"version": "0.0.0",
6+
"scripts": {
7+
"test:e2e": "npm run run-collector && npm run export-telemetry && npm run verify && npm run stop-collector",
8+
"lint": "eslint . --ext .mjs",
9+
"lint:fix": "eslint . --ext .mjs --fix",
10+
"run-collector": "docker run -d --rm --name otelcol-e2e -v $(pwd)/collector-config.yaml:/etc/otelcol/config.yaml -v $(pwd)/collector-output.json:/tmp/collector-output.json -p 4317:4317 -p 4318:4318 -w /tmp otel/opentelemetry-collector-contrib:latest --config /etc/otelcol/config.yaml && sleep 5",
11+
"export-telemetry": "node test.mjs",
12+
"prerun-collector": "node -e \"require('fs').writeFileSync('collector-output.json', '')\"",
13+
"stop-collector": "docker stop otelcol-e2e",
14+
"verify": "node verify.mjs"
15+
},
16+
"dependencies": {
17+
"@opentelemetry/api": "^1.3.0",
18+
"@opentelemetry/api-logs": "~0.201.1",
19+
"@opentelemetry/sdk-node": "0.201.1",
20+
"@opentelemetry/exporter-trace-otlp-proto": "0.201.1",
21+
"@opentelemetry/exporter-metrics-otlp-proto": "0.201.1",
22+
"@opentelemetry/exporter-logs-otlp-proto": "0.201.1",
23+
"@opentelemetry/sdk-metrics": "2.0.1",
24+
"@opentelemetry/sdk-logs": "0.201.1",
25+
"@opentelemetry/sdk-trace-base": "2.0.1"
26+
}
27+
}

e2e-tests/test.mjs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
import { NodeSDK } from '@opentelemetry/sdk-node';
17+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
18+
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto';
19+
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
20+
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-proto';
21+
import { SimpleLogRecordProcessor } from '@opentelemetry/sdk-logs';
22+
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
23+
import {
24+
diag,
25+
DiagConsoleLogger,
26+
DiagLogLevel,
27+
trace,
28+
metrics,
29+
} from '@opentelemetry/api';
30+
import { logs } from '@opentelemetry/api-logs';
31+
32+
// Enable diagnostic logging (optional)
33+
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
34+
35+
const collectorUrl = 'http://localhost:4318/v1';
36+
37+
// Set up trace exporter with SimpleSpanProcessor
38+
const traceExporter = new OTLPTraceExporter({
39+
url: `${collectorUrl}/traces`,
40+
});
41+
const spanProcessors = [new SimpleSpanProcessor(traceExporter)];
42+
43+
// Set up metric exporter
44+
const metricExporter = new OTLPMetricExporter({
45+
url: `${collectorUrl}/metrics`,
46+
});
47+
const metricReader = new PeriodicExportingMetricReader({
48+
exporter: metricExporter,
49+
exportIntervalMillis: 1000,
50+
exportTimeoutMillis: 1000,
51+
});
52+
53+
// Set up log exporter
54+
const logExporter = new OTLPLogExporter({
55+
url: `${collectorUrl}/logs`,
56+
});
57+
const logRecordProcessors = [new SimpleLogRecordProcessor(logExporter)];
58+
59+
// Set up OpenTelemetry SDK
60+
const sdk = new NodeSDK({
61+
spanProcessors,
62+
metricReader,
63+
logRecordProcessors,
64+
});
65+
66+
async function main() {
67+
sdk.start();
68+
69+
// Create a span
70+
const tracer = trace.getTracer('example-tracer');
71+
const span = tracer.startSpan('example-span');
72+
span.setAttribute('example-attribute', 'value');
73+
span.end();
74+
75+
// Create a metric
76+
const meter = metrics.getMeter('example-meter');
77+
const counter = meter.createUpDownCounter('example_counter');
78+
counter.add(42, { foo: 'bar' });
79+
80+
// Create a log
81+
const logger = logs.getLogger('example-logger');
82+
logger.emit({
83+
severityText: 'INFO',
84+
body: 'test-log-body',
85+
attributes: { foo: 'bar' },
86+
});
87+
88+
// flushes exporters and shuts down the SDK
89+
await sdk.shutdown();
90+
}
91+
92+
main().catch(err => {
93+
console.error('Error running example:', err);
94+
process.exit(1);
95+
});

e2e-tests/verify.mjs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
'use strict';
17+
18+
import fs from 'fs';
19+
20+
const data = fs.readFileSync('collector-output.json', 'utf8');
21+
22+
let verifiedSpan = false;
23+
let verifiedMetric = false;
24+
let verifiedLog = false;
25+
26+
const lines = data.split('\n').filter(Boolean);
27+
for (const line of lines) {
28+
const parsed = JSON.parse(line);
29+
if (parsed.resourceSpans) {
30+
console.log('found span');
31+
verifySpan(parsed.resourceSpans[0].scopeSpans[0].spans[0]);
32+
verifiedSpan = true;
33+
}
34+
if (parsed.resourceMetrics) {
35+
console.log('found metric');
36+
verifyMetric(parsed.resourceMetrics[0].scopeMetrics[0].metrics[0]);
37+
verifiedMetric = true;
38+
}
39+
if (parsed.resourceLogs) {
40+
console.log('found log');
41+
verifyLog(parsed.resourceLogs[0].scopeLogs[0].logRecords[0]);
42+
verifiedLog = true;
43+
}
44+
}
45+
46+
if (!verifiedSpan) {
47+
console.error('No spans found in the output');
48+
process.exit(1);
49+
}
50+
if (!verifiedMetric) {
51+
console.error('No metrics found in the output');
52+
process.exit(1);
53+
}
54+
if (!verifiedLog) {
55+
console.error('No logs found in the output');
56+
process.exit(1);
57+
}
58+
59+
function verifySpan(span) {
60+
const expectedName = 'example-span';
61+
if (span.name !== expectedName) {
62+
console.error(`Expected span name ${expectedName}, but got '${span.name}'`);
63+
process.exit(1);
64+
}
65+
}
66+
67+
function verifyMetric(metric) {
68+
const expectedName = 'example_counter';
69+
const expectedValue = 42;
70+
71+
if (metric.name !== expectedName) {
72+
console.error(
73+
`Expected metric name ${expectedName}, but got '${metric.name}'`
74+
);
75+
process.exit(1);
76+
}
77+
if (
78+
metric.sum &&
79+
metric.sum.dataPoints &&
80+
metric.sum.dataPoints[0].asDouble !== expectedValue
81+
) {
82+
console.error(
83+
`Expected metric value ${expectedValue}, but got '${metric.sum.dataPoints[0].asDouble}'`
84+
);
85+
process.exit(1);
86+
}
87+
}
88+
89+
function verifyLog(log) {
90+
const expectedBody = 'test-log-body';
91+
if (log.body && log.body.stringValue !== expectedBody) {
92+
console.error(
93+
`Expected log body '${expectedBody}', but got '${log.body.stringValue}'`
94+
);
95+
process.exit(1);
96+
}
97+
}

experimental/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ 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-otlp-\*): update proto to `v1.7.0`
1314
* feat(exporter-metrics-otlp-proto): Support to protobuf in browser metrics. [#5710](https://github.com/open-telemetry/opentelemetry-js/pull/5710) @YangJonghun
1415

1516
### :bug: Bug Fixes

0 commit comments

Comments
 (0)