Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import RemoteDispatcher from './dispatchers/remote';
import {Dispatcher} from './dispatchers/dispatcher';
import InMemoryDispatcher from './dispatchers/in_memory';
import NoopDispatcher from './dispatchers/noop';
import { TracerConfig } from './tracer-config';

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

const dispatcher = config.dispatcher;
if (dispatcher) {
Expand Down
4 changes: 2 additions & 2 deletions src/dispatchers/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import * as grpc from 'grpc';
const services = require('../proto_idl_codegen/agent/spanAgent_grpc_pb');
import {Dispatcher} from './dispatcher';
import Span from '../span';
import NullLogger from '../logger';
import { Logger, NullLogger } from '../logger';
import Utils from '../utils';

export default class RemoteDispatcher implements Dispatcher {
_client: any;
_logger: any;

constructor(agentHost: string, agentPort: number, logger = new NullLogger()) {
constructor(agentHost: string, agentPort: number, logger: Logger = new NullLogger()) {
agentHost = agentHost || 'haystack-agent';
agentPort = agentPort || 35000;
logger.info(`Initializing the remote dispatcher, connecting at ${agentHost}:${agentPort}`);
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ import InMemoryDispatcher from './dispatchers/in_memory';
import FileDispatcher from './dispatchers/file';
import AgentDispatcher from './dispatchers/remote';
import Configuration from './configuration';
import { Logger } from './logger';
import { TracerConfig } from './tracer-config';

import * as opentracing from 'opentracing';

export {
Configuration,
TracerConfig,
Tracer,
SpanContext,
Span,
NoopDispatcher,
InMemoryDispatcher,
FileDispatcher,
AgentDispatcher,
opentracing
opentracing,
Logger
};

module.exports = {
Expand Down
18 changes: 18 additions & 0 deletions src/logger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 * from './null-logger';
export * from './logger';
10 changes: 5 additions & 5 deletions src/logger.ts → src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

export default class NullLogger {
debug(msg: string): void {}
info(msg: string): void {}
warn(msg: string): void {}
error(msg: string): void {}
export interface Logger {
debug(msg: string): void;
info(msg: string): void;
warn(msg: string): void;
error(msg: string): void;
}
24 changes: 24 additions & 0 deletions src/logger/null-logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.
*/

import { Logger } from './logger';

export class NullLogger implements Logger {
debug(msg: string): void {}
info(msg: string): void {}
warn(msg: string): void {}
error(msg: string): void {}
}
25 changes: 25 additions & 0 deletions src/tracer-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

import { Logger } from './logger/index';

export interface TracerConfig {
disable?: boolean;
serviceName: string;
logger?: Logger;
commonTags?: any;
dispatcher?: any;
}
7 changes: 4 additions & 3 deletions src/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import {Dispatcher} from './dispatchers/dispatcher';
import Span from './span';
import SpanContext from './span_context';
import NoopDispatcher from './dispatchers/noop';
import NullLogger from './logger';
import { Logger, NullLogger } from './logger/index';
import Utils from './utils';
import PropagationRegistry from './propagators/propagation_registry';
import TextMapPropagator from './propagators/textmap_propagator';
import URLCodex from './propagators/url_codex';
import StartSpanFields from './start_span_fields';
import BinaryPropagator from './propagators/binary_propagator';
import { TracerConfig } from './tracer-config';

export default class Tracer extends opentracing.Tracer {
_serviceName: string;
Expand All @@ -39,7 +40,7 @@ export default class Tracer extends opentracing.Tracer {
constructor(serviceName: string,
dispatcher = new NoopDispatcher(),
commonTags: any = {},
logger = new NullLogger()) {
logger: Logger = new NullLogger()) {
super();
this._commonTags = commonTags || {};
this._serviceName = serviceName;
Expand Down Expand Up @@ -163,7 +164,7 @@ export default class Tracer extends opentracing.Tracer {
return propagator.extract(carrier);
}

static initTracer(config): opentracing.Tracer {
static initTracer(config: TracerConfig): opentracing.Tracer {
if (config.disable) {
return new opentracing.Tracer();
}
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import * as uuid from 'uuid';
import Span from './span';

const messages = require('./proto_idl_codegen/span_pb');

export default class Utils {
Expand Down