From 98acb74552dd7d550e75186be902836f06f9aebe Mon Sep 17 00:00:00 2001 From: Michael Goin Date: Thu, 23 Jul 2020 12:35:21 -0700 Subject: [PATCH] style: lint auto-fix --- .../opentelemetry-core/src/context/context.ts | 17 +++-- .../test/context/context.test.ts | 66 +++++++++++-------- packages/opentelemetry-tracing/src/Tracer.ts | 4 +- .../src/export/SimpleSpanProcessor.ts | 4 +- .../opentelemetry-tracing/test/Tracer.test.ts | 16 +++-- .../test/export/BatchSpanProcessor.test.ts | 10 +-- .../test/export/SimpleSpanProcessor.test.ts | 10 +-- .../test/export/TestStackContextManager.ts | 14 ++-- .../test/export/TestTracingSpanExporter.ts | 12 ++-- 9 files changed, 89 insertions(+), 64 deletions(-) diff --git a/packages/opentelemetry-core/src/context/context.ts b/packages/opentelemetry-core/src/context/context.ts index 671523b44f..d196e10e84 100644 --- a/packages/opentelemetry-core/src/context/context.ts +++ b/packages/opentelemetry-core/src/context/context.ts @@ -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 @@ -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); } /** @@ -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; } diff --git a/packages/opentelemetry-core/test/context/context.test.ts b/packages/opentelemetry-core/test/context/context.test.ts index 7328d8d957..f97a925c18 100644 --- a/packages/opentelemetry-core/test/context/context.test.ts +++ b/packages/opentelemetry-core/test/context/context.test.ts @@ -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); + }); + }); +}); diff --git a/packages/opentelemetry-tracing/src/Tracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts index 2dc355fb1a..72d656567a 100644 --- a/packages/opentelemetry-tracing/src/Tracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -25,7 +25,7 @@ import { randomSpanId, randomTraceId, setActiveSpan, - getSuppressInstrumentation + getSuppressInstrumentation, } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import { BasicTracerProvider } from './BasicTracerProvider'; @@ -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; diff --git a/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts b/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts index fbd2d90627..1ffbeba22f 100644 --- a/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts +++ b/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts @@ -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} @@ -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 { diff --git a/packages/opentelemetry-tracing/test/Tracer.test.ts b/packages/opentelemetry-tracing/test/Tracer.test.ts index cbd6d233e6..4d81537229 100644 --- a/packages/opentelemetry-tracing/test/Tracer.test.ts +++ b/packages/opentelemetry-tracing/test/Tracer.test.ts @@ -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', () => { @@ -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(); }); }); diff --git a/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts b/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts index c1d6cb27c4..52abf4aaae 100644 --- a/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts +++ b/packages/opentelemetry-tracing/test/export/BatchSpanProcessor.test.ts @@ -233,7 +233,7 @@ describe('BatchSpanProcessor', () => { describe('flushing spans with exporter triggering instrumentation', () => { beforeEach(() => { - const contextManager = new TestStackContextManager().enable() + const contextManager = new TestStackContextManager().enable(); context.setGlobalContextManager(contextManager); }); @@ -241,8 +241,8 @@ describe('BatchSpanProcessor', () => { 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'); @@ -250,8 +250,8 @@ describe('BatchSpanProcessor', () => { processor.onEnd(span); processor.forceFlush(() => { - const exporterCreatedSpans = testTracingExporter.getExporterCreatedSpans() - assert.equal(exporterCreatedSpans.length, 0) + const exporterCreatedSpans = testTracingExporter.getExporterCreatedSpans(); + assert.equal(exporterCreatedSpans.length, 0); done(); }); diff --git a/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts b/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts index eb29c69bca..d16d765512 100644 --- a/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts +++ b/packages/opentelemetry-tracing/test/export/SimpleSpanProcessor.test.ts @@ -19,7 +19,7 @@ import { Span, BasicTracerProvider, InMemorySpanExporter, - SimpleSpanProcessor + SimpleSpanProcessor, } from '../../src'; import { SpanContext, SpanKind, TraceFlags, context } from '@opentelemetry/api'; import { TestTracingSpanExporter } from './TestTracingSpanExporter'; @@ -102,7 +102,7 @@ describe('SimpleSpanProcessor', () => { describe('onEnd', () => { beforeEach(() => { - const contextManager = new TestStackContextManager().enable() + const contextManager = new TestStackContextManager().enable(); context.setGlobalContextManager(contextManager); }); @@ -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 = { @@ -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); }); }); }); diff --git a/packages/opentelemetry-tracing/test/export/TestStackContextManager.ts b/packages/opentelemetry-tracing/test/export/TestStackContextManager.ts index e9cc59cd29..3062ea1069 100644 --- a/packages/opentelemetry-tracing/test/export/TestStackContextManager.ts +++ b/packages/opentelemetry-tracing/test/export/TestStackContextManager.ts @@ -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 ReturnType>(context: Context, fn: T): ReturnType { + with ReturnType>( + context: Context, + fn: T + ): ReturnType { this._contextStack.push(context); try { return fn(); - } - finally { + } finally { this._contextStack.pop(); } } bind(target: T, context?: Context): T { - throw new Error("Method not implemented."); + throw new Error('Method not implemented.'); } enable(): this { diff --git a/packages/opentelemetry-tracing/test/export/TestTracingSpanExporter.ts b/packages/opentelemetry-tracing/test/export/TestTracingSpanExporter.ts index d9af0689f5..e4268e586f 100644 --- a/packages/opentelemetry-tracing/test/export/TestTracingSpanExporter.ts +++ b/packages/opentelemetry-tracing/test/export/TestTracingSpanExporter.ts @@ -19,7 +19,7 @@ import { SpanExporter, ReadableSpan, Tracer, - SpanProcessor + SpanProcessor, } from '../../src'; import { ExportResult, NoopLogger, AlwaysOnSampler } from '@opentelemetry/core'; @@ -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' }, @@ -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);