Skip to content

Commit

Permalink
style: lint auto-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgoin committed Jul 23, 2020
1 parent f5d351c commit 98acb74
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 64 deletions.
17 changes: 11 additions & 6 deletions packages/opentelemetry-core/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function getParentSpanContext(
*/
export const SUPPRESS_INSTRUMENTATION_KEY = Context.createKey(
'OpenTelemetry Context Key SUPPRESS_INSTRUMENTATION'
)
);

/**
* Set whether or not instrumentation should be suppressed beyond
Expand All @@ -100,8 +100,11 @@ export const SUPPRESS_INSTRUMENTATION_KEY = Context.createKey(
* @param context context to set the suppress instrumentation value on.
* @param shouldSuppress value to set.
*/
export function setSuppressInstrumentation(context: Context, shouldSuppress: boolean): Context {
return context.setValue(SUPPRESS_INSTRUMENTATION_KEY, shouldSuppress)
export function setSuppressInstrumentation(
context: Context,
shouldSuppress: boolean
): Context {
return context.setValue(SUPPRESS_INSTRUMENTATION_KEY, shouldSuppress);
}

/**
Expand All @@ -110,7 +113,9 @@ export function setSuppressInstrumentation(context: Context, shouldSuppress: boo
*
* @param context context check for the suppress instrumentation value.
*/
export function getSuppressInstrumentation(context: Context): boolean | undefined {
const value = context.getValue(SUPPRESS_INSTRUMENTATION_KEY) as boolean
return value
export function getSuppressInstrumentation(
context: Context
): boolean | undefined {
const value = context.getValue(SUPPRESS_INSTRUMENTATION_KEY) as boolean;
return value;
}
66 changes: 38 additions & 28 deletions packages/opentelemetry-core/test/context/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,57 @@ import {
} from '../../src/context/context';
import { Context } from '@opentelemetry/api';


describe('Context Helpers', () => {
describe('setSuppressInstrumentation', () => {
it('should set suppress instrumentation value', () => {
const expectedValue = true
const context = setSuppressInstrumentation(Context.ROOT_CONTEXT, expectedValue)
const expectedValue = true;
const context = setSuppressInstrumentation(
Context.ROOT_CONTEXT,
expectedValue
);

const value = context.getValue(SUPPRESS_INSTRUMENTATION_KEY)
const boolValue = value as boolean
const value = context.getValue(SUPPRESS_INSTRUMENTATION_KEY);
const boolValue = value as boolean;

assert.equal(boolValue, expectedValue)
})
})
assert.equal(boolValue, expectedValue);
});
});

describe('getSuppressInstrumentation', () => {
it('should get value as bool', () => {
const expectedValue = false
const context = Context.ROOT_CONTEXT.setValue(SUPPRESS_INSTRUMENTATION_KEY, expectedValue)
const expectedValue = false;
const context = Context.ROOT_CONTEXT.setValue(
SUPPRESS_INSTRUMENTATION_KEY,
expectedValue
);

const value = getSuppressInstrumentation(context)
const value = getSuppressInstrumentation(context);

assert.equal(value, expectedValue)
})
assert.equal(value, expectedValue);
});

it('should handle null values', () => {
const expectedValue = null
const context = Context.ROOT_CONTEXT.setValue(SUPPRESS_INSTRUMENTATION_KEY, expectedValue)
const expectedValue = null;
const context = Context.ROOT_CONTEXT.setValue(
SUPPRESS_INSTRUMENTATION_KEY,
expectedValue
);

const value = getSuppressInstrumentation(context)
const value = getSuppressInstrumentation(context);

assert.equal(value, expectedValue)
})
assert.equal(value, expectedValue);
});

it('should handle undefined values', () => {
const expectedValue = undefined
const context = Context.ROOT_CONTEXT.setValue(SUPPRESS_INSTRUMENTATION_KEY, expectedValue)

const value = getSuppressInstrumentation(context)

assert.equal(value, expectedValue)
})
})
})

const expectedValue = undefined;
const context = Context.ROOT_CONTEXT.setValue(
SUPPRESS_INSTRUMENTATION_KEY,
expectedValue
);

const value = getSuppressInstrumentation(context);

