Skip to content

Commit 711cfb0

Browse files
authored
Merge pull request #21 from smyrick/config-types
feat: add tracer config types
2 parents 17b7c1b + 080b398 commit 711cfb0

9 files changed

Lines changed: 86 additions & 12 deletions

File tree

src/configuration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ 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 { TracerConfig } from './tracer-config';
2223

2324
export default class Configuration {
24-
static _getDispatcher(config): Dispatcher {
25+
static _getDispatcher(config: TracerConfig): Dispatcher {
2526

2627
const dispatcher = config.dispatcher;
2728
if (dispatcher) {

src/dispatchers/remote.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import * as grpc from 'grpc';
1818
const services = require('../proto_idl_codegen/agent/spanAgent_grpc_pb');
1919
import {Dispatcher} from './dispatcher';
2020
import Span from '../span';
21-
import NullLogger from '../logger';
21+
import { Logger, NullLogger } from '../logger';
2222
import Utils from '../utils';
2323

2424
export default class RemoteDispatcher implements Dispatcher {
2525
_client: any;
2626
_logger: any;
2727

28-
constructor(agentHost: string, agentPort: number, logger = new NullLogger()) {
28+
constructor(agentHost: string, agentPort: number, logger: Logger = new NullLogger()) {
2929
agentHost = agentHost || 'haystack-agent';
3030
agentPort = agentPort || 35000;
3131
logger.info(`Initializing the remote dispatcher, connecting at ${agentHost}:${agentPort}`);

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,23 @@ import InMemoryDispatcher from './dispatchers/in_memory';
2323
import FileDispatcher from './dispatchers/file';
2424
import AgentDispatcher from './dispatchers/remote';
2525
import Configuration from './configuration';
26+
import { Logger } from './logger';
27+
import { TracerConfig } from './tracer-config';
2628

2729
import * as opentracing from 'opentracing';
2830

2931
export {
3032
Configuration,
33+
TracerConfig,
3134
Tracer,
3235
SpanContext,
3336
Span,
3437
NoopDispatcher,
3538
InMemoryDispatcher,
3639
FileDispatcher,
3740
AgentDispatcher,
38-
opentracing
41+
opentracing,
42+
Logger
3943
};
4044

4145
module.exports = {

src/logger/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 * from './null-logger';
18+
export * from './logger';

src/logger.ts renamed to src/logger/logger.ts

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

17-
export default class NullLogger {
18-
debug(msg: string): void {}
19-
info(msg: string): void {}
20-
warn(msg: string): void {}
21-
error(msg: string): void {}
17+
export interface Logger {
18+
debug(msg: string): void;
19+
info(msg: string): void;
20+
warn(msg: string): void;
21+
error(msg: string): void;
2222
}

src/logger/null-logger.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
import { Logger } from './logger';
18+
19+
export class NullLogger implements Logger {
20+
debug(msg: string): void {}
21+
info(msg: string): void {}
22+
warn(msg: string): void {}
23+
error(msg: string): void {}
24+
}

src/tracer-config.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
import { Logger } from './logger/index';
18+
19+
export interface TracerConfig {
20+
disable?: boolean;
21+
serviceName: string;
22+
logger?: Logger;
23+
commonTags?: any;
24+
dispatcher?: any;
25+
}

src/tracer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import {Dispatcher} from './dispatchers/dispatcher';
2121
import Span from './span';
2222
import SpanContext from './span_context';
2323
import NoopDispatcher from './dispatchers/noop';
24-
import NullLogger from './logger';
24+
import { Logger, NullLogger } from './logger/index';
2525
import Utils from './utils';
2626
import PropagationRegistry from './propagators/propagation_registry';
2727
import TextMapPropagator from './propagators/textmap_propagator';
2828
import URLCodex from './propagators/url_codex';
2929
import StartSpanFields from './start_span_fields';
3030
import BinaryPropagator from './propagators/binary_propagator';
31+
import { TracerConfig } from './tracer-config';
3132

3233
export default class Tracer extends opentracing.Tracer {
3334
_serviceName: string;
@@ -39,7 +40,7 @@ export default class Tracer extends opentracing.Tracer {
3940
constructor(serviceName: string,
4041
dispatcher = new NoopDispatcher(),
4142
commonTags: any = {},
42-
logger = new NullLogger()) {
43+
logger: Logger = new NullLogger()) {
4344
super();
4445
this._commonTags = commonTags || {};
4546
this._serviceName = serviceName;
@@ -163,7 +164,7 @@ export default class Tracer extends opentracing.Tracer {
163164
return propagator.extract(carrier);
164165
}
165166

166-
static initTracer(config): opentracing.Tracer {
167+
static initTracer(config: TracerConfig): opentracing.Tracer {
167168
if (config.disable) {
168169
return new opentracing.Tracer();
169170
}

src/utils.ts

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

1717
import * as uuid from 'uuid';
1818
import Span from './span';
19+
1920
const messages = require('./proto_idl_codegen/span_pb');
2021

2122
export default class Utils {

0 commit comments

Comments
 (0)