From 4c08972ee4c3079da4dc7fed2358e14a5999ef81 Mon Sep 17 00:00:00 2001 From: vmarchaud Date: Thu, 27 Jun 2019 14:22:02 +0200 Subject: [PATCH] add ContextManager interface #46 --- .../opentelemetry-context-base/src/index.ts | 2 + .../opentelemetry-context-base/src/types.ts | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 packages/opentelemetry-context-base/src/types.ts diff --git a/packages/opentelemetry-context-base/src/index.ts b/packages/opentelemetry-context-base/src/index.ts index 6acf3afa4e0..f21192eb003 100644 --- a/packages/opentelemetry-context-base/src/index.ts +++ b/packages/opentelemetry-context-base/src/index.ts @@ -13,3 +13,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +export * from './types'; diff --git a/packages/opentelemetry-context-base/src/types.ts b/packages/opentelemetry-context-base/src/types.ts new file mode 100644 index 00000000000..cd6a0a3ee5b --- /dev/null +++ b/packages/opentelemetry-context-base/src/types.ts @@ -0,0 +1,51 @@ +/** + * Copyright 2019, 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 + * + * 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 interface BaseContext { + /** + * Get the current state of the context propagation + */ + active: boolean; + + /** + * Wrap an object in the current context (or optionally in a specific context) + * @param object Object to which a context need to be set + * @param [context] Optionaly specify the context which you want to assign + */ + wrap(object: T, context?: unknown): T; + + /** + * Get the current value of a given key from the current context. + * There are specific case where the context is not propagated by specific + * code (ex: user space queueing) so expect it to be undefined sometimes. + */ + get(key: string): unknown; + + /** + * Set the value of a given key in the current context. + */ + set(key: string, value: unknown): void; + + /** + * Enable context propagation + */ + enable(): void; + + /** + * Disable context propagation + */ + disable(): void; +}