Skip to content

Commit

Permalink
feat: expose dispatcher config types (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
smyrick authored and ashishagg committed Aug 20, 2018
1 parent 711cfb0 commit 61dc131
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
3 changes: 2 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import RemoteDispatcher from './dispatchers/remote';
import {Dispatcher} from './dispatchers/dispatcher';
import InMemoryDispatcher from './dispatchers/in_memory';
import NoopDispatcher from './dispatchers/noop';
import { DispatcherConfig } from './dispatchers/dispatcher-config';
import { TracerConfig } from './tracer-config';

export default class Configuration {
static _getDispatcher(config: TracerConfig): Dispatcher {

const dispatcher = config.dispatcher;
const dispatcher: DispatcherConfig = config.dispatcher;
if (dispatcher) {
switch (dispatcher.type) {
case 'file':
Expand Down
22 changes: 22 additions & 0 deletions src/dispatchers/dispatcher-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2018 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export interface DispatcherConfig {
type: string;
filePath?: string;
agentHost?: string;
agentPort?: number;
}
4 changes: 1 addition & 3 deletions src/dispatchers/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export default class RemoteDispatcher implements Dispatcher {
_client: any;
_logger: any;

constructor(agentHost: string, agentPort: number, logger: Logger = new NullLogger()) {
agentHost = agentHost || 'haystack-agent';
agentPort = agentPort || 35000;
constructor(agentHost: string = 'haystack-agent', agentPort: number = 35000, logger: Logger = new NullLogger()) {
logger.info(`Initializing the remote dispatcher, connecting at ${agentHost}:${agentPort}`);
this._client = new services.SpanAgentClient(`${agentHost}:${agentPort}`, grpc.credentials.createInsecure());
this._logger = logger;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import NoopDispatcher from './dispatchers/noop';
import InMemoryDispatcher from './dispatchers/in_memory';
import FileDispatcher from './dispatchers/file';
import AgentDispatcher from './dispatchers/remote';
import { DispatcherConfig } from './dispatchers/dispatcher-config';
import Configuration from './configuration';
import { Logger } from './logger';
import { TracerConfig } from './tracer-config';
Expand All @@ -38,6 +39,7 @@ export {
InMemoryDispatcher,
FileDispatcher,
AgentDispatcher,
DispatcherConfig,
opentracing,
Logger
};
Expand Down
7 changes: 4 additions & 3 deletions src/tracer-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import { Logger } from './logger/index';
import { Logger } from './logger';
import { DispatcherConfig } from './dispatchers/dispatcher-config';

export interface TracerConfig {
disable?: boolean;
serviceName: string;
logger?: Logger;
commonTags?: any;
dispatcher?: any;
commonTags?: { [key: string]: any };
dispatcher?: DispatcherConfig;
}
6 changes: 3 additions & 3 deletions src/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {Dispatcher} from './dispatchers/dispatcher';
import Span from './span';
import SpanContext from './span_context';
import NoopDispatcher from './dispatchers/noop';
import { Logger, NullLogger } from './logger/index';
import { Logger, NullLogger } from './logger';
import Utils from './utils';
import PropagationRegistry from './propagators/propagation_registry';
import TextMapPropagator from './propagators/textmap_propagator';
Expand All @@ -38,8 +38,8 @@ export default class Tracer extends opentracing.Tracer {
_registry: PropagationRegistry;

constructor(serviceName: string,
dispatcher = new NoopDispatcher(),
commonTags: any = {},
dispatcher: Dispatcher = new NoopDispatcher(),
commonTags: { [key: string]: any } = {},
logger: Logger = new NullLogger()) {
super();
this._commonTags = commonTags || {};
Expand Down

0 comments on commit 61dc131

Please sign in to comment.