Skip to content

Commit 61dc131

Browse files
smyrickashishagg
authored andcommitted
feat: expose dispatcher config types (#22)
1 parent 711cfb0 commit 61dc131

File tree

7 files changed

+35
-10
lines changed

7 files changed

+35
-10
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6

src/configuration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ import RemoteDispatcher from './dispatchers/remote';
1919
import {Dispatcher} from './dispatchers/dispatcher';
2020
import InMemoryDispatcher from './dispatchers/in_memory';
2121
import NoopDispatcher from './dispatchers/noop';
22+
import { DispatcherConfig } from './dispatchers/dispatcher-config';
2223
import { TracerConfig } from './tracer-config';
2324

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

27-
const dispatcher = config.dispatcher;
28+
const dispatcher: DispatcherConfig = config.dispatcher;
2829
if (dispatcher) {
2930
switch (dispatcher.type) {
3031
case 'file':
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2018 Expedia, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export interface DispatcherConfig {
18+
type: string;
19+
filePath?: string;
20+
agentHost?: string;
21+
agentPort?: number;
22+
}

src/dispatchers/remote.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export default class RemoteDispatcher implements Dispatcher {
2525
_client: any;
2626
_logger: any;
2727

28-
constructor(agentHost: string, agentPort: number, logger: Logger = new NullLogger()) {
29-
agentHost = agentHost || 'haystack-agent';
30-
agentPort = agentPort || 35000;
28+
constructor(agentHost: string = 'haystack-agent', agentPort: number = 35000, logger: Logger = new NullLogger()) {
3129
logger.info(`Initializing the remote dispatcher, connecting at ${agentHost}:${agentPort}`);
3230
this._client = new services.SpanAgentClient(`${agentHost}:${agentPort}`, grpc.credentials.createInsecure());
3331
this._logger = logger;

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import NoopDispatcher from './dispatchers/noop';
2222
import InMemoryDispatcher from './dispatchers/in_memory';
2323
import FileDispatcher from './dispatchers/file';
2424
import AgentDispatcher from './dispatchers/remote';
25+
import { DispatcherConfig } from './dispatchers/dispatcher-config';
2526
import Configuration from './configuration';
2627
import { Logger } from './logger';
2728
import { TracerConfig } from './tracer-config';
@@ -38,6 +39,7 @@ export {
3839
InMemoryDispatcher,
3940
FileDispatcher,
4041
AgentDispatcher,
42+
DispatcherConfig,
4143
opentracing,
4244
Logger
4345
};

src/tracer-config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

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

1920
export interface TracerConfig {
2021
disable?: boolean;
2122
serviceName: string;
2223
logger?: Logger;
23-
commonTags?: any;
24-
dispatcher?: any;
24+
commonTags?: { [key: string]: any };
25+
dispatcher?: DispatcherConfig;
2526
}

src/tracer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {Dispatcher} from './dispatchers/dispatcher';
2121
import Span from './span';
2222
import SpanContext from './span_context';
2323
import NoopDispatcher from './dispatchers/noop';
24-
import { Logger, NullLogger } from './logger/index';
24+
import { Logger, NullLogger } from './logger';
2525
import Utils from './utils';
2626
import PropagationRegistry from './propagators/propagation_registry';
2727
import TextMapPropagator from './propagators/textmap_propagator';
@@ -38,8 +38,8 @@ export default class Tracer extends opentracing.Tracer {
3838
_registry: PropagationRegistry;
3939

4040
constructor(serviceName: string,
41-
dispatcher = new NoopDispatcher(),
42-
commonTags: any = {},
41+
dispatcher: Dispatcher = new NoopDispatcher(),
42+
commonTags: { [key: string]: any } = {},
4343
logger: Logger = new NullLogger()) {
4444
super();
4545
this._commonTags = commonTags || {};

0 commit comments

Comments
 (0)