Skip to content

Commit

Permalink
Merge branch 'main' into chore/dashboard-approval-for-lerna
Browse files Browse the repository at this point in the history
  • Loading branch information
pichlermarc authored Nov 9, 2023
2 parents f93d932 + f5ef8de commit 0dbfddd
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 57 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :house: (Internal)

* chore: type reference on zone.js [#4257](https://github.com/open-telemetry/opentelemetry-js/pull/4257) @legendecas
* chore: no need for 'packages' in lerna.json [#4264](https://github.com/open-telemetry/opentelemetry-js/pull/4264) @trentm

### :bug: (Bug Fix)

## 1.18.1

### :bug: (Bug Fix)
Expand Down
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(sdk-logs): avoid map attribute set when count limit exceeded

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
22 changes: 16 additions & 6 deletions experimental/examples/prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,28 @@ This is a simple example that demonstrates basic metrics collection and exports
npm install
```

Setup [Prometheus](https://prometheus.io/docs/prometheus/latest/getting_started/)

## Run the Application

- Run the server

```sh
# from this directory
npm run start
```

If you are using the default configurations, the metrics should be available at <http://localhost:9464/metrics>

## Run Prometheus

### With docker

```sh
# from this directory
docker compose up
```

### With binary

Setup [Prometheus](https://prometheus.io/docs/prometheus/latest/getting_started/)

- Replace the `prometheus.yml` provided by the Prometheus installation with the following:

```yaml
Expand All @@ -34,7 +45,6 @@ scrape_configs:
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9464']

```
- Start Prometheus
Expand All @@ -44,7 +54,7 @@ scrape_configs:
prometheus --config.file=prometheus.yml
```

### Prometheus UI
## Prometheus UI

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

Expand Down
12 changes: 12 additions & 0 deletions experimental/examples/prometheus/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.7'

services:
prometheus:
image: prom/prometheus:v2.47.2
extra_hosts:
- host.docker.internal:host-gateway
volumes:
- "./prometheus.docker.yml:/etc/prometheus/prometheus.yml"
ports:
- 9090:9090
restart: always
9 changes: 9 additions & 0 deletions experimental/examples/prometheus/prometheus.docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
global:
scrape_interval: 15s # Default is every 1 minute.

scrape_configs:
- job_name: 'opentelemetry'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['host.docker.internal:9464']
1 change: 1 addition & 0 deletions experimental/packages/otlp-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test:browser": "karma start --single-run",
"test:bench": "node test/performance/benchmark/index.js | tee .benchmark-results.txt",
"prewatch": "node ../../../scripts/version-update.js",
"watch": "tsc --build -w tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"peer-api-check": "node ../../../scripts/peer-api-check.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 Benchmark = require('benchmark');
const { createExportTraceServiceRequest } = require('../../../build/src');
const { BasicTracerProvider } = require('@opentelemetry/sdk-trace-base');

const tracerProvider = new BasicTracerProvider();
const tracer = tracerProvider.getTracer('test')

const suite = new Benchmark.Suite();

const span = createSpan();
const spans = [];
for (let i = 0; i < 100; i++) {
spans.push(createSpan());
}

suite.on('cycle', event => {
console.log(String(event.target));
});

suite.add('transform 1 span', function() {
createExportTraceServiceRequest([span]);
});

suite.add('transform 100 spans', function() {
createExportTraceServiceRequest(spans);
});

suite.run();

function createSpan() {
const span = tracer.startSpan('span');
span.setAttribute('aaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('bbbbbbbbbbbbbbbbbbbb', 'bbbbbbbbbbbbbbbbbbbb');
span.setAttribute('cccccccccccccccccccc', 'cccccccccccccccccccc');
span.setAttribute('dddddddddddddddddddd', 'dddddddddddddddddddd');
span.setAttribute('eeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeee');
span.setAttribute('ffffffffffffffffffff', 'ffffffffffffffffffff');
span.setAttribute('gggggggggggggggggggg', 'gggggggggggggggggggg');
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'hhhhhhhhhhhhhhhhhhhh');
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'iiiiiiiiiiiiiiiiiiii');
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'jjjjjjjjjjjjjjjjjjjj');
span.end();

return span;
}
22 changes: 13 additions & 9 deletions experimental/packages/sdk-logs/src/LogRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ export class LogRecord implements ReadableLogRecord {
if (value === null) {
return this;
}
if (
typeof value === 'object' &&
!Array.isArray(value) &&
Object.keys(value).length > 0
) {
this.attributes[key] = value;
}
if (key.length === 0) {
api.diag.warn(`Invalid attribute key: ${key}`);
return this;
}
if (!isAttributeValue(value)) {
if (
!isAttributeValue(value) &&
!(
typeof value === 'object' &&
!Array.isArray(value) &&
Object.keys(value).length > 0
)
) {
api.diag.warn(`Invalid attribute value set for key: ${key}`);
return this;
}
Expand All @@ -136,7 +136,11 @@ export class LogRecord implements ReadableLogRecord {
) {
return this;
}
this.attributes[key] = this._truncateToSize(value);
if (isAttributeValue(value)) {
this.attributes[key] = this._truncateToSize(value);
} else {
this.attributes[key] = value;
}
return this;
}

Expand Down
26 changes: 24 additions & 2 deletions experimental/packages/sdk-logs/test/common/LogRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,36 @@ describe('LogRecord', () => {
describe('when "attributeCountLimit" option defined', () => {
const { logRecord } = setup({ attributeCountLimit: 100 });
for (let i = 0; i < 150; i++) {
logRecord.setAttribute(`foo${i}`, `bar${i}`);
let attributeValue;
switch (i % 3) {
case 0: {
attributeValue = `bar${i}`;
break;
}
case 1: {
attributeValue = [`bar${i}`];
break;
}
case 2: {
attributeValue = {
bar: `bar${i}`,
};
break;
}
default: {
attributeValue = `bar${i}`;
}
}
logRecord.setAttribute(`foo${i}`, attributeValue);
}

it('should remove / drop all remaining values after the number of values exceeds this limit', () => {
const { attributes } = logRecord;
assert.strictEqual(Object.keys(attributes).length, 100);
assert.strictEqual(attributes.foo0, 'bar0');
assert.strictEqual(attributes.foo99, 'bar99');
assert.deepStrictEqual(attributes.foo98, { bar: 'bar98' });
assert.strictEqual(attributes.foo147, undefined);
assert.strictEqual(attributes.foo148, undefined);
assert.strictEqual(attributes.foo149, undefined);
});
});
Expand Down
17 changes: 1 addition & 16 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
{
"version": "independent",
"npmClient": "npm",
"useWorkspaces": true,
"// packages": "Please sync with package.json#workspaces",
"packages": [
"api",
"packages/*",
"experimental/packages/*",
"experimental/examples/*",
"experimental/backwards-compatibility/*",
"integration-tests/*",
"selenium-tests",
"examples/otlp-exporter-node",
"examples/opentelemetry-web",
"examples/http",
"examples/https",
"examples/esm-http-ts"
]
"useWorkspaces": true
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
},
"cacheDir": ".changelog"
},
"// workspaces": "Please sync with lerna.json#packages",
"workspaces": [
"api",
"packages/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

/// <reference types="zone.js" />
import { Context, ContextManager, ROOT_CONTEXT } from '@opentelemetry/api';
import { TargetWithEvents } from './types';
import { isListenerObject } from './util';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"rootDir": "src",
"tsBuildInfoFile": "build/esm/tsconfig.esm.tsbuildinfo"
},
"files": [
"node_modules/zone.js/dist/zone.js.d.ts"
],
"include": [
"src/**/*.ts"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"rootDir": "src",
"tsBuildInfoFile": "build/esnext/tsconfig.esnext.tsbuildinfo"
},
"files": [
"node_modules/zone.js/dist/zone.js.d.ts"
],
"include": [
"src/**/*.ts"
],
Expand Down
3 changes: 0 additions & 3 deletions packages/opentelemetry-context-zone-peer-dep/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
"outDir": "build",
"rootDir": "."
},
"files": [
"node_modules/zone.js/dist/zone.js.d.ts"
],
"include": [
"src/**/*.ts",
"test/**/*.ts"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 Benchmark = require('benchmark');
const { BasicTracerProvider, BatchSpanProcessor } = require('../../../build/src');
const { ExportResultCode } = require('@opentelemetry/core');

class NoopExporter {
export(spans, resultCallback) {
setTimeout(() => resultCallback({ code: ExportResultCode.SUCCESS }), 0);
}

shutdown() {
return this.forceFlush();
}

forceFlush() {
return Promise.resolve();
}
}

function createSpan() {
const span = tracer.startSpan('span');
span.setAttribute('aaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('bbbbbbbbbbbbbbbbbbbb', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('cccccccccccccccccccc', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('dddddddddddddddddddd', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('eeeeeeeeeeeeeeeeeeee', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('ffffffffffffffffffff', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('gggggggggggggggggggg', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'aaaaaaaaaaaaaaaaaaaa');
span.end();
}

const tracerProvider = new BasicTracerProvider();
tracerProvider.addSpanProcessor(new BatchSpanProcessor(new NoopExporter()));
const tracer = tracerProvider.getTracer('test')

const suite = new Benchmark.Suite('BatchSpanProcessor');

suite.on('cycle', event => {
console.log(String(event.target));
});

suite.add('BatchSpanProcessor process span', function() {
createSpan();
});

suite.run();
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
*/

require('./span');
require('./BatchSpanProcessor');
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ suite.add('create spans (10 attributes)', function() {
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'aaaaaaaaaaaaaaaaaaaa');
span.end();
});

suite.run();
Loading

0 comments on commit 0dbfddd

Please sign in to comment.