assert.equal(value, expectedValue);
});
});
});
4 changes: 2 additions & 2 deletions packages/opentelemetry-tracing/src/Tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
randomSpanId,
randomTraceId,
setActiveSpan,
getSuppressInstrumentation
getSuppressInstrumentation,
} from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { BasicTracerProvider } from './BasicTracerProvider';
Expand Down Expand Up @@ -70,7 +70,7 @@ export class Tracer implements api.Tracer {
options: api.SpanOptions = {},
context = api.context.active()
): api.Span {
const suppressInstrumentation = getSuppressInstrumentation(context)
const suppressInstrumentation = getSuppressInstrumentation(context);
if (suppressInstrumentation) {
this.logger.debug('Instrumentation suppressed, returning NoOp Span');
return api.NOOP_SPAN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SpanProcessor } from '../SpanProcessor';
import { SpanExporter } from './SpanExporter';
import { ReadableSpan } from './ReadableSpan';
import { context } from '@opentelemetry/api';
import { setSuppressInstrumentation } from '@opentelemetry/core'
import { setSuppressInstrumentation } from '@opentelemetry/core';

/**
* An implementation of the {@link SpanProcessor} that converts the {@link Span}
Expand Down Expand Up @@ -46,7 +46,7 @@ export class SimpleSpanProcessor implements SpanProcessor {
// prevent downstream exporter calls from generating spans
context.with(setSuppressInstrumentation(context.active(), true), () => {
this._exporter.export([span], () => {});
})
});
}

shutdown(cb: () => void = () => {}): void {
Expand Down
16 changes: 11 additions & 5 deletions packages/opentelemetry-tracing/test/Tracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
*/

import * as assert from 'assert';
import { NoopSpan, Sampler, SamplingDecision, Context, NOOP_SPAN } from '@opentelemetry/api';
import {
NoopSpan,
Sampler,
SamplingDecision,
Context,
NOOP_SPAN,
} from '@opentelemetry/api';
import { BasicTracerProvider, Tracer, Span } from '../src';
import {
InstrumentationLibrary,
NoopLogger,
AlwaysOnSampler,
AlwaysOffSampler,
setSuppressInstrumentation
setSuppressInstrumentation,
} from '@opentelemetry/core';

describe('Tracer', () => {
Expand Down Expand Up @@ -96,19 +102,19 @@ describe('Tracer', () => {
assert.strictEqual(lib.version, '0.0.1');
});

it('should return cached no-op span when suppressInstrumentation true', (done) => {
it('should return cached no-op span when suppressInstrumentation true', done => {
const tracer = new Tracer(
{ name: 'default', version: '0.0.1' },
{ sampler: new TestSampler() },
tracerProvider
);

const context = setSuppressInstrumentation(Context.ROOT_CONTEXT, true)
const context = setSuppressInstrumentation(Context.ROOT_CONTEXT, true);
const span = tracer.startSpan('span3', undefined, context);

assert.equal(span, NOOP_SPAN);
span.end();

done()
done();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,25 @@ describe('BatchSpanProcessor', () => {

describe('flushing spans with exporter triggering instrumentation', () => {
beforeEach(() => {
const contextManager = new TestStackContextManager().enable()
const contextManager = new TestStackContextManager().enable();
context.setGlobalContextManager(contextManager);
});

afterEach(() => {
context.disable();
});

it('should prevent instrumentation prior to export', (done) => {
const testTracingExporter = new TestTracingSpanExporter()
it('should prevent instrumentation prior to export', done => {
const testTracingExporter = new TestTracingSpanExporter();
const processor = new BatchSpanProcessor(testTracingExporter);

const span = createSampledSpan('test');
processor.onStart(span);
processor.onEnd(span);

processor.forceFlush(() => {
const exporterCreatedSpans = testTracingExporter.getExporterCreatedSpans()
assert.equal(exporterCreatedSpans.length, 0)
const exporterCreatedSpans = testTracingExporter.getExporterCreatedSpans();
assert.equal(exporterCreatedSpans.length, 0);

done();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Span,
BasicTracerProvider,
InMemorySpanExporter,
SimpleSpanProcessor
SimpleSpanProcessor,
} from '../../src';
import { SpanContext, SpanKind, TraceFlags, context } from '@opentelemetry/api';
import { TestTracingSpanExporter } from './TestTracingSpanExporter';
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('SimpleSpanProcessor', () => {

describe('onEnd', () => {
beforeEach(() => {
const contextManager = new TestStackContextManager().enable()
const contextManager = new TestStackContextManager().enable();
context.setGlobalContextManager(contextManager);
});

Expand All @@ -111,7 +111,7 @@ describe('SimpleSpanProcessor', () => {
});

it('should prevent instrumentation prior to export', () => {
const testTracingExporter = new TestTracingSpanExporter()
const testTracingExporter = new TestTracingSpanExporter();
const processor = new SimpleSpanProcessor(testTracingExporter);

const spanContext: SpanContext = {
Expand All @@ -128,8 +128,8 @@ describe('SimpleSpanProcessor', () => {

processor.onEnd(span);

const exporterCreatedSpans = testTracingExporter.getExporterCreatedSpans()
assert.equal(exporterCreatedSpans.length, 0)
const exporterCreatedSpans = testTracingExporter.getExporterCreatedSpans();
assert.equal(exporterCreatedSpans.length, 0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,25 @@ export class TestStackContextManager implements ContextManager {
private _contextStack: Context[] = [];

active(): Context {
return this._contextStack[this._contextStack.length - 1] ?? Context.ROOT_CONTEXT;
return (
this._contextStack[this._contextStack.length - 1] ?? Context.ROOT_CONTEXT
);
}

with<T extends (...args: unknown[]) => ReturnType<T>>(context: Context, fn: T): ReturnType<T> {
with<T extends (...args: unknown[]) => ReturnType<T>>(
context: Context,
fn: T
): ReturnType<T> {
this._contextStack.push(context);
try {
return fn();
}
finally {
} finally {
this._contextStack.pop();
}
}

bind<T>(target: T, context?: Context): T {
throw new Error("Method not implemented.");
throw new Error('Method not implemented.');
}

enable(): this {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
SpanExporter,
ReadableSpan,
Tracer,
SpanProcessor
SpanProcessor,
} from '../../src';
import { ExportResult, NoopLogger, AlwaysOnSampler } from '@opentelemetry/core';

Expand All @@ -42,12 +42,12 @@ export class TestTracingSpanExporter implements SpanExporter {
forceFlush: () => {},
onStart: () => {},
shutdown: () => {},
onEnd: (span) => {
onEnd: span => {
this._exporterCreatedSpans.push(span);
}
}
},
};

tracerProvider.addSpanProcessor(spanProcessor)
tracerProvider.addSpanProcessor(spanProcessor);

this._tracer = new Tracer(
{ name: 'default', version: '0.0.1' },
Expand All @@ -66,7 +66,7 @@ export class TestTracingSpanExporter implements SpanExporter {

// Simulates an instrumented exporter by creating a span on the tracer.
const createdSpan = this._tracer.startSpan('exporter-created-span');
createdSpan.end()
createdSpan.end();

this._processedSpans.push(...spans);
return resultCallback(ExportResult.SUCCESS);
Expand Down

0 comments on commit 98acb74

Please sign in to comment.