Skip to content

Commit 46f1c10

Browse files
authored
Merge branch 'main' into note-fetch-instrumentation
2 parents bc180bb + f5ef8de commit 46f1c10

File tree

19 files changed

+222
-57
lines changed

19 files changed

+222
-57
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
1616
### :house: (Internal)
1717

1818
### :bug: (Bug Fix)
19+
* chore: type reference on zone.js [#4257](https://github.com/open-telemetry/opentelemetry-js/pull/4257) @legendecas
20+
* chore: no need for 'packages' in lerna.json [#4264](https://github.com/open-telemetry/opentelemetry-js/pull/4264) @trentm
1921
* fix(sdk-trace): Allow fetch instrumentation to be used with native NodeJS fetch [#4063](https://github.com/open-telemetry/opentelemetry-js/pull/4063)
2022

2123
## 1.18.1

experimental/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ All notable changes to experimental packages in this project will be documented
1010

1111
### :bug: (Bug Fix)
1212

13+
* fix(sdk-logs): avoid map attribute set when count limit exceeded
14+
1315
### :books: (Refine Doc)
1416

1517
### :house: (Internal)

experimental/examples/prometheus/README.md

+16-6
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@ This is a simple example that demonstrates basic metrics collection and exports
1111
npm install
1212
```
1313

14-
Setup [Prometheus](https://prometheus.io/docs/prometheus/latest/getting_started/)
15-
1614
## Run the Application
1715

18-
- Run the server
19-
2016
```sh
2117
# from this directory
2218
npm run start
2319
```
2420

21+
If you are using the default configurations, the metrics should be available at <http://localhost:9464/metrics>
22+
23+
## Run Prometheus
24+
25+
### With docker
26+
27+
```sh
28+
# from this directory
29+
docker compose up
30+
```
31+
32+
### With binary
33+
34+
Setup [Prometheus](https://prometheus.io/docs/prometheus/latest/getting_started/)
35+
2536
- Replace the `prometheus.yml` provided by the Prometheus installation with the following:
2637

2738
```yaml
@@ -34,7 +45,6 @@ scrape_configs:
3445
# scheme defaults to 'http'.
3546
static_configs:
3647
- targets: ['localhost:9464']
37-
3848
```
3949
4050
- Start Prometheus
@@ -44,7 +54,7 @@ scrape_configs:
4454
prometheus --config.file=prometheus.yml
4555
```
4656

47-
### Prometheus UI
57+
## Prometheus UI
4858

4959
If you are using the default configurations, the prometheus client will be available at <http://localhost:9090>
5060

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3.7'
2+
3+
services:
4+
prometheus:
5+
image: prom/prometheus:v2.47.2
6+
extra_hosts:
7+
- host.docker.internal:host-gateway
8+
volumes:
9+
- "./prometheus.docker.yml:/etc/prometheus/prometheus.yml"
10+
ports:
11+
- 9090:9090
12+
restart: always
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
global:
2+
scrape_interval: 15s # Default is every 1 minute.
3+
4+
scrape_configs:
5+
- job_name: 'opentelemetry'
6+
# metrics_path defaults to '/metrics'
7+
# scheme defaults to 'http'.
8+
static_configs:
9+
- targets: ['host.docker.internal:9464']

experimental/packages/otlp-transformer/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"tdd": "npm run test -- --watch-extensions ts --watch",
2222
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
2323
"test:browser": "karma start --single-run",
24+
"test:bench": "node test/performance/benchmark/index.js | tee .benchmark-results.txt",
2425
"prewatch": "node ../../../scripts/version-update.js",
2526
"watch": "tsc --build -w tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
2627
"peer-api-check": "node ../../../scripts/peer-api-check.js",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 Benchmark = require('benchmark');
18+
const { createExportTraceServiceRequest } = require('../../../build/src');
19+
const { BasicTracerProvider } = require('@opentelemetry/sdk-trace-base');
20+
21+
const tracerProvider = new BasicTracerProvider();
22+
const tracer = tracerProvider.getTracer('test')
23+
24+
const suite = new Benchmark.Suite();
25+
26+
const span = createSpan();
27+
const spans = [];
28+
for (let i = 0; i < 100; i++) {
29+
spans.push(createSpan());
30+
}
31+
32+
suite.on('cycle', event => {
33+
console.log(String(event.target));
34+
});
35+
36+
suite.add('transform 1 span', function() {
37+
createExportTraceServiceRequest([span]);
38+
});
39+
40+
suite.add('transform 100 spans', function() {
41+
createExportTraceServiceRequest(spans);
42+
});
43+
44+
suite.run();
45+
46+
function createSpan() {
47+
const span = tracer.startSpan('span');
48+
span.setAttribute('aaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaa');
49+
span.setAttribute('bbbbbbbbbbbbbbbbbbbb', 'bbbbbbbbbbbbbbbbbbbb');
50+
span.setAttribute('cccccccccccccccccccc', 'cccccccccccccccccccc');
51+
span.setAttribute('dddddddddddddddddddd', 'dddddddddddddddddddd');
52+
span.setAttribute('eeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeee');
53+
span.setAttribute('ffffffffffffffffffff', 'ffffffffffffffffffff');
54+
span.setAttribute('gggggggggggggggggggg', 'gggggggggggggggggggg');
55+
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'hhhhhhhhhhhhhhhhhhhh');
56+
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'iiiiiiiiiiiiiiiiiiii');
57+
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'jjjjjjjjjjjjjjjjjjjj');
58+
span.end();
59+
60+
return span;
61+
}

