Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Collector Metric Exporter][1/x] Rename CollectorExporter to CollectorTraceExporter #1256

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
31 changes: 30 additions & 1 deletion packages/opentelemetry-exporter-collector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
*/
Expand Down
Loading