diff --git a/CHANGELOG.md b/CHANGELOG.md index 887ccf13a3..b4b570dad4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 7a5a363e44..bb1fd6aca0 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -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) diff --git a/experimental/examples/prometheus/README.md b/experimental/examples/prometheus/README.md index 53ec356b61..398427baec 100644 --- a/experimental/examples/prometheus/README.md +++ b/experimental/examples/prometheus/README.md @@ -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 + +## 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 @@ -34,7 +45,6 @@ scrape_configs: # scheme defaults to 'http'. static_configs: - targets: ['localhost:9464'] - ``` - Start Prometheus @@ -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 diff --git a/experimental/examples/prometheus/docker-compose.yaml b/experimental/examples/prometheus/docker-compose.yaml new file mode 100644 index 0000000000..5647d893f9 --- /dev/null +++ b/experimental/examples/prometheus/docker-compose.yaml @@ -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 diff --git a/experimental/examples/prometheus/prometheus.docker.yml b/experimental/examples/prometheus/prometheus.docker.yml new file mode 100644 index 0000000000..2fb8007583 --- /dev/null +++ b/experimental/examples/prometheus/prometheus.docker.yml @@ -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'] diff --git a/experimental/packages/otlp-transformer/package.json b/experimental/packages/otlp-transformer/package.json index 7570d15051..04ee4c802e 100644 --- a/experimental/packages/otlp-transformer/package.json +++ b/experimental/packages/otlp-transformer/package.json @@ -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", diff --git a/experimental/packages/otlp-transformer/test/performance/benchmark/index.js b/experimental/packages/otlp-transformer/test/performance/benchmark/index.js new file mode 100644 index 0000000000..e110bbe784 --- /dev/null +++ b/experimental/packages/otlp-transformer/test/performance/benchmark/index.js @@ -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; +} diff --git a/experimental/packages/sdk-logs/src/LogRecord.ts b/experimental/packages/sdk-logs/src/LogRecord.ts index ed76d5eb07..8d8fae6168 100644 --- a/experimental/packages/sdk-logs/src/LogRecord.ts +++ b/experimental/packages/sdk-logs/src/LogRecord.ts @@ -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; } @@ -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; } diff --git a/experimental/packages/sdk-logs/test/common/LogRecord.test.ts b/experimental/packages/sdk-logs/test/common/LogRecord.test.ts index e32ab39838..678b4c2e72 100644 --- a/experimental/packages/sdk-logs/test/common/LogRecord.test.ts +++ b/experimental/packages/sdk-logs/test/common/LogRecord.test.ts @@ -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); }); }); diff --git a/lerna.json b/lerna.json index 4e03ac4f79..336c3e85ca 100644 --- a/lerna.json +++ b/lerna.json @@ -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 } diff --git a/package.json b/package.json index bfc13ff392..7e7cb81ade 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,6 @@ }, "cacheDir": ".changelog" }, - "// workspaces": "Please sync with lerna.json#packages", "workspaces": [ "api", "packages/*", diff --git a/packages/opentelemetry-context-zone-peer-dep/src/ZoneContextManager.ts b/packages/opentelemetry-context-zone-peer-dep/src/ZoneContextManager.ts index 3f5c8c71c8..81042ac652 100644 --- a/packages/opentelemetry-context-zone-peer-dep/src/ZoneContextManager.ts +++ b/packages/opentelemetry-context-zone-peer-dep/src/ZoneContextManager.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +/// import { Context, ContextManager, ROOT_CONTEXT } from '@opentelemetry/api'; import { TargetWithEvents } from './types'; import { isListenerObject } from './util'; diff --git a/packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json b/packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json index 971caf60aa..9d9e733405 100644 --- a/packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json +++ b/packages/opentelemetry-context-zone-peer-dep/tsconfig.esm.json @@ -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" ], diff --git a/packages/opentelemetry-context-zone-peer-dep/tsconfig.esnext.json b/packages/opentelemetry-context-zone-peer-dep/tsconfig.esnext.json index ff768ce18a..9f2935984e 100644 --- a/packages/opentelemetry-context-zone-peer-dep/tsconfig.esnext.json +++ b/packages/opentelemetry-context-zone-peer-dep/tsconfig.esnext.json @@ -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" ], diff --git a/packages/opentelemetry-context-zone-peer-dep/tsconfig.json b/packages/opentelemetry-context-zone-peer-dep/tsconfig.json index a4adfa3f7f..7e466ec926 100644 --- a/packages/opentelemetry-context-zone-peer-dep/tsconfig.json +++ b/packages/opentelemetry-context-zone-peer-dep/tsconfig.json @@ -4,9 +4,6 @@ "outDir": "build", "rootDir": "." }, - "files": [ - "node_modules/zone.js/dist/zone.js.d.ts" - ], "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/BatchSpanProcessor.js b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/BatchSpanProcessor.js new file mode 100644 index 0000000000..ccdb82d481 --- /dev/null +++ b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/BatchSpanProcessor.js @@ -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(); diff --git a/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js index 83558ea01f..1307732495 100644 --- a/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js +++ b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js @@ -15,3 +15,4 @@ */ require('./span'); +require('./BatchSpanProcessor'); diff --git a/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js index ac978a6140..851123c392 100644 --- a/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js +++ b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js @@ -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(); diff --git a/scripts/update-ts-configs.js b/scripts/update-ts-configs.js index d437172181..bc3319f4de 100644 --- a/scripts/update-ts-configs.js +++ b/scripts/update-ts-configs.js @@ -71,23 +71,23 @@ main(); function main() { const pkgRoot = process.cwd(); const projectRoot = findProjectRoot(pkgRoot); - const lernaPackages = resolveLernaPackages(projectRoot); + const workspacePackages = resolveWorkspacePackages(projectRoot); - generateTsConfig(projectRoot, lernaPackages, pkgRoot, true); - for (const packageMeta of lernaPackages.values()) { - generateTsConfig(projectRoot, lernaPackages, path.join(projectRoot, packageMeta.dir), false, packageMeta); + generateTsConfig(projectRoot, workspacePackages, pkgRoot, true); + for (const packageMeta of workspacePackages.values()) { + generateTsConfig(projectRoot, workspacePackages, path.join(projectRoot, packageMeta.dir), false, packageMeta); } } -function generateTsConfig(projectRoot, lernaProjects, pkgRoot, isLernaRoot, packageMeta) { +function generateTsConfig(projectRoot, workspacePackages, pkgRoot, isLernaRoot, packageMeta) { // Root tsconfig.json if (isLernaRoot) { - writeRootTsConfigJson(pkgRoot, projectRoot, lernaProjects); + writeRootTsConfigJson(pkgRoot, projectRoot, workspacePackages); return; } const otelDependencies = getOtelDependencies(packageMeta.pkgJson); - const dependenciesDir = resolveDependencyDirs(lernaProjects, otelDependencies); + const dependenciesDir = resolveDependencyDirs(workspacePackages, otelDependencies); const references = dependenciesDir.map(it => path.relative(pkgRoot, path.join(projectRoot, it))).sort(); if (packageMeta.hasMultiTarget) { @@ -97,16 +97,16 @@ function generateTsConfig(projectRoot, lernaProjects, pkgRoot, isLernaRoot, pack writeSingleTargetTsConfig(pkgRoot, projectRoot, references); } -function writeRootTsConfigJson(pkgRoot, projectRoot, lernaProjects) { +function writeRootTsConfigJson(pkgRoot, projectRoot, workspacePackages) { const tsconfigPath = path.join(pkgRoot, 'tsconfig.json'); const tsconfig = readJSON(tsconfigPath); - const references = Array.from(lernaProjects.values()) + const references = Array.from(workspacePackages.values()) .filter(it => it.isTsProject) .map(it => toPosix(path.relative(pkgRoot, path.join(projectRoot, it.dir)))).sort(); tsconfig.references = references.map(path => { return { path: toPosix(path) } }); - tsconfig.typedocOptions.entryPoints = Array.from(lernaProjects.values()) + tsconfig.typedocOptions.entryPoints = Array.from(workspacePackages.values()) .filter(it => !it.private && it.isTsProject) .map(it => toPosix(path.relative(pkgRoot, path.join(projectRoot, it.dir)))).sort(); writeJSON(tsconfigPath, tsconfig, dryRun); @@ -114,7 +114,7 @@ function writeRootTsConfigJson(pkgRoot, projectRoot, lernaProjects) { for (const tsconfigName of ['tsconfig.esm.json', 'tsconfig.esnext.json']) { const tsconfigPath = path.join(pkgRoot, tsconfigName); const tsconfig = readJSON(tsconfigPath); - const references = Array.from(lernaProjects.values()) + const references = Array.from(workspacePackages.values()) .filter(it => it.isTsProject && it.hasMultiTarget) .map(it => toPosix(path.relative(pkgRoot, path.join(projectRoot, it.dir)))).sort(); tsconfig.references = references.map(pkgPath => { @@ -182,10 +182,10 @@ function getOtelDependencies(packageJson) { return Array.from(deps.values()); } -function resolveLernaPackages(projectRoot) { +function resolveWorkspacePackages(projectRoot) { const map = new Map(); - const lernaJson = readJSON(`${projectRoot}/lerna.json`); - for (const pkgDefinition of lernaJson.packages) { + const packageJson = readJSON(`${projectRoot}/package.json`); + for (const pkgDefinition of packageJson.workspaces) { if (ignoredLernaProjects.includes(pkgDefinition)) { continue; }