experimental/packages/sdk-logs/src/LogRecord.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,18 @@ export class LogRecord implements ReadableLogRecord {
114114
if (value === null) {
115115
return this;
116116
}
117-
if (
118-
typeof value === 'object' &&
119-
!Array.isArray(value) &&
120-
Object.keys(value).length > 0
121-
) {
122-
this.attributes[key] = value;
123-
}
124117
if (key.length === 0) {
125118
api.diag.warn(`Invalid attribute key: ${key}`);
126119
return this;
127120
}
128-
if (!isAttributeValue(value)) {
121+
if (
122+
!isAttributeValue(value) &&
123+
!(
124+
typeof value === 'object' &&
125+
!Array.isArray(value) &&
126+
Object.keys(value).length > 0
127+
)
128+
) {
129129
api.diag.warn(`Invalid attribute value set for key: ${key}`);
130130
return this;
131131
}
@@ -136,7 +136,11 @@ export class LogRecord implements ReadableLogRecord {
136136
) {
137137
return this;
138138
}
139-
this.attributes[key] = this._truncateToSize(value);
139+
if (isAttributeValue(value)) {
140+
this.attributes[key] = this._truncateToSize(value);
141+
} else {
142+
this.attributes[key] = value;
143+
}
140144
return this;
141145
}
142146

experimental/packages/sdk-logs/test/common/LogRecord.test.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,36 @@ describe('LogRecord', () => {
179179
describe('when "attributeCountLimit" option defined', () => {
180180
const { logRecord } = setup({ attributeCountLimit: 100 });
181181
for (let i = 0; i < 150; i++) {
182-
logRecord.setAttribute(`foo${i}`, `bar${i}`);
182+
let attributeValue;
183+
switch (i % 3) {
184+
case 0: {
185+
attributeValue = `bar${i}`;
186+
break;
187+
}
188+
case 1: {
189+
attributeValue = [`bar${i}`];
190+
break;
191+
}
192+
case 2: {
193+
attributeValue = {
194+
bar: `bar${i}`,
195+
};
196+
break;
197+
}
198+
default: {
199+
attributeValue = `bar${i}`;
200+
}
201+
}
202+
logRecord.setAttribute(`foo${i}`, attributeValue);
183203
}
184204

185205
it('should remove / drop all remaining values after the number of values exceeds this limit', () => {
186206
const { attributes } = logRecord;
187207
assert.strictEqual(Object.keys(attributes).length, 100);
188208
assert.strictEqual(attributes.foo0, 'bar0');
189-
assert.strictEqual(attributes.foo99, 'bar99');
209+
assert.deepStrictEqual(attributes.foo98, { bar: 'bar98' });
210+
assert.strictEqual(attributes.foo147, undefined);
211+
assert.strictEqual(attributes.foo148, undefined);
190212
assert.strictEqual(attributes.foo149, undefined);
191213
});
192214
});

lerna.json

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
{
22
"version": "independent",
33
"npmClient": "npm",
4-
"useWorkspaces": true,
5-
"// packages": "Please sync with package.json#workspaces",
6-
"packages": [
7-
"api",
8-
"packages/*",
9-
"experimental/packages/*",
10-
"experimental/examples/*",
11-
"experimental/backwards-compatibility/*",
12-
"integration-tests/*",
13-
"selenium-tests",
14-
"examples/otlp-exporter-node",
15-
"examples/opentelemetry-web",
16-
"examples/http",
17-
"examples/https",
18-
"examples/esm-http-ts"
19-
]
4+
"useWorkspaces": true
205
}

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
},
103103
"cacheDir": ".changelog"
104104
},
105-
"// workspaces": "Please sync with lerna.json#packages",
106105
"workspaces": [
107106
"api",
108107
"packages/*",

packages/opentelemetry-context-zone-peer-dep/src/ZoneContextManager.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
/// <reference types="zone.js" />
1718
import { Context, ContextManager, ROOT_CONTEXT } from '@opentelemetry/api';
1819
import { TargetWithEvents } from './types';
1920
import { isListenerObject } from './util';

packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"rootDir": "src",
66
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
77
},
8-
"files": [
9-
"node_modules/zone.js/dist/zone.js.d.ts"
10-
],
118
"include": [
129
"src/**/*.ts"
1310
],

packages/opentelemetry-context-zone-peer-dep/tsconfig.esnext.json

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
"rootDir": "src",
66
"tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo"
77
},
8-
"files": [
9-
"node_modules/zone.js/dist/zone.js.d.ts"
10-
],
118
"include": [
129
"src/**/*.ts"
1310
],

