Skip to content

Commit

Permalink
feat: [Collector Metric Exporter][1/x] Rename CollectorExporter to Co…
Browse files Browse the repository at this point in the history
…llectorTraceExporter (#1256)
  • Loading branch information
davidwitten authored Jun 29, 2020
1 parent 336286a commit a370a47
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 128 deletions.
4 changes: 2 additions & 2 deletions examples/collector-exporter-node/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
4 changes: 2 additions & 2 deletions examples/tracer-web/examples/document-load/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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: [
new DocumentLoad(),
],
});
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter()));

provider.register({
contextManager: new ZoneContextManager(),
Expand Down
4 changes: 2 additions & 2 deletions examples/tracer-web/examples/fetch/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions examples/tracer-web/examples/user-interaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions examples/tracer-web/examples/xml-http-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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(),
Expand Down
20 changes: 10 additions & 10 deletions packages/opentelemetry-exporter-collector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ 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: '<opentelemetry-collector-url>', // url is optional and can be omitted - default is http://localhost:55678/v1/trace
headers: {}, //an optional object containing custom headers to be sent with each request
};

const provider = new WebTracerProvider();
const exporter = new CollectorExporter(collectorOptions);
const exporter = new CollectorTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

provider.register();
Expand All @@ -38,19 +38,19 @@ 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',
url: '<opentelemetry-collector-url>' // url is optional and can be omitted - default is localhost:55678
};

const provider = new BasicTracerProvider();
const exporter = new CollectorExporter(collectorOptions);
const exporter = new CollectorTraceExporter(collectorOptions);
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));

provider.register();
Expand All @@ -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',
Expand All @@ -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();
Expand All @@ -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');
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,19 @@
* limitations under the License.
*/

import {
CollectorExporterBase,
CollectorExporterConfigBase,
} from '../../CollectorExporterBase';
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',
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './CollectorExporter';
export * from './CollectorTraceExporter';
Original file line number Diff line number Diff line change
Expand Up @@ -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 '../../CollectorExporterBase';
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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
});
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
* limitations under the License.
*/

export * from './CollectorExporter';
export * from './CollectorTraceExporter';
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions packages/opentelemetry-exporter-collector/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 './CollectorExporterBase';
import { COLLECTOR_SPAN_KIND_MAPPING, opentelemetryProto } from './types';
} from './types';
import ValueType = opentelemetryProto.common.v1.ValueType;
import { InstrumentationLibrary } from '@opentelemetry/core';

Expand Down Expand Up @@ -200,7 +201,7 @@ export function toCollectorExportTraceServiceRequest<
T extends CollectorExporterConfigBase
>(
spans: ReadableSpan[],
collectorExporterBase: CollectorExporterBase<T>,
collectorExporterBase: CollectorTraceExporterBase<T>,
name = ''
): opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest {
const groupedSpans: Map<
Expand Down
Loading

0 comments on commit a370a47

Please sign in to comment.