From 18b8644b36a9c805bf1f2a160aef8e2786be2a06 Mon Sep 17 00:00:00 2001 From: davidwitten Date: Mon, 29 Jun 2020 18:55:24 +0000 Subject: [PATCH 1/3] Renamed --- .../{CollectorExporterBase.ts => CollectorTraceExporterBase.ts} | 0 .../browser/{CollectorExporter.ts => CollectorTraceExporter.ts} | 2 +- .../src/platform/browser/index.ts | 2 +- .../node/{CollectorExporter.ts => CollectorTraceExporter.ts} | 2 +- .../opentelemetry-exporter-collector/src/platform/node/index.ts | 2 +- .../opentelemetry-exporter-collector/src/platform/node/protos | 2 +- packages/opentelemetry-exporter-collector/src/transform.ts | 2 +- ...CollectorExporter.test.ts => CollectorTraceExporter.test.ts} | 0 ...CollectorExporter.test.ts => CollectorTraceExporter.test.ts} | 2 +- ...CollectorExporter.test.ts => CollectorTraceExporter.test.ts} | 0 10 files changed, 7 insertions(+), 7 deletions(-) rename packages/opentelemetry-exporter-collector/src/{CollectorExporterBase.ts => CollectorTraceExporterBase.ts} (100%) rename packages/opentelemetry-exporter-collector/src/platform/browser/{CollectorExporter.ts => CollectorTraceExporter.ts} (98%) rename packages/opentelemetry-exporter-collector/src/platform/node/{CollectorExporter.ts => CollectorTraceExporter.ts} (98%) rename packages/opentelemetry-exporter-collector/test/browser/{CollectorExporter.test.ts => CollectorTraceExporter.test.ts} (100%) rename packages/opentelemetry-exporter-collector/test/common/{CollectorExporter.test.ts => CollectorTraceExporter.test.ts} (99%) rename packages/opentelemetry-exporter-collector/test/node/{CollectorExporter.test.ts => CollectorTraceExporter.test.ts} (100%) diff --git a/packages/opentelemetry-exporter-collector/src/CollectorExporterBase.ts b/packages/opentelemetry-exporter-collector/src/CollectorTraceExporterBase.ts similarity index 100% rename from packages/opentelemetry-exporter-collector/src/CollectorExporterBase.ts rename to packages/opentelemetry-exporter-collector/src/CollectorTraceExporterBase.ts diff --git a/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorExporter.ts b/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts similarity index 98% rename from packages/opentelemetry-exporter-collector/src/platform/browser/CollectorExporter.ts rename to packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts index 5e7f121ac6..b9afe7777b 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorExporter.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts @@ -17,7 +17,7 @@ import { CollectorExporterBase, CollectorExporterConfigBase, -} from '../../CollectorExporterBase'; +} from '../../CollectorTraceExporterBase'; import { ReadableSpan } from '@opentelemetry/tracing'; import { toCollectorExportTraceServiceRequest } from '../../transform'; import * as collectorTypes from '../../types'; diff --git a/packages/opentelemetry-exporter-collector/src/platform/browser/index.ts b/packages/opentelemetry-exporter-collector/src/platform/browser/index.ts index f38bc0489f..1c17973de2 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/browser/index.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/browser/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export * from './CollectorExporter'; +export * from './CollectorTraceExporter'; diff --git a/packages/opentelemetry-exporter-collector/src/platform/node/CollectorExporter.ts b/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts similarity index 98% rename from packages/opentelemetry-exporter-collector/src/platform/node/CollectorExporter.ts rename to packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts index e5c767ecf3..c440c06105 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/node/CollectorExporter.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts @@ -23,7 +23,7 @@ import { ReadableSpan } from '@opentelemetry/tracing'; import { CollectorExporterBase, CollectorExporterConfigBase, -} from '../../CollectorExporterBase'; +} from '../../CollectorTraceExporterBase'; import { CollectorExporterError } from '../../types'; import { toCollectorExportTraceServiceRequest } from '../../transform'; import { GRPCQueueItem, TraceServiceClient } from './types'; diff --git a/packages/opentelemetry-exporter-collector/src/platform/node/index.ts b/packages/opentelemetry-exporter-collector/src/platform/node/index.ts index f38bc0489f..1c17973de2 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/node/index.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/node/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export * from './CollectorExporter'; +export * from './CollectorTraceExporter'; diff --git a/packages/opentelemetry-exporter-collector/src/platform/node/protos b/packages/opentelemetry-exporter-collector/src/platform/node/protos index e6c3c4a74d..b546885691 160000 --- a/packages/opentelemetry-exporter-collector/src/platform/node/protos +++ b/packages/opentelemetry-exporter-collector/src/platform/node/protos @@ -1 +1 @@ -Subproject commit e6c3c4a74d57f870a0d781bada02cb2b2c497d14 +Subproject commit b54688569186e0b862bf7462a983ccf2c50c0547 diff --git a/packages/opentelemetry-exporter-collector/src/transform.ts b/packages/opentelemetry-exporter-collector/src/transform.ts index 09af80dbf0..2eb0ffe8fb 100644 --- a/packages/opentelemetry-exporter-collector/src/transform.ts +++ b/packages/opentelemetry-exporter-collector/src/transform.ts @@ -27,7 +27,7 @@ import { ReadableSpan } from '@opentelemetry/tracing'; import { CollectorExporterBase, CollectorExporterConfigBase, -} from './CollectorExporterBase'; +} from './CollectorTraceExporterBase'; import { COLLECTOR_SPAN_KIND_MAPPING, opentelemetryProto } from './types'; import ValueType = opentelemetryProto.common.v1.ValueType; import { InstrumentationLibrary } from '@opentelemetry/core'; diff --git a/packages/opentelemetry-exporter-collector/test/browser/CollectorExporter.test.ts b/packages/opentelemetry-exporter-collector/test/browser/CollectorTraceExporter.test.ts similarity index 100% rename from packages/opentelemetry-exporter-collector/test/browser/CollectorExporter.test.ts rename to packages/opentelemetry-exporter-collector/test/browser/CollectorTraceExporter.test.ts diff --git a/packages/opentelemetry-exporter-collector/test/common/CollectorExporter.test.ts b/packages/opentelemetry-exporter-collector/test/common/CollectorTraceExporter.test.ts similarity index 99% rename from packages/opentelemetry-exporter-collector/test/common/CollectorExporter.test.ts rename to packages/opentelemetry-exporter-collector/test/common/CollectorTraceExporter.test.ts index e5d67d67db..7bd74fc2e2 100644 --- a/packages/opentelemetry-exporter-collector/test/common/CollectorExporter.test.ts +++ b/packages/opentelemetry-exporter-collector/test/common/CollectorTraceExporter.test.ts @@ -21,7 +21,7 @@ import * as sinon from 'sinon'; import { CollectorExporterBase, CollectorExporterConfigBase, -} from '../../src/CollectorExporterBase'; +} from '../../src/CollectorTraceExporterBase'; import { mockedReadableSpan } from '../helper'; diff --git a/packages/opentelemetry-exporter-collector/test/node/CollectorExporter.test.ts b/packages/opentelemetry-exporter-collector/test/node/CollectorTraceExporter.test.ts similarity index 100% rename from packages/opentelemetry-exporter-collector/test/node/CollectorExporter.test.ts rename to packages/opentelemetry-exporter-collector/test/node/CollectorTraceExporter.test.ts From b5bd5ca64c9f1a36f9c5f79797e3f576de3f0137 Mon Sep 17 00:00:00 2001 From: davidwitten Date: Mon, 29 Jun 2020 19:10:07 +0000 Subject: [PATCH 2/3] Completed renaming --- .../src/CollectorTraceExporterBase.ts | 21 ++--- .../browser/CollectorTraceExporter.ts | 19 ++--- .../platform/node/CollectorTraceExporter.ts | 35 ++++---- .../src/platform/node/types.ts | 6 +- .../src/transform.ts | 9 +- .../src/types.ts | 31 ++++++- .../browser/CollectorTraceExporter.test.ts | 82 ++++++++++++------- .../common/CollectorTraceExporter.test.ts | 30 +++---- .../test/node/CollectorTraceExporter.test.ts | 10 +-- 9 files changed, 139 insertions(+), 104 deletions(-) diff --git a/packages/opentelemetry-exporter-collector/src/CollectorTraceExporterBase.ts b/packages/opentelemetry-exporter-collector/src/CollectorTraceExporterBase.ts index 0e6e052e9d..93ab2330db 100644 --- a/packages/opentelemetry-exporter-collector/src/CollectorTraceExporterBase.ts +++ b/packages/opentelemetry-exporter-collector/src/CollectorTraceExporterBase.ts @@ -17,25 +17,18 @@ import { Attributes, Logger } from '@opentelemetry/api'; import { ExportResult, NoopLogger } from '@opentelemetry/core'; import { ReadableSpan, SpanExporter } from '@opentelemetry/tracing'; -import { opentelemetryProto, CollectorExporterError } from './types'; - -/** - * Collector Exporter base config - */ -export interface CollectorExporterConfigBase { - hostName?: string; - logger?: Logger; - serviceName?: string; - attributes?: Attributes; - url?: string; -} +import { + opentelemetryProto, + CollectorExporterError, + CollectorExporterConfigBase, +} from './types'; const DEFAULT_SERVICE_NAME = 'collector-exporter'; /** - * Collector Exporter abstract base class + * Collector Trace Exporter abstract base class */ -export abstract class CollectorExporterBase< +export abstract class CollectorTraceExporterBase< T extends CollectorExporterConfigBase > implements SpanExporter { public readonly serviceName: string; diff --git a/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts b/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts index b9afe7777b..2d0a337f2b 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/browser/CollectorTraceExporter.ts @@ -14,28 +14,19 @@ * limitations under the License. */ -import { - CollectorExporterBase, - CollectorExporterConfigBase, -} from '../../CollectorTraceExporterBase'; +import { CollectorTraceExporterBase } from '../../CollectorTraceExporterBase'; import { ReadableSpan } from '@opentelemetry/tracing'; import { toCollectorExportTraceServiceRequest } from '../../transform'; +import { CollectorExporterConfigBrowser } from '../../types'; import * as collectorTypes from '../../types'; -/** - * Collector Exporter Config for Web - */ -export interface CollectorExporterConfig extends CollectorExporterConfigBase { - headers?: { [key: string]: string }; -} - const DEFAULT_COLLECTOR_URL = 'http://localhost:55678/v1/trace'; /** * Collector Exporter for Web */ -export class CollectorExporter extends CollectorExporterBase< - CollectorExporterConfig +export class CollectorTraceExporter extends CollectorTraceExporterBase< + CollectorExporterConfigBrowser > { DEFAULT_HEADERS: { [key: string]: string } = { [collectorTypes.OT_REQUEST_HEADER]: '1', @@ -46,7 +37,7 @@ export class CollectorExporter extends CollectorExporterBase< /** * @param config */ - constructor(config: CollectorExporterConfig = {}) { + constructor(config: CollectorExporterConfigBrowser = {}) { super(config); this._headers = config.headers || this.DEFAULT_HEADERS; this._useXHR = diff --git a/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts b/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts index c440c06105..8659a97b71 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/node/CollectorTraceExporter.ts @@ -20,40 +20,32 @@ import * as path from 'path'; import * as collectorTypes from '../../types'; import { ReadableSpan } from '@opentelemetry/tracing'; +import { CollectorTraceExporterBase } from '../../CollectorTraceExporterBase'; import { - CollectorExporterBase, - CollectorExporterConfigBase, -} from '../../CollectorTraceExporterBase'; -import { CollectorExporterError } from '../../types'; + CollectorExporterError, + CollectorExporterConfigNode, +} from '../../types'; import { toCollectorExportTraceServiceRequest } from '../../transform'; -import { GRPCQueueItem, TraceServiceClient } from './types'; +import { GRPCSpanQueueItem, ServiceClient } from './types'; import { removeProtocol } from './util'; const DEFAULT_COLLECTOR_URL = 'localhost:55678'; /** - * Collector Exporter Config for Node + * Collector Trace Exporter for Node */ -export interface CollectorExporterConfig extends CollectorExporterConfigBase { - credentials?: grpc.ChannelCredentials; - metadata?: grpc.Metadata; -} - -/** - * Collector Exporter for Node - */ -export class CollectorExporter extends CollectorExporterBase< - CollectorExporterConfig +export class CollectorTraceExporter extends CollectorTraceExporterBase< + CollectorExporterConfigNode > { isShutDown: boolean = false; - traceServiceClient?: TraceServiceClient = undefined; - grpcSpansQueue: GRPCQueueItem[] = []; + traceServiceClient?: ServiceClient = undefined; + grpcSpansQueue: GRPCSpanQueueItem[] = []; metadata?: grpc.Metadata; /** * @param config */ - constructor(config: CollectorExporterConfig = {}) { + constructor(config: CollectorExporterConfigNode = {}) { super(config); this.metadata = config.metadata; } @@ -65,7 +57,7 @@ export class CollectorExporter extends CollectorExporterBase< } } - onInit(config: CollectorExporterConfig): void { + onInit(config: CollectorExporterConfigNode): void { this.isShutDown = false; this.grpcSpansQueue = []; const serverAddress = removeProtocol(this.url); @@ -95,7 +87,7 @@ export class CollectorExporter extends CollectorExporterBase< ); if (this.grpcSpansQueue.length > 0) { const queue = this.grpcSpansQueue.splice(0); - queue.forEach((item: GRPCQueueItem) => { + queue.forEach((item: GRPCSpanQueueItem) => { this.sendSpans(item.spans, item.onSuccess, item.onError); }); } @@ -108,6 +100,7 @@ export class CollectorExporter extends CollectorExporterBase< onError: (error: CollectorExporterError) => void ): void { if (this.isShutDown) { + this.logger.debug('Shutdown already started. Cannot send spans'); return; } if (this.traceServiceClient) { diff --git a/packages/opentelemetry-exporter-collector/src/platform/node/types.ts b/packages/opentelemetry-exporter-collector/src/platform/node/types.ts index 4674fadf90..01b1a9a33f 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/node/types.ts +++ b/packages/opentelemetry-exporter-collector/src/platform/node/types.ts @@ -22,16 +22,16 @@ import { CollectorExporterError } from '../../types'; * Queue item to be used to save temporary spans in case the GRPC service * hasn't been fully initialised yet */ -export interface GRPCQueueItem { +export interface GRPCSpanQueueItem { spans: ReadableSpan[]; onSuccess: () => void; onError: (error: CollectorExporterError) => void; } /** - * Trace Service Client for sending spans + * Service Client for sending spans or metrics */ -export interface TraceServiceClient extends grpc.Client { +export interface ServiceClient extends grpc.Client { export: ( request: any, metadata: grpc.Metadata | undefined, diff --git a/packages/opentelemetry-exporter-collector/src/transform.ts b/packages/opentelemetry-exporter-collector/src/transform.ts index 2eb0ffe8fb..626169d077 100644 --- a/packages/opentelemetry-exporter-collector/src/transform.ts +++ b/packages/opentelemetry-exporter-collector/src/transform.ts @@ -24,11 +24,12 @@ import { import * as core from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import { ReadableSpan } from '@opentelemetry/tracing'; +import { CollectorTraceExporterBase } from './CollectorTraceExporterBase'; import { - CollectorExporterBase, + COLLECTOR_SPAN_KIND_MAPPING, + opentelemetryProto, CollectorExporterConfigBase, -} from './CollectorTraceExporterBase'; -import { COLLECTOR_SPAN_KIND_MAPPING, opentelemetryProto } from './types'; +} from './types'; import ValueType = opentelemetryProto.common.v1.ValueType; import { InstrumentationLibrary } from '@opentelemetry/core'; @@ -200,7 +201,7 @@ export function toCollectorExportTraceServiceRequest< T extends CollectorExporterConfigBase >( spans: ReadableSpan[], - collectorExporterBase: CollectorExporterBase, + collectorExporterBase: CollectorTraceExporterBase, name = '' ): opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest { const groupedSpans: Map< diff --git a/packages/opentelemetry-exporter-collector/src/types.ts b/packages/opentelemetry-exporter-collector/src/types.ts index ea10b0ca4b..aca9f6dfb3 100644 --- a/packages/opentelemetry-exporter-collector/src/types.ts +++ b/packages/opentelemetry-exporter-collector/src/types.ts @@ -14,8 +14,9 @@ * limitations under the License. */ -import { SpanKind } from '@opentelemetry/api'; +import { SpanKind, Logger, Attributes } from '@opentelemetry/api'; import * as api from '@opentelemetry/api'; +import * as grpc from 'grpc'; // header to prevent instrumentation on request export const OT_REQUEST_HEADER = 'x-opentelemetry-outgoing-request'; @@ -170,6 +171,34 @@ export interface CollectorExporterError { stack?: string; } +/** + * Collector Exporter base config + */ +export interface CollectorExporterConfigBase { + hostName?: string; + logger?: Logger; + serviceName?: string; + attributes?: Attributes; + url?: string; +} + +/** + * Collector Exporter Config for Web + */ +export interface CollectorExporterConfigBrowser + extends CollectorExporterConfigBase { + headers?: { [key: string]: string }; +} + +/** + * Collector Exporter Config for Node + */ +export interface CollectorExporterConfigNode + extends CollectorExporterConfigBase { + credentials?: grpc.ChannelCredentials; + metadata?: grpc.Metadata; +} + /** * Mapping between api SpanKind and proto SpanKind */ diff --git a/packages/opentelemetry-exporter-collector/test/browser/CollectorTraceExporter.test.ts b/packages/opentelemetry-exporter-collector/test/browser/CollectorTraceExporter.test.ts index 265bf44136..b5621a3ee5 100644 --- a/packages/opentelemetry-exporter-collector/test/browser/CollectorTraceExporter.test.ts +++ b/packages/opentelemetry-exporter-collector/test/browser/CollectorTraceExporter.test.ts @@ -18,10 +18,7 @@ import { NoopLogger } from '@opentelemetry/core'; import { ReadableSpan } from '@opentelemetry/tracing'; import * as assert from 'assert'; import * as sinon from 'sinon'; -import { - CollectorExporter, - CollectorExporterConfig, -} from '../../src/platform/browser/index'; +import { CollectorTraceExporter } from '../../src/platform/browser/index'; import * as collectorTypes from '../../src/types'; import { @@ -34,8 +31,8 @@ import { const sendBeacon = navigator.sendBeacon; describe('CollectorExporter - web', () => { - let collectorExporter: CollectorExporter; - let collectorExporterConfig: CollectorExporterConfig; + let collectorTraceExporter: CollectorTraceExporter; + let collectorExporterConfig: collectorTypes.CollectorExporterConfigBrowser; let spyOpen: any; let spySend: any; let spyBeacon: any; @@ -69,11 +66,13 @@ describe('CollectorExporter - web', () => { describe('when "sendBeacon" is available', () => { beforeEach(() => { - collectorExporter = new CollectorExporter(collectorExporterConfig); + collectorTraceExporter = new CollectorTraceExporter( + collectorExporterConfig + ); }); it('should successfully send the spans using sendBeacon', done => { - collectorExporter.export(spans, () => {}); + collectorTraceExporter.export(spans, () => {}); setTimeout(() => { const args = spyBeacon.args[0]; @@ -108,12 +107,18 @@ describe('CollectorExporter - web', () => { }); it('should log the successful message', done => { - const spyLoggerDebug = sinon.stub(collectorExporter.logger, 'debug'); - const spyLoggerError = sinon.stub(collectorExporter.logger, 'error'); + const spyLoggerDebug = sinon.stub( + collectorTraceExporter.logger, + 'debug' + ); + const spyLoggerError = sinon.stub( + collectorTraceExporter.logger, + 'error' + ); spyBeacon.restore(); spyBeacon = sinon.stub(window.navigator, 'sendBeacon').returns(true); - collectorExporter.export(spans, () => {}); + collectorTraceExporter.export(spans, () => {}); setTimeout(() => { const response: any = spyLoggerDebug.args[1][0]; @@ -125,12 +130,18 @@ describe('CollectorExporter - web', () => { }); it('should log the error message', done => { - const spyLoggerDebug = sinon.stub(collectorExporter.logger, 'debug'); - const spyLoggerError = sinon.stub(collectorExporter.logger, 'error'); + const spyLoggerDebug = sinon.stub( + collectorTraceExporter.logger, + 'debug' + ); + const spyLoggerError = sinon.stub( + collectorTraceExporter.logger, + 'error' + ); spyBeacon.restore(); spyBeacon = sinon.stub(window.navigator, 'sendBeacon').returns(false); - collectorExporter.export(spans, () => {}); + collectorTraceExporter.export(spans, () => {}); setTimeout(() => { const response: any = spyLoggerError.args[0][0]; @@ -146,7 +157,9 @@ describe('CollectorExporter - web', () => { let server: any; beforeEach(() => { (window.navigator as any).sendBeacon = false; - collectorExporter = new CollectorExporter(collectorExporterConfig); + collectorTraceExporter = new CollectorTraceExporter( + collectorExporterConfig + ); server = sinon.fakeServer.create(); }); afterEach(() => { @@ -154,7 +167,7 @@ describe('CollectorExporter - web', () => { }); it('should successfully send the spans using XMLHttpRequest', done => { - collectorExporter.export(spans, () => {}); + collectorTraceExporter.export(spans, () => {}); setTimeout(() => { const request = server.requests[0]; @@ -188,10 +201,16 @@ describe('CollectorExporter - web', () => { }); it('should log the successful message', done => { - const spyLoggerDebug = sinon.stub(collectorExporter.logger, 'debug'); - const spyLoggerError = sinon.stub(collectorExporter.logger, 'error'); + const spyLoggerDebug = sinon.stub( + collectorTraceExporter.logger, + 'debug' + ); + const spyLoggerError = sinon.stub( + collectorTraceExporter.logger, + 'error' + ); - collectorExporter.export(spans, () => {}); + collectorTraceExporter.export(spans, () => {}); setTimeout(() => { const request = server.requests[0]; @@ -207,9 +226,12 @@ describe('CollectorExporter - web', () => { }); it('should log the error message', done => { - const spyLoggerError = sinon.stub(collectorExporter.logger, 'error'); + const spyLoggerError = sinon.stub( + collectorTraceExporter.logger, + 'error' + ); - collectorExporter.export(spans, () => {}); + collectorTraceExporter.export(spans, () => {}); setTimeout(() => { const request = server.requests[0]; @@ -226,7 +248,7 @@ describe('CollectorExporter - web', () => { }); it('should send custom headers', done => { - collectorExporter.export(spans, () => {}); + collectorTraceExporter.export(spans, () => {}); setTimeout(() => { const request = server.requests[0]; @@ -260,10 +282,12 @@ describe('CollectorExporter - web', () => { describe('when "sendBeacon" is available', () => { beforeEach(() => { - collectorExporter = new CollectorExporter(collectorExporterConfig); + collectorTraceExporter = new CollectorTraceExporter( + collectorExporterConfig + ); }); it('should successfully send custom headers using XMLHTTPRequest', done => { - collectorExporter.export(spans, () => {}); + collectorTraceExporter.export(spans, () => {}); setTimeout(() => { const [{ requestHeaders }] = server.requests; @@ -280,11 +304,13 @@ describe('CollectorExporter - web', () => { describe('when "sendBeacon" is NOT available', () => { beforeEach(() => { (window.navigator as any).sendBeacon = false; - collectorExporter = new CollectorExporter(collectorExporterConfig); + collectorTraceExporter = new CollectorTraceExporter( + collectorExporterConfig + ); }); it('should successfully send spans using XMLHttpRequest', done => { - collectorExporter.export(spans, () => {}); + collectorTraceExporter.export(spans, () => {}); setTimeout(() => { const [{ requestHeaders }] = server.requests; @@ -302,7 +328,7 @@ describe('CollectorExporter - web', () => { describe('CollectorExporter - browser (getDefaultUrl)', () => { it('should default to v1/trace', done => { - const collectorExporter = new CollectorExporter({}); + const collectorExporter = new CollectorTraceExporter({}); setTimeout(() => { assert.strictEqual( collectorExporter['url'], @@ -313,7 +339,7 @@ describe('CollectorExporter - browser (getDefaultUrl)', () => { }); it('should keep the URL if included', done => { const url = 'http://foo.bar.com'; - const collectorExporter = new CollectorExporter({ url }); + const collectorExporter = new CollectorTraceExporter({ url }); setTimeout(() => { assert.strictEqual(collectorExporter['url'], url); done(); diff --git a/packages/opentelemetry-exporter-collector/test/common/CollectorTraceExporter.test.ts b/packages/opentelemetry-exporter-collector/test/common/CollectorTraceExporter.test.ts index 7bd74fc2e2..71ccee1c1c 100644 --- a/packages/opentelemetry-exporter-collector/test/common/CollectorTraceExporter.test.ts +++ b/packages/opentelemetry-exporter-collector/test/common/CollectorTraceExporter.test.ts @@ -18,15 +18,14 @@ import { ExportResult, NoopLogger } from '@opentelemetry/core'; import { ReadableSpan } from '@opentelemetry/tracing'; import * as assert from 'assert'; import * as sinon from 'sinon'; -import { - CollectorExporterBase, - CollectorExporterConfigBase, -} from '../../src/CollectorTraceExporterBase'; - +import { CollectorTraceExporterBase } from '../../src/CollectorTraceExporterBase'; +import { CollectorExporterConfigBase } from '../../src/types'; import { mockedReadableSpan } from '../helper'; type CollectorExporterConfig = CollectorExporterConfigBase; -class CollectorExporter extends CollectorExporterBase { +class CollectorTraceExporter extends CollectorTraceExporterBase< + CollectorExporterConfig +> { onInit() {} onShutdown() {} sendSpans() {} @@ -36,14 +35,14 @@ class CollectorExporter extends CollectorExporterBase { } describe('CollectorExporter - common', () => { - let collectorExporter: CollectorExporter; + let collectorExporter: CollectorTraceExporter; let collectorExporterConfig: CollectorExporterConfig; describe('constructor', () => { let onInitSpy: any; beforeEach(() => { - onInitSpy = sinon.stub(CollectorExporter.prototype, 'onInit'); + onInitSpy = sinon.stub(CollectorTraceExporter.prototype, 'onInit'); collectorExporterConfig = { hostName: 'foo', logger: new NoopLogger(), @@ -51,7 +50,7 @@ describe('CollectorExporter - common', () => { attributes: {}, url: 'http://foo.bar.com', }; - collectorExporter = new CollectorExporter(collectorExporterConfig); + collectorExporter = new CollectorTraceExporter(collectorExporterConfig); }); afterEach(() => { @@ -86,7 +85,7 @@ describe('CollectorExporter - common', () => { describe('when config is missing certain params', () => { beforeEach(() => { - collectorExporter = new CollectorExporter(); + collectorExporter = new CollectorTraceExporter(); }); it('should set default serviceName', () => { @@ -102,8 +101,8 @@ describe('CollectorExporter - common', () => { describe('export', () => { let spySend: any; beforeEach(() => { - spySend = sinon.stub(CollectorExporter.prototype, 'sendSpans'); - collectorExporter = new CollectorExporter(collectorExporterConfig); + spySend = sinon.stub(CollectorTraceExporter.prototype, 'sendSpans'); + collectorExporter = new CollectorTraceExporter(collectorExporterConfig); }); afterEach(() => { spySend.restore(); @@ -146,7 +145,10 @@ describe('CollectorExporter - common', () => { describe('shutdown', () => { let onShutdownSpy: any; beforeEach(() => { - onShutdownSpy = sinon.stub(CollectorExporter.prototype, 'onShutdown'); + onShutdownSpy = sinon.stub( + CollectorTraceExporter.prototype, + 'onShutdown' + ); collectorExporterConfig = { hostName: 'foo', logger: new NoopLogger(), @@ -154,7 +156,7 @@ describe('CollectorExporter - common', () => { attributes: {}, url: 'http://foo.bar.com', }; - collectorExporter = new CollectorExporter(collectorExporterConfig); + collectorExporter = new CollectorTraceExporter(collectorExporterConfig); }); afterEach(() => { onShutdownSpy.restore(); diff --git a/packages/opentelemetry-exporter-collector/test/node/CollectorTraceExporter.test.ts b/packages/opentelemetry-exporter-collector/test/node/CollectorTraceExporter.test.ts index 13da3284a2..aaa534986a 100644 --- a/packages/opentelemetry-exporter-collector/test/node/CollectorTraceExporter.test.ts +++ b/packages/opentelemetry-exporter-collector/test/node/CollectorTraceExporter.test.ts @@ -25,7 +25,7 @@ import { import * as assert from 'assert'; import * as sinon from 'sinon'; -import { CollectorExporter } from '../../src/platform/node'; +import { CollectorTraceExporter } from '../../src/platform/node'; import * as collectorTypes from '../../src/types'; import { @@ -53,7 +53,7 @@ const testCollectorExporter = (params: TestParams) => describe(`CollectorExporter - node ${ params.useTLS ? 'with' : 'without' } TLS, ${params.metadata ? 'with' : 'without'} metadata`, () => { - let collectorExporter: CollectorExporter; + let collectorExporter: CollectorTraceExporter; let server: grpc.Server; let exportedData: | collectorTypes.opentelemetryProto.trace.v1.ResourceSpans @@ -121,7 +121,7 @@ const testCollectorExporter = (params: TestParams) => fs.readFileSync('./test/certs/client.crt') ) : undefined; - collectorExporter = new CollectorExporter({ + collectorExporter = new CollectorTraceExporter({ serviceName: 'basic-service', url: address, credentials, @@ -174,7 +174,7 @@ const testCollectorExporter = (params: TestParams) => describe('CollectorExporter - node (getDefaultUrl)', () => { it('should default to localhost', done => { - const collectorExporter = new CollectorExporter({}); + const collectorExporter = new CollectorTraceExporter({}); setTimeout(() => { assert.strictEqual(collectorExporter['url'], 'localhost:55678'); done(); @@ -182,7 +182,7 @@ describe('CollectorExporter - node (getDefaultUrl)', () => { }); it('should keep the URL if included', done => { const url = 'http://foo.bar.com'; - const collectorExporter = new CollectorExporter({ url }); + const collectorExporter = new CollectorTraceExporter({ url }); setTimeout(() => { assert.strictEqual(collectorExporter['url'], url); done(); From 955aea2bbe74f42252f9521ffdc7d78acfcee60d Mon Sep 17 00:00:00 2001 From: davidwitten Date: Mon, 29 Jun 2020 20:26:53 +0000 Subject: [PATCH 3/3] Added documentation --- examples/collector-exporter-node/start.js | 4 ++-- .../examples/document-load/index.js | 4 ++-- examples/tracer-web/examples/fetch/index.js | 4 ++-- .../examples/user-interaction/index.js | 4 ++-- .../examples/xml-http-request/index.js | 4 ++-- .../README.md | 20 +++++++++---------- .../src/platform/node/README.md | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/collector-exporter-node/start.js b/examples/collector-exporter-node/start.js index 9acbcc0687..5ff85ec123 100644 --- a/examples/collector-exporter-node/start.js +++ b/examples/collector-exporter-node/start.js @@ -2,10 +2,10 @@ const opentelemetry = require('@opentelemetry/api'); const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/tracing'); -const { CollectorExporter } = require('@opentelemetry/exporter-collector'); +const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); const address = '127.0.0.1:55678'; -const exporter = new CollectorExporter({ +const exporter = new CollectorTraceExporter({ serviceName: 'basic-service', url: address, }); diff --git a/examples/tracer-web/examples/document-load/index.js b/examples/tracer-web/examples/document-load/index.js index 4228e8730b..fe72746a5e 100644 --- a/examples/tracer-web/examples/document-load/index.js +++ b/examples/tracer-web/examples/document-load/index.js @@ -2,7 +2,7 @@ import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing import { WebTracerProvider } from '@opentelemetry/web'; import { DocumentLoad } from '@opentelemetry/plugin-document-load'; import { ZoneContextManager } from '@opentelemetry/context-zone'; -import { CollectorExporter } from '@opentelemetry/exporter-collector'; +import { CollectorTraceExporter } from '@opentelemetry/exporter-collector'; const provider = new WebTracerProvider({ plugins: [ @@ -10,7 +10,7 @@ const provider = new WebTracerProvider({ ], }); provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter())); +provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter())); provider.register({ contextManager: new ZoneContextManager(), diff --git a/examples/tracer-web/examples/fetch/index.js b/examples/tracer-web/examples/fetch/index.js index 5be984bbbe..1d29b65475 100644 --- a/examples/tracer-web/examples/fetch/index.js +++ b/examples/tracer-web/examples/fetch/index.js @@ -1,7 +1,7 @@ 'use strict'; import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing'; -import { CollectorExporter } from '@opentelemetry/exporter-collector'; +import { CollectorTraceExporter } from '@opentelemetry/exporter-collector'; import { WebTracerProvider } from '@opentelemetry/web'; import { FetchPlugin } from '@opentelemetry/plugin-fetch'; import { ZoneContextManager } from '@opentelemetry/context-zone'; @@ -21,7 +21,7 @@ const provider = new WebTracerProvider({ }); provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter())); +provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter())); provider.register({ contextManager: new ZoneContextManager(), propagator: new B3Propagator(), diff --git a/examples/tracer-web/examples/user-interaction/index.js b/examples/tracer-web/examples/user-interaction/index.js index a8b67488f6..b15f85a99e 100644 --- a/examples/tracer-web/examples/user-interaction/index.js +++ b/examples/tracer-web/examples/user-interaction/index.js @@ -3,7 +3,7 @@ import { WebTracerProvider } from '@opentelemetry/web'; import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request'; import { UserInteractionPlugin } from '@opentelemetry/plugin-user-interaction'; import { ZoneContextManager } from '@opentelemetry/context-zone'; -import { CollectorExporter } from '@opentelemetry/exporter-collector'; +import { CollectorTraceExporter } from '@opentelemetry/exporter-collector'; import { B3Propagator } from '@opentelemetry/core'; const providerWithZone = new WebTracerProvider({ @@ -19,7 +19,7 @@ const providerWithZone = new WebTracerProvider({ }); providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter())); +providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter())); providerWithZone.register({ contextManager: new ZoneContextManager(), diff --git a/examples/tracer-web/examples/xml-http-request/index.js b/examples/tracer-web/examples/xml-http-request/index.js index 7f025ea14b..ce22cec2c5 100644 --- a/examples/tracer-web/examples/xml-http-request/index.js +++ b/examples/tracer-web/examples/xml-http-request/index.js @@ -2,7 +2,7 @@ import { ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing import { WebTracerProvider } from '@opentelemetry/web'; import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request'; import { ZoneContextManager } from '@opentelemetry/context-zone'; -import { CollectorExporter } from '@opentelemetry/exporter-collector'; +import { CollectorTraceExporter } from '@opentelemetry/exporter-collector'; import { B3Propagator } from '@opentelemetry/core'; const providerWithZone = new WebTracerProvider({ @@ -17,7 +17,7 @@ const providerWithZone = new WebTracerProvider({ }); providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter())); -providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter())); +providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter())); providerWithZone.register({ contextManager: new ZoneContextManager(), diff --git a/packages/opentelemetry-exporter-collector/README.md b/packages/opentelemetry-exporter-collector/README.md index 6a8b828056..a3d0ecd6a3 100644 --- a/packages/opentelemetry-exporter-collector/README.md +++ b/packages/opentelemetry-exporter-collector/README.md @@ -16,12 +16,12 @@ npm install --save @opentelemetry/exporter-collector ## Usage in Web -The CollectorExporter in Web expects the endpoint to end in `/v1/trace`. +The CollectorTraceExporter in Web expects the endpoint to end in `/v1/trace`. ```js import { SimpleSpanProcessor } from '@opentelemetry/tracing'; import { WebTracerProvider } from '@opentelemetry/web'; -import { CollectorExporter } from '@opentelemetry/exporter-collector'; +import { CollectorTraceExporter } from '@opentelemetry/exporter-collector'; const collectorOptions = { url: '', // url is optional and can be omitted - default is http://localhost:55678/v1/trace @@ -29,7 +29,7 @@ const collectorOptions = { }; const provider = new WebTracerProvider(); -const exporter = new CollectorExporter(collectorOptions); +const exporter = new CollectorTraceExporter(collectorOptions); provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); provider.register(); @@ -38,11 +38,11 @@ provider.register(); ## Usage in Node -The CollectorExporter in Node expects the URL to only be the hostname. It will not work with `/v1/trace`. +The CollectorTraceExporter in Node expects the URL to only be the hostname. It will not work with `/v1/trace`. ```js const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/tracing'); -const { CollectorExporter } = require('@opentelemetry/exporter-collector'); +const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); const collectorOptions = { serviceName: 'basic-service', @@ -50,7 +50,7 @@ const collectorOptions = { }; const provider = new BasicTracerProvider(); -const exporter = new CollectorExporter(collectorOptions); +const exporter = new CollectorTraceExporter(collectorOptions); provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); provider.register(); @@ -63,7 +63,7 @@ By default, plaintext connection is used. In order to use TLS in Node.js, provid const fs = require('fs'); const grpc = require('grpc'); const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/tracing'); -const { CollectorExporter } = require('@opentelemetry/exporter-collector'); +const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); const collectorOptions = { serviceName: 'basic-service', @@ -76,7 +76,7 @@ const collectorOptions = { }; const provider = new BasicTracerProvider(); -const exporter = new CollectorExporter(collectorOptions); +const exporter = new CollectorTraceExporter(collectorOptions); provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); provider.register(); @@ -89,7 +89,7 @@ The exporter can be configured to send custom metadata with each request as in t ```js const grpc = require('grpc'); const { BasicTracerProvider, SimpleSpanProcessor } = require('@opentelemetry/tracing'); -const { CollectorExporter } = require('@opentelemetry/exporter-collector'); +const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector'); const metadata = new grpc.Metadata(); metadata.set('k', 'v'); @@ -101,7 +101,7 @@ const collectorOptions = { }; const provider = new BasicTracerProvider(); -const exporter = new CollectorExporter(collectorOptions); +const exporter = new CollectorTraceExporter(collectorOptions); provider.addSpanProcessor(new SimpleSpanProcessor(exporter)); provider.register(); diff --git a/packages/opentelemetry-exporter-collector/src/platform/node/README.md b/packages/opentelemetry-exporter-collector/src/platform/node/README.md index edb0ab60a2..76ff2c2c49 100644 --- a/packages/opentelemetry-exporter-collector/src/platform/node/README.md +++ b/packages/opentelemetry-exporter-collector/src/platform/node/README.md @@ -15,7 +15,7 @@ Knowing this if you want to change the submodule to point to a different version ``` 3. Find the SHA which you want to update to and copy it (the long one) -the latest sha when this guide was written is `e6c3c4a74d57f870a0d781bada02cb2b2c497d14` +the latest sha when this guide was written is `b54688569186e0b862bf7462a983ccf2c50c0547` 4. Enter a submodule directory from this directory