packages/opentelemetry-context-zone-peer-dep/tsconfig.json

-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
"outDir": "build",
55
"rootDir": "."
66
},
7-
"files": [
8-
"node_modules/zone.js/dist/zone.js.d.ts"
9-
],
107
"include": [
118
"src/**/*.ts",
129
"test/**/*.ts"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 Benchmark = require('benchmark');
18+
const { BasicTracerProvider, BatchSpanProcessor } = require('../../../build/src');
19+
const { ExportResultCode } = require('@opentelemetry/core');
20+
21+
class NoopExporter {
22+
export(spans, resultCallback) {
23+
setTimeout(() => resultCallback({ code: ExportResultCode.SUCCESS }), 0);
24+
}
25+
26+
shutdown() {
27+
return this.forceFlush();
28+
}
29+
30+
forceFlush() {
31+
return Promise.resolve();
32+
}
33+
}
34+
35+
function createSpan() {
36+
const span = tracer.startSpan('span');
37+
span.setAttribute('aaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaa');
38+
span.setAttribute('bbbbbbbbbbbbbbbbbbbb', 'aaaaaaaaaaaaaaaaaaaa');
39+
span.setAttribute('cccccccccccccccccccc', 'aaaaaaaaaaaaaaaaaaaa');
40+
span.setAttribute('dddddddddddddddddddd', 'aaaaaaaaaaaaaaaaaaaa');
41+
span.setAttribute('eeeeeeeeeeeeeeeeeeee', 'aaaaaaaaaaaaaaaaaaaa');
42+
span.setAttribute('ffffffffffffffffffff', 'aaaaaaaaaaaaaaaaaaaa');
43+
span.setAttribute('gggggggggggggggggggg', 'aaaaaaaaaaaaaaaaaaaa');
44+
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'aaaaaaaaaaaaaaaaaaaa');
45+
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'aaaaaaaaaaaaaaaaaaaa');
46+
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'aaaaaaaaaaaaaaaaaaaa');
47+
span.end();
48+
}
49+
50+
const tracerProvider = new BasicTracerProvider();
51+
tracerProvider.addSpanProcessor(new BatchSpanProcessor(new NoopExporter()));
52+
const tracer = tracerProvider.getTracer('test')
53+
54+
const suite = new Benchmark.Suite('BatchSpanProcessor');
55+
56+
suite.on('cycle', event => {
57+
console.log(String(event.target));
58+
});
59+
60+
suite.add('BatchSpanProcessor process span', function() {
61+
createSpan();
62+
});
63+
64+
suite.run();

packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
*/
1616

1717
require('./span');
18+
require('./BatchSpanProcessor');

packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ suite.add('create spans (10 attributes)', function() {
3838
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'aaaaaaaaaaaaaaaaaaaa');
3939
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'aaaaaaaaaaaaaaaaaaaa');
4040
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'aaaaaaaaaaaaaaaaaaaa');
41+
span.end();
4142
});
4243

4344
suite.run();

0 commit comments

Comments
 (0)