Skip to content

Commit

Permalink
fix tests by moving serverAddress checks earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
lizthegrey committed Apr 20, 2021
1 parent 28b16d3 commit edcb871
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Expand Up @@ -26,6 +26,7 @@ import {
ServiceClientType,
} from './types';
import { ServiceClient } from './types';
import { fixUrl } from './util';

/**
* Collector Metric Exporter abstract base class
Expand All @@ -41,13 +42,16 @@ export abstract class CollectorExporterNodeBase<
grpcQueue: GRPCQueueItem<ExportItem>[] = [];
metadata?: Metadata;
serviceClient?: ServiceClient = undefined;
private serverAddress!: string;
private _send!: Function;

constructor(config: CollectorExporterConfigNode = {}) {
super(config);
if (config.headers) {
diag.warn('Headers cannot be set when using grpc');
}

this.serverAddress = fixUrl(this.url)
this.metadata = config.metadata;
}
private _sendPromise(
Expand Down
16 changes: 8 additions & 8 deletions packages/opentelemetry-exporter-collector-grpc/src/util.ts
Expand Up @@ -32,10 +32,6 @@ export function onInit<ExportItem, ServiceRequest>(
config: CollectorExporterConfigNode
): void {
collector.grpcQueue = [];
const serverAddress = removeProtocol(collector.url);
if (collector.url.includes('/')) {
diag.warn('URL path cannot be set when using grpc');
}
const credentials: grpc.ChannelCredentials =
config.credentials || grpc.credentials.createInsecure();

Expand All @@ -55,12 +51,12 @@ export function onInit<ExportItem, ServiceRequest>(

if (collector.getServiceClientType() === ServiceClientType.SPANS) {
collector.serviceClient = new packageObject.opentelemetry.proto.collector.trace.v1.TraceService(
serverAddress,
collector.serverAddress,
credentials
);
} else {
collector.serviceClient = new packageObject.opentelemetry.proto.collector.metrics.v1.MetricsService(
serverAddress,
collector.serverAddress,
credentials
);
}
Expand Down Expand Up @@ -108,6 +104,10 @@ export function send<ExportItem, ServiceRequest>(
}
}

function removeProtocol(url: string): string {
return url.replace(/^(http|grpc)s?:\/\//, '');
export function fixUrl(url: string): string {
const serverAddress = url.replace(/^(http|grpc)s?:\/\//, '');
if (serverAddress.includes('/')) {
diag.warn('URL path cannot be set when using grpc');
}
return serverAddress;
}

0 comments on commit edcb871

Please sign in to comment.