-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/*! | ||
* Copyright 2020, 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 { Context } from '@opentelemetry/scope-base'; | ||
import { Carrier } from '../context/propagation/carrier'; | ||
import { HttpTextFormat } from '../context/propagation/HttpTextFormat'; | ||
import { NOOP_HTTP_TEXT_FORMAT } from '../context/propagation/NoopHttpTextFormat'; | ||
|
||
/** | ||
* Singleton object which represents the entry point to the OpenTelemetry Propagation API | ||
*/ | ||
export class PropagationAPI { | ||
private static _instance?: PropagationAPI; | ||
private _propagator: HttpTextFormat = NOOP_HTTP_TEXT_FORMAT; | ||
|
||
/** Empty private constructor prevents end users from constructing a new instance of the API */ | ||
private constructor() {} | ||
|
||
/** Get the singleton instance of the Propagator API */ | ||
public static getInstance(): PropagationAPI { | ||
if (!this._instance) { | ||
this._instance = new PropagationAPI(); | ||
} | ||
|
||
return this._instance; | ||
} | ||
|
||
/** | ||
* Set the current propagator. Returns the initialized propagator | ||
*/ | ||
public initGlobalPropagator(propagator: HttpTextFormat): HttpTextFormat { | ||
this._propagator = propagator; | ||
return propagator; | ||
} | ||
|
||
/** | ||
* Inject context into a carrier to be propagated inter-process | ||
* | ||
* @param carrier carrier to inject context into | ||
* @param context context carrying tracing data to inject | ||
*/ | ||
// @todo use the context api to get active context | ||
inject(carrier: Carrier, context = Context.TODO): void { | ||
return this._propagator.inject(context, carrier); | ||
} | ||
|
||
/** | ||
* Extract context from a carrier | ||
* | ||
* @param carrier carrier to extract context from | ||
* @param context context which the newly created context will inherit from | ||
*/ | ||
extract( | ||
carrier: Carrier, | ||
// @todo use the context api to get active context | ||
context = Context.TODO | ||
): Context { | ||
return this._propagator.extract(context, carrier); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters