From 6ae72c23b63790219b9f3340ca7976ffc49b0c62 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Fri, 14 May 2021 03:22:06 -0400 Subject: [PATCH] chore: remove suppress instrumentation (#65) --- api/src/trace/context-utils.ts | 38 ------------- api/test/trace/context-utils.test.ts | 80 ---------------------------- 2 files changed, 118 deletions(-) delete mode 100644 api/test/trace/context-utils.test.ts diff --git a/api/src/trace/context-utils.ts b/api/src/trace/context-utils.ts index 4d8d2fe8ffb..3714eb964c6 100644 --- a/api/src/trace/context-utils.ts +++ b/api/src/trace/context-utils.ts @@ -25,14 +25,6 @@ import { NonRecordingSpan } from './NonRecordingSpan'; */ const SPAN_KEY = createContextKey('OpenTelemetry Context Key SPAN'); -/** - * Shared key for indicating if instrumentation should be suppressed beyond - * this current scope. - */ -const SUPPRESS_INSTRUMENTATION_KEY = createContextKey( - 'OpenTelemetry Context Key SUPPRESS_INSTRUMENTATION' -); - /** * Return the span if one exists * @@ -74,33 +66,3 @@ export function setSpanContext( export function getSpanContext(context: Context): SpanContext | undefined { return getSpan(context)?.spanContext(); } - -/** - * Sets value on context to indicate that instrumentation should - * be suppressed beyond this current scope. - * - * @param context context to set the suppress instrumentation value on. - */ -export function suppressInstrumentation(context: Context): Context { - return context.setValue(SUPPRESS_INSTRUMENTATION_KEY, true); -} - -/** - * Sets value on context to indicate that instrumentation should - * no-longer be suppressed beyond this current scope. - * - * @param context context to set the suppress instrumentation value on. - */ -export function unsuppressInstrumentation(context: Context): Context { - return context.setValue(SUPPRESS_INSTRUMENTATION_KEY, false); -} - -/** - * Return current suppress instrumentation value for the given context, - * if it exists. - * - * @param context context check for the suppress instrumentation value. - */ -export function isInstrumentationSuppressed(context: Context): boolean { - return Boolean(context.getValue(SUPPRESS_INSTRUMENTATION_KEY)); -} diff --git a/api/test/trace/context-utils.test.ts b/api/test/trace/context-utils.test.ts deleted file mode 100644 index 1f24c34c69c..00000000000 --- a/api/test/trace/context-utils.test.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * 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 - * - * https://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 * as assert from 'assert'; -import { - isInstrumentationSuppressed, - suppressInstrumentation, - unsuppressInstrumentation, -} from '../../src/trace/context-utils'; -import { createContextKey, ROOT_CONTEXT } from '../../src/context/context'; - -const SUPPRESS_INSTRUMENTATION_KEY = createContextKey( - 'OpenTelemetry Context Key SUPPRESS_INSTRUMENTATION' -); - -describe('Context Helpers', () => { - describe('suppressInstrumentation', () => { - it('should set suppress to true', () => { - const context = suppressInstrumentation(ROOT_CONTEXT); - assert.deepStrictEqual(isInstrumentationSuppressed(context), true); - }); - }); - - describe('unsuppressInstrumentation', () => { - it('should set suppress to false', () => { - const context = unsuppressInstrumentation(ROOT_CONTEXT); - assert.deepStrictEqual(isInstrumentationSuppressed(context), false); - }); - }); - - describe('isInstrumentationSuppressed', () => { - it('should get value as bool', () => { - const expectedValue = true; - const context = ROOT_CONTEXT.setValue( - SUPPRESS_INSTRUMENTATION_KEY, - expectedValue - ); - - const value = isInstrumentationSuppressed(context); - - assert.equal(value, expectedValue); - }); - - describe('when suppress instrumentation set to null', () => { - const context = ROOT_CONTEXT.setValue(SUPPRESS_INSTRUMENTATION_KEY, null); - - it('should return false', () => { - const value = isInstrumentationSuppressed(context); - - assert.equal(value, false); - }); - }); - - describe('when suppress instrumentation set to undefined', () => { - const context = ROOT_CONTEXT.setValue( - SUPPRESS_INSTRUMENTATION_KEY, - undefined - ); - - it('should return false', () => { - const value = isInstrumentationSuppressed(context); - - assert.equal(value, false); - }); - }); - }); -});