From 6a876a053fdcaeea20e53c2fa0d829c8a6819826 Mon Sep 17 00:00:00 2001 From: Jamie Danielson Date: Wed, 17 May 2023 01:22:27 -0400 Subject: [PATCH 01/14] feat(otlp-metric-exporters): Add User-Agent header to OTLP metric exporters (#3806) Co-authored-by: Marc Pichler --- experimental/CHANGELOG.md | 1 + .../src/OTLPMetricExporter.ts | 15 ++++++++++++--- .../test/OTLPMetricExporter.test.ts | 8 ++++++++ .../src/platform/node/OTLPMetricExporter.ts | 15 ++++++++++----- .../test/node/CollectorMetricExporter.test.ts | 8 ++++++++ .../src/OTLPMetricExporter.ts | 15 ++++++++++----- .../test/OTLPMetricExporter.test.ts | 11 +++++++++++ 7 files changed, 60 insertions(+), 13 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 3ee06e9fc81..19a69846ed5 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to experimental packages in this project will be documented ### :rocket: (Enhancement) * feat(otlp-trace-exporters): Add User-Agent header to OTLP trace exporters. [#3790](https://github.com/open-telemetry/opentelemetry-js/pull/3790) @JamieDanielson +* feat(otlp-metric-exporters): Add User-Agent header to OTLP metric exporters. [#3806](https://github.com/open-telemetry/opentelemetry-js/pull/3806) @JamieDanielson ### :boom: Breaking Change diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts index 20f917e5439..0ada75d4375 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/src/OTLPMetricExporter.ts @@ -32,6 +32,11 @@ import { createExportMetricsServiceRequest, IExportMetricsServiceRequest, } from '@opentelemetry/otlp-transformer'; +import { VERSION } from './version'; + +const USER_AGENT = { + 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, +}; class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase< ResourceMetrics, @@ -39,9 +44,13 @@ class OTLPMetricExporterProxy extends OTLPGRPCExporterNodeBase< > { constructor(config?: OTLPGRPCExporterConfigNode & OTLPMetricExporterOptions) { super(config); - const headers = baggageUtils.parseKeyPairsIntoRecord( - getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS - ); + const headers = { + ...USER_AGENT, + ...baggageUtils.parseKeyPairsIntoRecord( + getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS + ), + }; + this.metadata ||= new Metadata(); for (const [k, v] of Object.entries(headers)) { this.metadata.set(k, v); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts index 4b8d3265459..9e4e27ecb0a 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts @@ -43,6 +43,7 @@ import { IExportMetricsServiceRequest, IResourceMetrics, } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../src/version'; const metricsServiceProtoPath = 'opentelemetry/proto/collector/metrics/v1/metrics_service.proto'; @@ -314,6 +315,13 @@ describe('when configuring via environment', () => { ); envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; }); + it('should include user agent in header', () => { + const collectorExporter = new OTLPMetricExporter(); + assert.deepStrictEqual( + collectorExporter._otlpExporter.metadata?.get('User-Agent'), + [`OTel-OTLP-Exporter-JavaScript/${VERSION}`] + ); + }); it('should override global headers config with signal headers defined via env', () => { const metadata = new grpc.Metadata(); metadata.set('foo', 'bar'); diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts index 980931a6cb0..f83e414e701 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/platform/node/OTLPMetricExporter.ts @@ -28,9 +28,13 @@ import { createExportMetricsServiceRequest, IExportMetricsServiceRequest, } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../../version'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics'; const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const USER_AGENT = { + 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, +}; class OTLPExporterNodeProxy extends OTLPExporterNodeBase< ResourceMetrics, @@ -38,12 +42,13 @@ class OTLPExporterNodeProxy extends OTLPExporterNodeBase< > { constructor(config?: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions) { super(config); - this.headers = Object.assign( - this.headers, - baggageUtils.parseKeyPairsIntoRecord( + this.headers = { + ...this.headers, + ...USER_AGENT, + ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS - ) - ); + ), + }; } convert(metrics: ResourceMetrics[]): IExportMetricsServiceRequest { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts index d23ca628f70..042e5ebb4be 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-http/test/node/CollectorMetricExporter.test.ts @@ -50,6 +50,7 @@ import { OTLPExporterNodeConfigBase, } from '@opentelemetry/otlp-exporter-base'; import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../../src/version'; let fakeRequest: PassThrough; @@ -188,6 +189,13 @@ describe('OTLPMetricExporter - node with json over http', () => { assert.strictEqual(collectorExporter._otlpExporter.headers.foo, 'bar'); envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; }); + it('should include user agent in header', () => { + const collectorExporter = new OTLPMetricExporter(); + assert.strictEqual( + collectorExporter._otlpExporter.headers['User-Agent'], + `OTel-OTLP-Exporter-JavaScript/${VERSION}` + ); + }); it('should override global headers config with signal headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar,bar=foo'; envSource.OTEL_EXPORTER_OTLP_METRICS_HEADERS = 'foo=boo'; diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts index c29ae0085ca..8d1fb114b3f 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/src/OTLPMetricExporter.ts @@ -31,9 +31,13 @@ import { createExportMetricsServiceRequest, IExportMetricsServiceRequest, } from '@opentelemetry/otlp-transformer'; +import { VERSION } from './version'; const DEFAULT_COLLECTOR_RESOURCE_PATH = 'v1/metrics'; const DEFAULT_COLLECTOR_URL = `http://localhost:4318/${DEFAULT_COLLECTOR_RESOURCE_PATH}`; +const USER_AGENT = { + 'User-Agent': `OTel-OTLP-Exporter-JavaScript/${VERSION}`, +}; class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase< ResourceMetrics, @@ -41,12 +45,13 @@ class OTLPMetricExporterNodeProxy extends OTLPProtoExporterNodeBase< > { constructor(config?: OTLPExporterNodeConfigBase & OTLPMetricExporterOptions) { super(config); - this.headers = Object.assign( - this.headers, - baggageUtils.parseKeyPairsIntoRecord( + this.headers = { + ...this.headers, + ...USER_AGENT, + ...baggageUtils.parseKeyPairsIntoRecord( getEnv().OTEL_EXPORTER_OTLP_METRICS_HEADERS - ) - ); + ), + }; } convert(metrics: ResourceMetrics[]): IExportMetricsServiceRequest { diff --git a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts index 05ca183dcc8..d3270b6a9f3 100644 --- a/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts +++ b/experimental/packages/opentelemetry-exporter-metrics-otlp-proto/test/OTLPMetricExporter.test.ts @@ -46,6 +46,7 @@ import { OTLPMetricExporterOptions } from '@opentelemetry/exporter-metrics-otlp- import { Stream, PassThrough } from 'stream'; import { OTLPExporterNodeConfigBase } from '@opentelemetry/otlp-exporter-base'; import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; +import { VERSION } from '../src/version'; let fakeRequest: PassThrough; @@ -60,6 +61,16 @@ describe('OTLPMetricExporter - node with proto over http', () => { sinon.restore(); }); + describe('default behavior for headers', () => { + const collectorExporter = new OTLPMetricExporter(); + it('should include user agent in header', () => { + assert.strictEqual( + collectorExporter._otlpExporter.headers['User-Agent'], + `OTel-OTLP-Exporter-JavaScript/${VERSION}` + ); + }); + }); + describe('when configuring via environment', () => { const envSource = process.env; it('should use url defined in env that ends with root path and append version and signal path', () => { From 81ee1df218401bb34e5340fd9b1531b8935ad910 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Wed, 17 May 2023 15:18:40 +0200 Subject: [PATCH 02/14] chore(deps): update node.js to v20 (#3768) Co-authored-by: Daniel Dyla --- .github/workflows/peer-api.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/peer-api.yml b/.github/workflows/peer-api.yml index ac90efe9816..e6f52cccd77 100644 --- a/.github/workflows/peer-api.yml +++ b/.github/workflows/peer-api.yml @@ -11,7 +11,7 @@ jobs: peer-api-check: runs-on: ubuntu-latest container: - image: node:18 + image: node:20 steps: - name: Checkout uses: actions/checkout@v3 From c3feabe4e754055bad3805c7feb1b65e05a1742e Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Wed, 17 May 2023 16:06:12 +0200 Subject: [PATCH 03/14] fix(deps): update dependency axios to v1 (#3299) * fix(deps): update dependency axios to v1 * fix(deps): update dependency axios to v1 * Fix types --------- Co-authored-by: Daniel Dyla --- .../packages/opentelemetry-instrumentation-http/package.json | 2 +- .../test/functionals/http-package.test.ts | 2 +- .../test/functionals/https-package.test.ts | 2 +- integration-tests/propagation-validation-server/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation-http/package.json b/experimental/packages/opentelemetry-instrumentation-http/package.json index 763dabdf997..b46eef6a181 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/package.json +++ b/experimental/packages/opentelemetry-instrumentation-http/package.json @@ -56,7 +56,7 @@ "@types/semver": "7.3.9", "@types/sinon": "10.0.13", "@types/superagent": "4.1.13", - "axios": "0.24.0", + "axios": "1.4.0", "codecov": "3.8.3", "mocha": "10.0.0", "nock": "13.0.11", diff --git a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-package.test.ts b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-package.test.ts index 39b288ccdbb..c07039f290c 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-package.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/http-package.test.ts @@ -104,7 +104,7 @@ describe('Packages', () => { const result = await httpPackage.get(urlparsed.href!); if (!resHeaders) { const res = result as AxiosResponse; - resHeaders = res.headers; + resHeaders = res.headers as any; } const spans = memoryExporter.getFinishedSpans(); const span = spans[0]; diff --git a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-package.test.ts b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-package.test.ts index dada803e451..a7c5972a6a4 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-package.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/https-package.test.ts @@ -110,7 +110,7 @@ describe('Packages', () => { const result = await httpPackage.get(urlparsed.href!); if (!resHeaders) { const res = result as AxiosResponse; - resHeaders = res.headers; + resHeaders = res.headers as any; } const spans = memoryExporter.getFinishedSpans(); const span = spans[0]; diff --git a/integration-tests/propagation-validation-server/package.json b/integration-tests/propagation-validation-server/package.json index f2d5d6e9452..88846f5d9f7 100644 --- a/integration-tests/propagation-validation-server/package.json +++ b/integration-tests/propagation-validation-server/package.json @@ -15,7 +15,7 @@ "@opentelemetry/context-async-hooks": "1.13.0", "@opentelemetry/core": "1.13.0", "@opentelemetry/sdk-trace-base": "1.13.0", - "axios": "0.24.0", + "axios": "1.4.0", "body-parser": "1.19.0", "express": "4.17.3" }, From 18ea3df2b7f8c517195f6f579aab38472e460fe1 Mon Sep 17 00:00:00 2001 From: Aaron Abbott Date: Wed, 17 May 2023 11:56:23 -0400 Subject: [PATCH 04/14] chore(changelog): combine accidental multiple enhancement sections into one (#3815) --- experimental/CHANGELOG.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 19a69846ed5..23bce4b247c 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -4,16 +4,13 @@ All notable changes to experimental packages in this project will be documented ## Unreleased -### :rocket: (Enhancement) - -* feat(otlp-trace-exporters): Add User-Agent header to OTLP trace exporters. [#3790](https://github.com/open-telemetry/opentelemetry-js/pull/3790) @JamieDanielson -* feat(otlp-metric-exporters): Add User-Agent header to OTLP metric exporters. [#3806](https://github.com/open-telemetry/opentelemetry-js/pull/3806) @JamieDanielson - ### :boom: Breaking Change ### :rocket: (Enhancement) * feat(instrumentation): add ESM support for instrumentation. [#3698](https://github.com/open-telemetry/opentelemetry-js/pull/3698) @JamieDanielson, @pkanal, @vmarchaud, @lizthegrey, @bengl +* feat(otlp-trace-exporters): Add User-Agent header to OTLP trace exporters. [#3790](https://github.com/open-telemetry/opentelemetry-js/pull/3790) @JamieDanielson +* feat(otlp-metric-exporters): Add User-Agent header to OTLP metric exporters. [#3806](https://github.com/open-telemetry/opentelemetry-js/pull/3806) @JamieDanielson ### :bug: (Bug Fix) From 17eca4c79206fb13d6800920213c9f959c1699ec Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Wed, 17 May 2023 17:57:17 +0200 Subject: [PATCH 05/14] fix(deps): update dependency require-in-the-middle to v7 (#3782) Co-authored-by: Daniel Dyla --- experimental/packages/shim-opencensus/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/packages/shim-opencensus/package.json b/experimental/packages/shim-opencensus/package.json index 87512230d7e..1dae7c52a5f 100644 --- a/experimental/packages/shim-opencensus/package.json +++ b/experimental/packages/shim-opencensus/package.json @@ -67,7 +67,7 @@ "dependencies": { "@opentelemetry/context-async-hooks": "1.13.0", "@opentelemetry/core": "1.13.0", - "require-in-the-middle": "^6.0.0", + "require-in-the-middle": "^7.0.0", "semver": "^7.3.5" }, "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/shim-opencensus", From fcd75dfda82b84c2131ed91e4362eb13085cd578 Mon Sep 17 00:00:00 2001 From: Jackson Weber <47067795+JacksonWeber@users.noreply.github.com> Date: Wed, 17 May 2023 13:07:26 -0700 Subject: [PATCH 06/14] feat(opentelemetry-sdk-trace-base): Add optional forceFlush property to SpanExporter interface (#3753) * feat(opentelemetry-sdk-trace-base): Add optional forceFlush property to SpanExporter interface Signed-off-by: Sidartha Gracias * feat(opentelemetry-sdk-trace-base): fixup changelog Signed-off-by: Sidartha Gracias * feat(opentelemetry-sdk-trace-base): fixup changelog Signed-off-by: Sidartha Gracias * feat(opentelemetry-sdk-trace-base): add exporter forceflush functions Signed-off-by: Sidartha Gracias * feat(opentelemetry-sdk-trace-base): add tests, add empty implemtation for downstream exporters Signed-off-by: Sidartha Gracias * feat(opentelemetry-sdk-trace-base): add implementation for forceflush for zipkin, jaeger, otlp * feat(opentelemetry-sdk-trace-base): fix lint, minor review change * feat(opentelemetry-sdk-trace-base): minor review change * feat(opentelemetry-sdk-trace-base): fix lint * feat(opentelemetry-sdk-trace-base): minor change * Fix lint. * Have the SimpleSpanProcessor handle force flush. * Update changelog. * Update the span processor to call forceFlush in the exporter. * Fix lint. * Make the forceFlush method optional. * fix(changelog): replace mandatory -> optional * Add or update the Azure App Service build and deployment workflow config * Delete issue_3067_jacksonweber-test-github.yml * Add comment for ignoring resolved values. --------- Signed-off-by: Sidartha Gracias Co-authored-by: Sidartha Gracias Co-authored-by: Sidartha Gracias <97981532+sgracias1@users.noreply.github.com> Co-authored-by: Marc Pichler --- CHANGELOG.md | 2 ++ .../test/fetch.test.ts | 4 ++++ .../test/xhr.test.ts | 4 ++++ .../otlp-exporter-base/src/OTLPExporterBase.ts | 13 ++++++++++--- .../otlp-exporter-base/test/node/util.test.ts | 7 +++++++ .../opentelemetry-exporter-jaeger/src/jaeger.ts | 7 +++++++ .../test/jaeger.test.ts | 8 ++++++++ .../opentelemetry-exporter-zipkin/src/zipkin.ts | 7 +++++++ .../test/node/zipkin.test.ts | 7 +++++++ .../src/export/ConsoleSpanExporter.ts | 7 +++++++ .../src/export/InMemorySpanExporter.ts | 7 +++++++ .../src/export/SimpleSpanProcessor.ts | 3 +++ .../src/export/SpanExporter.ts | 3 +++ .../test/common/export/ConsoleSpanExporter.test.ts | 7 +++++++ .../test/common/export/InMemorySpanExporter.test.ts | 7 +++++++ .../test/common/export/SimpleSpanProcessor.test.ts | 8 ++++++++ 16 files changed, 98 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3ebf020f92..f827e315853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :rocket: (Enhancement) +* feat(SpanExpoter): Add optional forceFlush to SpanExporter interface [#3753](https://github.com/open-telemetry/opentelemetry-js/pull/3753/) @sgracias1 @JacksonWeber + ### :bug: (Bug Fix) ### :books: (Refine Doc) diff --git a/experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts b/experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts index 40f3381dbb0..318e0f98c3e 100644 --- a/experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts @@ -49,6 +49,10 @@ class DummySpanExporter implements tracing.SpanExporter { shutdown() { return Promise.resolve(); } + + forceFlush(): Promise { + return Promise.resolve(); + } } const getData = (url: string, method?: string) => { diff --git a/experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts b/experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts index 6176dd005c4..b304bb9c03d 100644 --- a/experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts @@ -46,6 +46,10 @@ class DummySpanExporter implements tracing.SpanExporter { shutdown() { return Promise.resolve(); } + + forceFlush(): Promise { + return Promise.resolve(); + } } const XHR_TIMEOUT = 2000; diff --git a/experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts b/experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts index c78adb7e278..c9603057830 100644 --- a/experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts +++ b/experimental/packages/otlp-exporter-base/src/OTLPExporterBase.ts @@ -117,15 +117,22 @@ export abstract class OTLPExporterBase< return this._shutdownOnce.call(); } + /** + * Exports any pending spans in the exporter + */ + forceFlush(): Promise { + return Promise.all(this._sendingPromises).then(() => { + /** ignore resolved values */ + }); + } + /** * Called by _shutdownOnce with BindOnceFuture */ private _shutdown(): Promise { diag.debug('shutdown started'); this.onShutdown(); - return Promise.all(this._sendingPromises).then(() => { - /** ignore resolved values */ - }); + return this.forceFlush(); } abstract onShutdown(): void; diff --git a/experimental/packages/otlp-exporter-base/test/node/util.test.ts b/experimental/packages/otlp-exporter-base/test/node/util.test.ts index 86c8df40ab0..b279e57b9a1 100644 --- a/experimental/packages/otlp-exporter-base/test/node/util.test.ts +++ b/experimental/packages/otlp-exporter-base/test/node/util.test.ts @@ -60,6 +60,13 @@ class Exporter extends OTLPExporterNodeBase { } } +describe('force flush', () => { + it('forceFlush should flush spans and return', async () => { + const exporter = new Exporter({}); + await exporter.forceFlush(); + }); +}); + describe('configureExporterTimeout', () => { const envSource = process.env; it('should use timeoutMillis parameter as export timeout value', () => { diff --git a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts index 28d3ccb3372..aafc884cd08 100644 --- a/packages/opentelemetry-exporter-jaeger/src/jaeger.ts +++ b/packages/opentelemetry-exporter-jaeger/src/jaeger.ts @@ -97,6 +97,13 @@ export class JaegerExporter implements SpanExporter { return this._shutdownOnce.call(); } + /** + * Exports any pending spans in exporter + */ + forceFlush(): Promise { + return this._flush(); + } + private _shutdown(): Promise { return Promise.race([ new Promise((_resolve, reject) => { diff --git a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts index bcfdbf051f8..d6675796370 100644 --- a/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts +++ b/packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts @@ -178,6 +178,14 @@ describe('JaegerExporter', () => { }); }); + describe('force flush', () => { + let exporter: JaegerExporter; + it('forceFlush should flush spans and return', async () => { + exporter = new JaegerExporter(); + await exporter.forceFlush(); + }); + }); + describe('export', () => { let exporter: JaegerExporter; diff --git a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts index 2cb3e44436b..ca52806d39c 100644 --- a/packages/opentelemetry-exporter-zipkin/src/zipkin.ts +++ b/packages/opentelemetry-exporter-zipkin/src/zipkin.ts @@ -102,6 +102,13 @@ export class ZipkinExporter implements SpanExporter { shutdown(): Promise { diag.debug('Zipkin exporter shutdown'); this._isShutdown = true; + return this.forceFlush(); + } + + /** + * Exports any pending spans in exporter + */ + forceFlush(): Promise { return new Promise((resolve, reject) => { Promise.all(this._sendingPromises).then(() => { resolve(); diff --git a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts index eeab75348e8..30016624980 100644 --- a/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts +++ b/packages/opentelemetry-exporter-zipkin/test/node/zipkin.test.ts @@ -526,6 +526,13 @@ describe('Zipkin Exporter - node', () => { }); }); + describe('force flush', () => { + it('forceFlush should flush spans and return', async () => { + const exporter = new ZipkinExporter({}); + await exporter.forceFlush(); + }); + }); + describe('when env.OTEL_EXPORTER_ZIPKIN_ENDPOINT is set', () => { before(() => { process.env.OTEL_EXPORTER_ZIPKIN_ENDPOINT = 'http://localhost:9412'; diff --git a/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts b/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts index 77b0965598f..596b3cefd3b 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts @@ -46,6 +46,13 @@ export class ConsoleSpanExporter implements SpanExporter { */ shutdown(): Promise { this._sendSpans([]); + return this.forceFlush(); + } + + /** + * Exports any pending spans in exporter + */ + forceFlush(): Promise { return Promise.resolve(); } diff --git a/packages/opentelemetry-sdk-trace-base/src/export/InMemorySpanExporter.ts b/packages/opentelemetry-sdk-trace-base/src/export/InMemorySpanExporter.ts index c7c17d80c16..4a755ea8cd9 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/InMemorySpanExporter.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/InMemorySpanExporter.ts @@ -48,6 +48,13 @@ export class InMemorySpanExporter implements SpanExporter { shutdown(): Promise { this._stopped = true; this._finishedSpans = []; + return this.forceFlush(); + } + + /** + * Exports any pending spans in the exporter + */ + forceFlush(): Promise { return Promise.resolve(); } diff --git a/packages/opentelemetry-sdk-trace-base/src/export/SimpleSpanProcessor.ts b/packages/opentelemetry-sdk-trace-base/src/export/SimpleSpanProcessor.ts index 8351b4b6edd..463e8376bde 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/SimpleSpanProcessor.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/SimpleSpanProcessor.ts @@ -46,6 +46,9 @@ export class SimpleSpanProcessor implements SpanProcessor { async forceFlush(): Promise { // await unresolved resources before resolving await Promise.all(Array.from(this._unresolvedExports)); + if (this._exporter.forceFlush) { + await this._exporter.forceFlush(); + } } onStart(_span: Span, _parentContext: Context): void {} diff --git a/packages/opentelemetry-sdk-trace-base/src/export/SpanExporter.ts b/packages/opentelemetry-sdk-trace-base/src/export/SpanExporter.ts index b3b89d4aa61..c9ca9c0c897 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/SpanExporter.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/SpanExporter.ts @@ -36,4 +36,7 @@ export interface SpanExporter { /** Stops the exporter. */ shutdown(): Promise; + + /** Immediately export all spans */ + forceFlush?(): Promise; } diff --git a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts index 72642927a38..d005a2f8035 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts @@ -99,4 +99,11 @@ describe('ConsoleSpanExporter', () => { }); }); }); + + describe('force flush', () => { + it('forceFlush should flush spans and return', async () => { + consoleExporter = new ConsoleSpanExporter(); + await consoleExporter.forceFlush(); + }); + }); }); diff --git a/packages/opentelemetry-sdk-trace-base/test/common/export/InMemorySpanExporter.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/export/InMemorySpanExporter.test.ts index df9105d97b1..585610514ee 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/export/InMemorySpanExporter.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/export/InMemorySpanExporter.test.ts @@ -86,6 +86,13 @@ describe('InMemorySpanExporter', () => { assert.strictEqual(memoryExporter.getFinishedSpans().length, 0); }); + describe('force flush', () => { + it('forceFlush should flush spans and return', async () => { + memoryExporter = new InMemorySpanExporter(); + await memoryExporter.forceFlush(); + }); + }); + it('should return the success result', () => { const exorter = new InMemorySpanExporter(); exorter.export([], (result: ExportResult) => { diff --git a/packages/opentelemetry-sdk-trace-base/test/common/export/SimpleSpanProcessor.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/export/SimpleSpanProcessor.test.ts index 88490c527b8..94e86eeed7f 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/export/SimpleSpanProcessor.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/export/SimpleSpanProcessor.test.ts @@ -152,6 +152,14 @@ describe('SimpleSpanProcessor', () => { }); describe('force flush', () => { + it('should call forceflush on exporter', () => { + const spyflush = sinon.spy(exporter, 'forceFlush'); + const processor = new SimpleSpanProcessor(exporter); + processor.forceFlush().then(() => { + assert.ok(spyflush.calledOnce); + }); + }); + it('should await unresolved resources', async () => { const processor = new SimpleSpanProcessor(exporter); const providerWithAsyncResource = new BasicTracerProvider({ From d4a41bd815dd50703f692000a70c59235ad71959 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Wed, 17 May 2023 17:11:03 -0400 Subject: [PATCH 07/14] Add scripts to prepare releases automatically (#3805) --- .github/workflows/label-releases.yml | 12 ++++++++++++ package.json | 20 ++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/label-releases.yml diff --git a/.github/workflows/label-releases.yml b/.github/workflows/label-releases.yml new file mode 100644 index 00000000000..29c5357f71d --- /dev/null +++ b/.github/workflows/label-releases.yml @@ -0,0 +1,12 @@ +on: + pull_request_target: + branches: + - main + +jobs: + label-release: + if: ${{ startsWith(github.event.pull_request.title, 'release:') }} + runs-on: ubuntu-latest + steps: + - run: echo this is a release PR + - run: gh pr edit ${{ github.event.pull_request.number }} --add-label release diff --git a/package.json b/package.json index d03e6ff438e..0d232ef6361 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,24 @@ "lint:markdown": "./node_modules/.bin/markdownlint $(git ls-files '*.md') -i ./CHANGELOG.md", "lint:markdown:fix": "./node_modules/.bin/markdownlint $(git ls-files '*.md') -i ./CHANGELOG.md --fix", "reset": "lerna clean -y && rm -rf node_modules && npm i && npm run compile && npm run lint:fix", - "update-ts-configs": "node scripts/update-ts-configs.js" + "update-ts-configs": "node scripts/update-ts-configs.js", + + "comment_prepare_1": "echo scripts in this section automatically prepare releases. Intended for use by maintainers only.", + "comment_prepare_2": "echo experimental preparation scripts only prepare experimental packages", + "prepare_release:experimental:patch": "npm run _check:no_changes && npm run _backup:lerna && npm run _lerna:remove_api && npm run _lerna:remove_stable && npm run _lerna:version_patch && npm run _restore:lerna", + "prepare_release:experimental:minor": "npm run _check:no_changes && npm run _backup:lerna && npm run _lerna:remove_api && npm run _lerna:remove_stable && npm run _lerna:version_minor && npm run _restore:lerna", + "comment_prepare_3": "echo sdk preparation scripts prepare all stable and experimental packages", + "prepare_release:sdk:patch": "npm run _check:no_changes && npm run _backup:lerna && npm run _lerna:remove_api && npm run _lerna:version_patch && npm run _restore:lerna", + "prepare_release:sdk:minor": "npm run _check:no_changes && npm run _backup:lerna && npm run _lerna:remove_api && npm run _lerna:version_minor && npm run _restore:lerna", + + "comment_internal": "echo scripts below this line are for internal use", + "_check:no_changes": "if [ ! -z \"$(git status -uall --porcelain)\" ]; then echo Please ensure all changes are committed; exit 1; fi", + "_backup:lerna": "cp lerna.json lerna.json.backup", + "_restore:lerna": "mv lerna.json.backup lerna.json", + "_lerna:remove_api": "node -e 'var fs=require(\"fs\");var l=require(\"./lerna.json\");l.packages=l.packages.filter(p=>p!==\"api\");fs.writeFileSync(\"lerna.json\",JSON.stringify(l,null,2))'", + "_lerna:remove_stable": "node -e 'var fs=require(\"fs\");var l=require(\"./lerna.json\");l.packages=l.packages.filter(p=>p!==\"packages/*\");fs.writeFileSync(\"lerna.json\",JSON.stringify(l,null,2))'", + "_lerna:version_patch": "npx lerna version patch --exact --no-git-tag-version --no-push --yes", + "_lerna:version_minor": "npx lerna version minor --exact --no-git-tag-version --no-push --yes" }, "repository": "open-telemetry/opentelemetry-js", "keywords": [ @@ -55,7 +72,6 @@ "eslint-plugin-prettier": "4.2.1", "gh-pages": "5.0.0", "lerna": "6.0.3", - "lerna-changelog": "2.2.0", "linkinator": "4.0.3", "markdownlint-cli": "0.32.2", "prettier": "2.8.0", From 9fe1f7d8d5aef51136b9d9313a0d4175de67f268 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Fri, 19 May 2023 20:30:03 +0200 Subject: [PATCH 08/14] chore(deps): update dependency chromedriver to v113 (#3822) --- selenium-tests/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selenium-tests/package.json b/selenium-tests/package.json index 5635f40c013..1bef831b3e8 100644 --- a/selenium-tests/package.json +++ b/selenium-tests/package.json @@ -40,7 +40,7 @@ "babel-loader": "8.2.3", "babel-polyfill": "6.26.0", "browserstack-local": "1.4.8", - "chromedriver": "112.0.0", + "chromedriver": "113.0.0", "dotenv": "16.0.0", "fast-safe-stringify": "2.1.1", "geckodriver": "3.0.1", From de22983c50a341364871af753b6cf9ad99a7550e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=B2=92=E7=B2=92=E6=A9=99?= Date: Sat, 20 May 2023 03:13:37 +0800 Subject: [PATCH 09/14] feat(api-logs): add `ObservedTimestamp` to `LogRecord` (#3787) * feat(api-logs): add `ObservedTimestamp` to `LogRecord` * chore(changelog): add changelog * fix(sdk-logs): use `Date` instead of `hrTime()` for timestamps --------- Co-authored-by: Marc Pichler Co-authored-by: Daniel Dyla --- experimental/CHANGELOG.md | 1 + experimental/packages/api-logs/src/types/LogRecord.ts | 5 +++++ .../packages/exporter-logs-otlp-grpc/test/logsHelper.ts | 3 ++- experimental/packages/otlp-transformer/src/logs/index.ts | 2 +- experimental/packages/otlp-transformer/test/logs.test.ts | 4 +++- experimental/packages/sdk-logs/src/LogRecord.ts | 9 +++++++-- .../packages/sdk-logs/src/export/ReadableLogRecord.ts | 1 + 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 23bce4b247c..86f868f6f54 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -35,6 +35,7 @@ All notable changes to experimental packages in this project will be documented * feat(exporter-logs-otlp-grpc): otlp-grpc exporter for logs. [#3712](https://github.com/open-telemetry/opentelemetry-js/pull/3712/) @llc1123 * feat(otlp-grpc-exporter-base): use statically generated protobuf code [#3705](https://github.com/open-telemetry/opentelemetry-js/pull/3705) @pichlermarc * refactor(otlp-transformer): refine metric transformers. [#3770](https://github.com/open-telemetry/opentelemetry-js/pull/3770/) @llc1123 +* feat(api-logs): add `ObservedTimestamp` to `LogRecord`. [#3787](https://github.com/open-telemetry/opentelemetry-js/pull/3787/) @llc1123 ### :bug: (Bug Fix) diff --git a/experimental/packages/api-logs/src/types/LogRecord.ts b/experimental/packages/api-logs/src/types/LogRecord.ts index a2c7d25ad3d..e1c1100c5ff 100644 --- a/experimental/packages/api-logs/src/types/LogRecord.ts +++ b/experimental/packages/api-logs/src/types/LogRecord.ts @@ -50,6 +50,11 @@ export interface LogRecord { */ timestamp?: number; + /** + * Time when the event was observed by the collection system. + */ + observedTimestamp?: number; + /** * Numerical value of the severity. */ diff --git a/experimental/packages/exporter-logs-otlp-grpc/test/logsHelper.ts b/experimental/packages/exporter-logs-otlp-grpc/test/logsHelper.ts index b57b2682bdc..1dfd82675ad 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/test/logsHelper.ts +++ b/experimental/packages/exporter-logs-otlp-grpc/test/logsHelper.ts @@ -45,6 +45,7 @@ export const mockedReadableLogRecord: ReadableLogRecord = { schemaUrl: 'http://url.to.schema', }, hrTime: [1680253513, 123241635] as HrTime, + hrTimeObserved: [1683526948, 965142784] as HrTime, attributes: { 'some-attribute': 'some attribute value', }, @@ -92,7 +93,7 @@ export function ensureExportedLogRecordIsCorrect(logRecord: ILogRecord) { ); assert.strictEqual( logRecord.observedTimeUnixNano, - '1680253513123241728', + '1683526948965142784', 'observedTimeUnixNano is wrong' ); assert.strictEqual( diff --git a/experimental/packages/otlp-transformer/src/logs/index.ts b/experimental/packages/otlp-transformer/src/logs/index.ts index 4fd114fa694..6fa4d11e866 100644 --- a/experimental/packages/otlp-transformer/src/logs/index.ts +++ b/experimental/packages/otlp-transformer/src/logs/index.ts @@ -93,7 +93,7 @@ function logRecordsToResourceLogs( function toLogRecord(log: ReadableLogRecord, useHex?: boolean): ILogRecord { return { timeUnixNano: hrTimeToNanoseconds(log.hrTime), - observedTimeUnixNano: hrTimeToNanoseconds(log.hrTime), + observedTimeUnixNano: hrTimeToNanoseconds(log.hrTimeObserved), severityNumber: toSeverityNumber(log.severityNumber), severityText: log.severityText, body: toAnyValue(log.body), diff --git a/experimental/packages/otlp-transformer/test/logs.test.ts b/experimental/packages/otlp-transformer/test/logs.test.ts index c184134ce4c..ef0a4cf9d76 100644 --- a/experimental/packages/otlp-transformer/test/logs.test.ts +++ b/experimental/packages/otlp-transformer/test/logs.test.ts @@ -52,7 +52,7 @@ function createExpectedLogJson(useHex: boolean): IExportLogsServiceRequest { // eslint-disable-next-line @typescript-eslint/no-loss-of-precision timeUnixNano: 1680253513123241635, // eslint-disable-next-line @typescript-eslint/no-loss-of-precision - observedTimeUnixNano: 1680253513123241635, + observedTimeUnixNano: 1683526948965142784, severityNumber: ESeverityNumber.SEVERITY_NUMBER_ERROR, severityText: 'error', body: { stringValue: 'some_log_body' }, @@ -105,6 +105,7 @@ describe('Logs', () => { }; const log_fragment_1 = { hrTime: [1680253513, 123241635] as HrTime, + hrTimeObserved: [1683526948, 965142784] as HrTime, attributes: { 'some-attribute': 'some attribute value', }, @@ -119,6 +120,7 @@ describe('Logs', () => { }; const log_fragment_2 = { hrTime: [1680253797, 687038506] as HrTime, + hrTimeObserved: [1680253797, 687038506] as HrTime, attributes: { 'another-attribute': 'another attribute value', }, diff --git a/experimental/packages/sdk-logs/src/LogRecord.ts b/experimental/packages/sdk-logs/src/LogRecord.ts index a4601af6fcf..9d3e909feb0 100644 --- a/experimental/packages/sdk-logs/src/LogRecord.ts +++ b/experimental/packages/sdk-logs/src/LogRecord.ts @@ -30,6 +30,7 @@ import { Logger } from './Logger'; export class LogRecord implements ReadableLogRecord { readonly hrTime: api.HrTime; + readonly hrTimeObserved: api.HrTime; readonly spanContext?: api.SpanContext; readonly resource: IResource; readonly instrumentationScope: InstrumentationScope; @@ -73,7 +74,8 @@ export class LogRecord implements ReadableLogRecord { constructor(logger: Logger, logRecord: logsAPI.LogRecord) { const { - timestamp = Date.now(), + timestamp, + observedTimestamp, severityNumber, severityText, body, @@ -81,7 +83,10 @@ export class LogRecord implements ReadableLogRecord { context, } = logRecord; - this.hrTime = timeInputToHrTime(timestamp); + const now = Date.now(); + this.hrTime = timeInputToHrTime(timestamp ?? now); + this.hrTimeObserved = timeInputToHrTime(observedTimestamp ?? now); + if (context) { const spanContext = api.trace.getSpanContext(context); if (spanContext && api.isSpanContextValid(spanContext)) { diff --git a/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts b/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts index e02d53dae9c..72fe7d1d358 100644 --- a/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts +++ b/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts @@ -21,6 +21,7 @@ import type { SeverityNumber } from '@opentelemetry/api-logs'; export interface ReadableLogRecord { readonly hrTime: HrTime; + readonly hrTimeObserved: HrTime; readonly spanContext?: SpanContext; readonly severityText?: string; readonly severityNumber?: SeverityNumber; From 0471c54a4ca2119c77c04c860de1705f137d2815 Mon Sep 17 00:00:00 2001 From: fuaiyi Date: Mon, 22 May 2023 16:48:37 +0800 Subject: [PATCH 10/14] =?UTF-8?q?fix(exporter-logs-otlp-grpc):=20change=20?= =?UTF-8?q?OTLPLogsExporter=20to=20OTLPLogExpo=E2=80=A6=20(#3819)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- experimental/CHANGELOG.md | 2 ++ .../exporter-logs-otlp-grpc/README.md | 6 ++-- ...OTLPLogsExporter.ts => OTLPLogExporter.ts} | 2 +- .../exporter-logs-otlp-grpc/src/index.ts | 2 +- ...porter.test.ts => OTLPLogExporter.test.ts} | 36 +++++++++---------- 5 files changed, 25 insertions(+), 23 deletions(-) rename experimental/packages/exporter-logs-otlp-grpc/src/{OTLPLogsExporter.ts => OTLPLogExporter.ts} (98%) rename experimental/packages/exporter-logs-otlp-grpc/test/{OTLPLogsExporter.test.ts => OTLPLogExporter.test.ts} (92%) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 86f868f6f54..1a5a6595cb7 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to experimental packages in this project will be documented ### :boom: Breaking Change +* fix(exporter-logs-otlp-grpc): change OTLPLogsExporter to OTLPLogExporter [#3819](https://github.com/open-telemetry/opentelemetry-js/pull/3819) @fuaiyi + ### :rocket: (Enhancement) * feat(instrumentation): add ESM support for instrumentation. [#3698](https://github.com/open-telemetry/opentelemetry-js/pull/3698) @JamieDanielson, @pkanal, @vmarchaud, @lizthegrey, @bengl diff --git a/experimental/packages/exporter-logs-otlp-grpc/README.md b/experimental/packages/exporter-logs-otlp-grpc/README.md index dee62b496ff..17c95733988 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/README.md +++ b/experimental/packages/exporter-logs-otlp-grpc/README.md @@ -22,7 +22,7 @@ To see documentation and sample code for the metric exporter, see the [exporter- ## Logs in Node - GRPC -The OTLPLogsExporter in Node expects the URL to only be the hostname. It will not work with `/v1/logs`. All +The OTLPLogExporter in Node expects the URL to only be the hostname. It will not work with `/v1/logs`. All options that work with trace also work with logs. ```js @@ -30,14 +30,14 @@ import { LoggerProvider, BatchLogRecordProcessor, } from '@opentelemetry/sdk-logs'; -import { OTLPLogsExporter } from '@opentelemetry/exporter-logs-otlp-grpc'; +import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-grpc'; const collectorOptions = { // url is optional and can be omitted - default is http://localhost:4317 url: 'http://:', }; -const loggerExporter = new OTLPLogsExporter(collectorOptions); +const loggerExporter = new OTLPLogExporter(collectorOptions); const loggerProvider = new LoggerProvider(); loggerProvider.addLogRecordProcessor( diff --git a/experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogsExporter.ts b/experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogExporter.ts similarity index 98% rename from experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogsExporter.ts rename to experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogExporter.ts index e4484fdb396..675ce83db0a 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogsExporter.ts +++ b/experimental/packages/exporter-logs-otlp-grpc/src/OTLPLogExporter.ts @@ -32,7 +32,7 @@ import { /** * OTLP Logs Exporter for Node */ -export class OTLPLogsExporter +export class OTLPLogExporter extends OTLPGRPCExporterNodeBase implements LogRecordExporter { diff --git a/experimental/packages/exporter-logs-otlp-grpc/src/index.ts b/experimental/packages/exporter-logs-otlp-grpc/src/index.ts index b35d852d902..b071c78ef5b 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/src/index.ts +++ b/experimental/packages/exporter-logs-otlp-grpc/src/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export * from './OTLPLogsExporter'; +export * from './OTLPLogExporter'; diff --git a/experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogsExporter.test.ts b/experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogExporter.test.ts similarity index 92% rename from experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogsExporter.test.ts rename to experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogExporter.test.ts index d413b8902d4..c229d5e5ddd 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogsExporter.test.ts +++ b/experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogExporter.test.ts @@ -22,7 +22,7 @@ import * as fs from 'fs'; import * as grpc from '@grpc/grpc-js'; import * as path from 'path'; import * as sinon from 'sinon'; -import { OTLPLogsExporter } from '../src'; +import { OTLPLogExporter } from '../src'; import { ensureExportedLogRecordIsCorrect, @@ -55,10 +55,10 @@ const metadata = new grpc.Metadata(); metadata.set('k', 'v'); const testCollectorExporter = (params: TestParams) => - describe(`OTLPLogsExporter - node ${ - params.useTLS ? 'with' : 'without' - } TLS, ${params.metadata ? 'with' : 'without'} metadata`, () => { - let collectorExporter: OTLPLogsExporter; + describe(`OTLPLogExporter - node ${params.useTLS ? 'with' : 'without'} TLS, ${ + params.metadata ? 'with' : 'without' + } metadata`, () => { + let collectorExporter: OTLPLogExporter; let server: grpc.Server; let exportedData: IResourceLogs | undefined; let reqMetadata: grpc.Metadata | undefined; @@ -122,7 +122,7 @@ const testCollectorExporter = (params: TestParams) => fs.readFileSync('./test/certs/client.crt') ) : grpc.credentials.createInsecure(); - collectorExporter = new OTLPLogsExporter({ + collectorExporter = new OTLPLogExporter({ url: 'https://' + address, credentials, metadata: params.metadata, @@ -140,7 +140,7 @@ const testCollectorExporter = (params: TestParams) => it('should warn about headers when using grpc', () => { // Need to stub/spy on the underlying logger as the 'diag' instance is global const spyLoggerWarn = sinon.stub(diag, 'warn'); - collectorExporter = new OTLPLogsExporter({ + collectorExporter = new OTLPLogExporter({ url: `http://${address}`, headers: { foo: 'bar', @@ -151,7 +151,7 @@ const testCollectorExporter = (params: TestParams) => }); it('should warn about path in url', () => { const spyLoggerWarn = sinon.stub(diag, 'warn'); - collectorExporter = new OTLPLogsExporter({ + collectorExporter = new OTLPLogExporter({ url: `http://${address}/v1/logs`, }); const args = spyLoggerWarn.args[0]; @@ -198,7 +198,7 @@ const testCollectorExporter = (params: TestParams) => ) : grpc.credentials.createInsecure(); - const collectorExporterWithTimeout = new OTLPLogsExporter({ + const collectorExporterWithTimeout = new OTLPLogExporter({ url: 'grpcs://' + address, credentials, metadata: params.metadata, @@ -229,7 +229,7 @@ const testCollectorExporter = (params: TestParams) => fs.readFileSync('./test/certs/client.crt') ) : grpc.credentials.createInsecure(); - collectorExporter = new OTLPLogsExporter({ + collectorExporter = new OTLPLogExporter({ url: 'https://' + address, credentials, metadata: params.metadata, @@ -272,7 +272,7 @@ const testCollectorExporter = (params: TestParams) => : grpc.credentials.createInsecure(); envSource.OTEL_EXPORTER_OTLP_COMPRESSION = 'gzip'; - collectorExporter = new OTLPLogsExporter({ + collectorExporter = new OTLPLogExporter({ url: 'https://' + address, credentials, metadata: params.metadata, @@ -286,9 +286,9 @@ const testCollectorExporter = (params: TestParams) => }); }); -describe('OTLPLogsExporter - node (getDefaultUrl)', () => { +describe('OTLPLogExporter - node (getDefaultUrl)', () => { it('should default to localhost', done => { - const collectorExporter = new OTLPLogsExporter({}); + const collectorExporter = new OTLPLogExporter({}); setTimeout(() => { assert.strictEqual(collectorExporter['url'], 'localhost:4317'); done(); @@ -296,7 +296,7 @@ describe('OTLPLogsExporter - node (getDefaultUrl)', () => { }); it('should keep the URL if included', done => { const url = 'http://foo.bar.com'; - const collectorExporter = new OTLPLogsExporter({ url }); + const collectorExporter = new OTLPLogExporter({ url }); setTimeout(() => { assert.strictEqual(collectorExporter['url'], 'foo.bar.com'); done(); @@ -308,21 +308,21 @@ describe('when configuring via environment', () => { const envSource = process.env; it('should use url defined in env', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual(collectorExporter.url, 'foo.bar'); envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; }); it('should override global exporter url with signal url defined in env', () => { envSource.OTEL_EXPORTER_OTLP_ENDPOINT = 'http://foo.bar'; envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = 'http://foo.logs'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.strictEqual(collectorExporter.url, 'foo.logs'); envSource.OTEL_EXPORTER_OTLP_ENDPOINT = ''; envSource.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = ''; }); it('should use headers defined via env', () => { envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=bar'; - const collectorExporter = new OTLPLogsExporter(); + const collectorExporter = new OTLPLogExporter(); assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['bar']); envSource.OTEL_EXPORTER_OTLP_HEADERS = ''; }); @@ -332,7 +332,7 @@ describe('when configuring via environment', () => { metadata.set('goo', 'lol'); envSource.OTEL_EXPORTER_OTLP_HEADERS = 'foo=jar,bar=foo'; envSource.OTEL_EXPORTER_OTLP_LOGS_HEADERS = 'foo=boo'; - const collectorExporter = new OTLPLogsExporter({ metadata }); + const collectorExporter = new OTLPLogExporter({ metadata }); assert.deepStrictEqual(collectorExporter.metadata?.get('foo'), ['boo']); assert.deepStrictEqual(collectorExporter.metadata?.get('bar'), ['foo']); assert.deepStrictEqual(collectorExporter.metadata?.get('goo'), ['lol']); From 58dbbb4b893a43912e696dc32164ea53f59e58eb Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 23 May 2023 02:42:16 -0700 Subject: [PATCH 11/14] [sdk-logs] remove includeTraceContext configuration and use LogRecord context when available (#3817) Co-authored-by: Daniel Dyla --- experimental/CHANGELOG.md | 1 + experimental/packages/sdk-logs/src/Logger.ts | 4 +-- .../packages/sdk-logs/src/LoggerProvider.ts | 1 - experimental/packages/sdk-logs/src/index.ts | 1 + experimental/packages/sdk-logs/src/types.ts | 3 -- .../sdk-logs/test/common/Logger.test.ts | 36 +++++++++---------- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 1a5a6595cb7..4ef6fff6190 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -17,6 +17,7 @@ All notable changes to experimental packages in this project will be documented ### :bug: (Bug Fix) * fix(sdk-node): use resource interface instead of concrete class [#3803](https://github.com/open-telemetry/opentelemetry-js/pull/3803) @blumamir +* fix(sdk-logs): remove includeTraceContext configuration and use LogRecord context when available [#3817](https://github.com/open-telemetry/opentelemetry-js/pull/3817) @hectorhdzg ### :books: (Refine Doc) diff --git a/experimental/packages/sdk-logs/src/Logger.ts b/experimental/packages/sdk-logs/src/Logger.ts index 0e6cfbe2d95..5ea4e8f28ff 100644 --- a/experimental/packages/sdk-logs/src/Logger.ts +++ b/experimental/packages/sdk-logs/src/Logger.ts @@ -39,9 +39,7 @@ export class Logger implements logsAPI.Logger { } public emit(logRecord: logsAPI.LogRecord): void { - const currentContext = this._loggerConfig.includeTraceContext - ? context.active() - : undefined; + const currentContext = logRecord.context || context.active(); /** * If a Logger was obtained with include_trace_context=true, * the LogRecords it emits MUST automatically include the Trace Context from the active Context, diff --git a/experimental/packages/sdk-logs/src/LoggerProvider.ts b/experimental/packages/sdk-logs/src/LoggerProvider.ts index a51438408a1..81515dab86b 100644 --- a/experimental/packages/sdk-logs/src/LoggerProvider.ts +++ b/experimental/packages/sdk-logs/src/LoggerProvider.ts @@ -84,7 +84,6 @@ export class LoggerProvider implements logsAPI.LoggerProvider { { name: loggerName, version, schemaUrl: options?.schemaUrl }, { logRecordLimits: this._config.logRecordLimits, - includeTraceContext: options?.includeTraceContext, }, this ) diff --git a/experimental/packages/sdk-logs/src/index.ts b/experimental/packages/sdk-logs/src/index.ts index 60124da1f0c..e718ae069e9 100644 --- a/experimental/packages/sdk-logs/src/index.ts +++ b/experimental/packages/sdk-logs/src/index.ts @@ -16,6 +16,7 @@ export { LoggerConfig, + LoggerProviderConfig, LogRecordLimits, BufferConfig, BatchLogRecordProcessorBrowserConfig, diff --git a/experimental/packages/sdk-logs/src/types.ts b/experimental/packages/sdk-logs/src/types.ts index 5bdad2a1e0a..026843dc155 100644 --- a/experimental/packages/sdk-logs/src/types.ts +++ b/experimental/packages/sdk-logs/src/types.ts @@ -33,9 +33,6 @@ export interface LoggerProviderConfig { export interface LoggerConfig { /** Log Record Limits*/ logRecordLimits?: LogRecordLimits; - - /** include Trace Context */ - includeTraceContext?: boolean; } export interface LogRecordLimits { diff --git a/experimental/packages/sdk-logs/test/common/Logger.test.ts b/experimental/packages/sdk-logs/test/common/Logger.test.ts index 5df756c9017..a5f690a4b7e 100644 --- a/experimental/packages/sdk-logs/test/common/Logger.test.ts +++ b/experimental/packages/sdk-logs/test/common/Logger.test.ts @@ -18,8 +18,8 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import { LogRecord, Logger, LoggerConfig, LoggerProvider } from '../../src'; -import { loadDefaultConfig } from '../../src/config'; -import { context } from '@opentelemetry/api'; +import { ROOT_CONTEXT, TraceFlags, context, trace } from '@opentelemetry/api'; +import { LogRecord as ApiLogRecord } from '@opentelemetry/api-logs'; const setup = (loggerConfig: LoggerConfig = {}) => { const logger = new Logger( @@ -40,14 +40,6 @@ describe('Logger', () => { const { logger } = setup(); assert.ok(logger instanceof Logger); }); - - it('should a default value with config.includeTraceContext', () => { - const { logger } = setup(); - assert.ok( - logger['_loggerConfig'].includeTraceContext === - loadDefaultConfig().includeTraceContext - ); - }); }); describe('emit', () => { @@ -69,8 +61,8 @@ describe('Logger', () => { assert.ok(makeOnlySpy.called); }); - it('should emit with current Context when includeTraceContext is true', () => { - const { logger } = setup({ includeTraceContext: true }); + it('should emit with current Context', () => { + const { logger } = setup({}); const callSpy = sinon.spy(logger.getActiveLogRecordProcessor(), 'onEmit'); logger.emit({ body: 'test log body', @@ -78,13 +70,21 @@ describe('Logger', () => { assert.ok(callSpy.calledWith(sinon.match.any, context.active())); }); - it('should emit with empty Context when includeTraceContext is false', () => { - const { logger } = setup({ includeTraceContext: false }); + it('should emit with Context specified in LogRecord', () => { + const { logger } = setup({}); + const spanContext = { + traceId: 'd4cda95b652f4a1592b449d5929fda1b', + spanId: '6e0c63257de34c92', + traceFlags: TraceFlags.SAMPLED, + }; + const activeContext = trace.setSpanContext(ROOT_CONTEXT, spanContext); + const logRecordData: ApiLogRecord = { + context: activeContext, + }; + const callSpy = sinon.spy(logger.getActiveLogRecordProcessor(), 'onEmit'); - logger.emit({ - body: 'test log body', - }); - assert.ok(callSpy.calledWith(sinon.match.any, undefined)); + logger.emit(logRecordData); + assert.ok(callSpy.calledWith(sinon.match.any, activeContext)); }); }); }); From 5fb44c044771cffdfbf82a719324c7839c36e711 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Wed, 24 May 2023 12:21:22 -0400 Subject: [PATCH 12/14] Add Jamie to approvers (#3830) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9daf9d73858..5187030f934 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,7 @@ We have a weekly SIG meeting! See the [community page](https://github.com/open-t - [Gerhard Stöbich](https://github.com/Flarna), Dynatrace - [Haddas Bronfman](https://github.com/haddasbronfman), Cisco +- [Jamie Danielson](https://github.com/JamieDanielson), Honeycomb - [John Bley](https://github.com/johnbley), Splunk - [Mark Wolff](https://github.com/markwolff), Microsoft - [Martin Kuba](https://github.com/martinkuba), Lightstep From a6635428a9b20e49694bcc8fab787acbbd66979a Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Wed, 24 May 2023 12:22:02 -0400 Subject: [PATCH 13/14] Add Hector to approvers (#3831) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5187030f934..d22874b9a0e 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,7 @@ We have a weekly SIG meeting! See the [community page](https://github.com/open-t - [Gerhard Stöbich](https://github.com/Flarna), Dynatrace - [Haddas Bronfman](https://github.com/haddasbronfman), Cisco +- [Hector Hernandez](https://github.com/hectorhdzg), Microsoft - [Jamie Danielson](https://github.com/JamieDanielson), Honeycomb - [John Bley](https://github.com/johnbley), Splunk - [Mark Wolff](https://github.com/markwolff), Microsoft From c6635fa4960407396aa87cdae41c9aa2075e2981 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Wed, 24 May 2023 12:22:28 -0400 Subject: [PATCH 14/14] Add Purvi to approvers (#3832) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d22874b9a0e..ca727967475 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,7 @@ We have a weekly SIG meeting! See the [community page](https://github.com/open-t - [Naseem K. Ullah](https://github.com/naseemkullah), Transit - [Neville Wylie](https://github.com/MSNev), Microsoft - [Olivier Albertini](https://github.com/OlivierAlbertini), Ville de Montréal +- [Purvi Kanal](https://github.com/pkanal), Honeycomb - [Svetlana Brennan](https://github.com/svetlanabrennan), New Relic *Find more about the approver role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver).*