Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Merge branch 'main' into document-symbol-for
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored May 12, 2021
2 parents f63dafc + 6dda822 commit 5de6aa8
Show file tree
Hide file tree
Showing 16 changed files with 199 additions and 209 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ Because the npm installer and node module resolution algorithm could potentially

### 1.0.0-rc.0 to x

- Removing `TimedEvent` which was not part of spec
- `HttpBaggage` renamed to `HttpBaggagePropagator`
- [#45](https://github.com/open-telemetry/opentelemetry-js-api/pull/45) `Span#context` renamed to `Span#spanContext`
- [#47](https://github.com/open-telemetry/opentelemetry-js-api/pull/47) `getSpan`/`setSpan`/`getSpanContext`/`setSpanContext` moved to `trace` namespace

## Useful links

Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
"access": "public"
},
"devDependencies": {
"@types/mocha": "8.2.1",
"@types/node": "14.14.28",
"@types/sinon": "9.0.10",
"@types/mocha": "8.2.2",
"@types/node": "14.14.42",
"@types/sinon": "10.0.0",
"@types/webpack-env": "1.16.0",
"@typescript-eslint/eslint-plugin": "4.15.1",
"@typescript-eslint/parser": "4.15.1",
"@typescript-eslint/eslint-plugin": "4.22.0",
"@typescript-eslint/parser": "4.22.0",
"codecov": "3.8.1",
"eslint": "7.20.0",
"eslint": "7.25.0",
"eslint-plugin-header": "3.1.1",
"eslint-plugin-import": "2.22.1",
"gh-pages": "3.1.0",
Expand All @@ -74,15 +74,15 @@
"karma-mocha": "2.0.1",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "4.0.2",
"lerna-changelog": "^1.0.1",
"linkinator": "2.13.5",
"lerna-changelog": "1.0.1",
"linkinator": "2.13.6",
"mocha": "7.2.0",
"nyc": "15.1.0",
"sinon": "9.2.4",
"ts-loader": "8.0.17",
"sinon": "10.0.0",
"ts-loader": "8.2.0",
"ts-mocha": "8.0.0",
"typedoc": "0.20.25",
"typescript": "4.1.5",
"typedoc": "0.20.36",
"typescript": "4.2.4",
"webpack": "4.46.0"
}
}
27 changes: 23 additions & 4 deletions src/api/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@
* limitations under the License.
*/

import { ProxyTracerProvider } from '../trace/ProxyTracerProvider';
import { Tracer } from '../trace/tracer';
import { TracerProvider } from '../trace/tracer_provider';
import { isSpanContextValid } from '../trace/spancontext-utils';
import {
getGlobal,
registerGlobal,
unregisterGlobal,
} from '../internal/global-utils';
import { ProxyTracerProvider } from '../trace/ProxyTracerProvider';
import {
isSpanContextValid,
wrapSpanContext,
} from '../trace/spancontext-utils';
import { Tracer } from '../trace/tracer';
import { TracerProvider } from '../trace/tracer_provider';
import {
getSpan,
getSpanContext,
setSpan,
setSpanContext,
} from '../trace/context-utils';

const API_NAME = 'trace';

Expand Down Expand Up @@ -76,5 +85,15 @@ export class TraceAPI {
this._proxyTracerProvider = new ProxyTracerProvider();
}

public wrapSpanContext = wrapSpanContext;

public isSpanContextValid = isSpanContextValid;

public getSpan = getSpan;

public getSpanContext = getSpanContext;

public setSpan = setSpan;

public setSpanContext = setSpanContext;
}
23 changes: 23 additions & 0 deletions src/baggage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ import { Baggage } from './Baggage';
import { BaggageEntry, BaggageEntryMetadata } from './Entry';
import { BaggageImpl } from './internal/baggage';
import { baggageEntryMetadataSymbol } from './internal/symbol';
import { Context } from '../context/types';
import { createContextKey } from '../context/context';

export * from './Baggage';
export * from './Entry';

/**
* Baggage key
*/
const BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key');

/**
* Create a new Baggage with optional entries
*
Expand All @@ -33,6 +40,22 @@ export function createBaggage(
return new BaggageImpl(new Map(Object.entries(entries)));
}

/**
* @param {Context} Context that manage all context values
* @returns {Baggage} Extracted baggage from the context
*/
export function getBaggage(context: Context): Baggage | undefined {
return (context.getValue(BAGGAGE_KEY) as Baggage) || undefined;
}

/**
* @param {Context} Context that manage all context values
* @param {Baggage} baggage that will be set in the actual context
*/
export function setBaggage(context: Context, baggage: Baggage): Context {
return context.setValue(BAGGAGE_KEY, baggage);
}

/**
* Create a serializable BaggageEntryMetadata object from a string.
*
Expand Down
108 changes: 0 additions & 108 deletions src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,114 +15,6 @@
*/

import { Context } from './types';
import { Baggage, Span, SpanContext } from '../';
import { NonRecordingSpan } from '../trace/NonRecordingSpan';

/**
* span key
*/
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'
);

/**
* Baggage key
*/
const BAGGAGE_KEY = createContextKey('OpenTelemetry Baggage Key');

/**
* Return the span if one exists
*
* @param context context to get span from
*/
export function getSpan(context: Context): Span | undefined {
return (context.getValue(SPAN_KEY) as Span) || undefined;
}

/**
* Set the span on a context
*
* @param context context to use as parent
* @param span span to set active
*/
export function setSpan(context: Context, span: Span): Context {
return context.setValue(SPAN_KEY, span);
}

/**
* Wrap span context in a NonRecordingSpan and set as span in a new
* context
*
* @param context context to set active span on
* @param spanContext span context to be wrapped
*/
export function setSpanContext(
context: Context,
spanContext: SpanContext
): Context {
return setSpan(context, new NonRecordingSpan(spanContext));
}

/**
* Get the span context of the span if it exists.
*
* @param context context to get values from
*/
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));
}

/**
* @param {Context} Context that manage all context values
* @returns {Baggage} Extracted baggage from the context
*/
export function getBaggage(context: Context): Baggage | undefined {
return (context.getValue(BAGGAGE_KEY) as Baggage) || undefined;
}

/**
* @param {Context} Context that manage all context values
* @param {Baggage} baggage that will be set in the actual context
*/
export function setBaggage(context: Context, baggage: Baggage): Context {
return context.setValue(BAGGAGE_KEY, baggage);
}

/** Get a key to uniquely identify a context value */
export function createContextKey(description: string) {
Expand Down
3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export * from './diag';
export * from './propagation/NoopTextMapPropagator';
export * from './propagation/TextMapPropagator';
export * from './trace/attributes';
export * from './trace/Event';
export * from './trace/link_context';
export * from './trace/link';
export * from './trace/NoopTracer';
export * from './trace/NoopTracerProvider';
Expand All @@ -35,7 +33,6 @@ export * from './trace/span_kind';
export * from './trace/span';
export * from './trace/SpanOptions';
export * from './trace/status';
export * from './trace/TimedEvent';
export * from './trace/trace_flags';
export * from './trace/trace_state';
export * from './trace/tracer_provider';
Expand Down
25 changes: 0 additions & 25 deletions src/trace/Event.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { getSpanContext } from '../context/context';
import { getSpanContext } from '../trace/context-utils';
import { Context } from '../context/types';
import { NonRecordingSpan } from './NonRecordingSpan';
import { Span } from './span';
Expand Down
26 changes: 0 additions & 26 deletions src/trace/TimedEvent.ts

This file was deleted.

Loading

0 comments on commit 5de6aa8

Please sign in to comment.