Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up API for release #1759

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opentelemetry-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async function doSomething() {
} catch (err) {
span.setStatus({
// use an appropriate status code here
code: api.StatusCode.ERROR,
code: api.SpanStatusCode.ERROR,
message: err.message,
});
span.end();
Expand Down
6 changes: 6 additions & 0 deletions packages/opentelemetry-api/src/api/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import {
Context,
ContextManager,
createContextKey,
NoopContextManager,
} from '@opentelemetry/context-base';
import {
Expand Down Expand Up @@ -109,4 +110,9 @@ export class ContextAPI {
this._getContextManager().disable();
delete _global[GLOBAL_CONTEXT_MANAGER_API_KEY];
}

/** Create a key to store context variables */
public createKey(description: string): symbol {
return createContextKey(description);
}
}
4 changes: 2 additions & 2 deletions packages/opentelemetry-api/src/baggage/Baggage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { EntryValue } from './EntryValue';
import { BaggageEntryValue } from './EntryValue';

/**
* Baggage represents collection of entries. Each key of
Expand All @@ -25,5 +25,5 @@ import { EntryValue } from './EntryValue';
* dimension to the metric or additional contest properties to logs and traces.
*/
export interface Baggage {
[entryKey: string]: EntryValue;
[entryKey: string]: BaggageEntryValue;
}
10 changes: 5 additions & 5 deletions packages/opentelemetry-api/src/baggage/EntryValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface EntryValue {
/** `String` value of the `EntryValue`. */
export interface BaggageEntryValue {
/** `String` value of the `BaggageEntryValue`. */
value: string;
/**
* ttl is an integer that represents number of hops an entry can
* propagate.
*/
ttl?: EntryTtl;
ttl?: BaggageEntryTtl;
}

/**
* EntryTtl is an integer that represents number of hops an entry can propagate.
* BaggageEntryTtl is an integer that represents number of hops an entry can propagate.
*
* For now, ONLY special values (0 and -1) are supported.
*/
export enum EntryTtl {
export enum BaggageEntryTtl {
/**
* NO_PROPAGATION is considered to have local context and is used within the
* process it created.
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-api/src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/

import { Context, createContextKey } from '@opentelemetry/context-base';
import { Baggage, NoopSpan, Span, SpanContext } from '../';
import { Baggage, Span, SpanContext } from '../';
import { NoopSpan } from '../trace/NoopSpan';

/**
* Active span key
Expand Down
12 changes: 0 additions & 12 deletions packages/opentelemetry-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,20 @@ export * from './common/Logger';
export * from './common/Time';
export * from './context/context';
export * from './context/propagation/TextMapPropagator';
export * from './context/propagation/NoopTextMapPropagator';
export * from './baggage/Baggage';
export * from './baggage/EntryValue';
export * from './metrics/BatchObserverResult';
export * from './metrics/BoundInstrument';
export * from './metrics/Meter';
export * from './metrics/MeterProvider';
export * from './metrics/Metric';
export * from './metrics/NoopMeter';
export * from './metrics/NoopMeterProvider';
export * from './metrics/Observation';
export * from './metrics/ObserverResult';
export * from './trace/attributes';
export * from './trace/Event';
export * from './trace/link_context';
export * from './trace/link';
export * from './trace/NoopLogger';
export * from './trace/NoopSpan';
export * from './trace/NoopTracer';
export * from './trace/NoopTracerProvider';
export * from './trace/ProxyTracer';
export * from './trace/ProxyTracerProvider';
export * from './trace/Sampler';
export * from './trace/SamplingResult';
export * from './trace/span_context';
Expand All @@ -55,9 +47,6 @@ export * from './trace/tracer_provider';
export * from './trace/tracer';

export {
INVALID_SPANID,
INVALID_TRACEID,
INVALID_SPAN_CONTEXT,
isSpanContextValid,
isValidTraceId,
isValidSpanId,
Expand All @@ -66,7 +55,6 @@ export {
export {
Context,
ROOT_CONTEXT,
createContextKey,
ContextManager,
} from '@opentelemetry/context-base';

Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-api/src/metrics/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface MetricOptions {
* Indicates the type of the recorded value.
* @default {@link ValueType.DOUBLE}
*/
valueType?: ValueType;
valueType?: MetricValueType;

/**
* User provided logger.
Expand All @@ -79,7 +79,7 @@ export interface BatchObserverOptions {
}

/** The Type of value. It describes how the data is reported. */
export enum ValueType {
export enum MetricValueType {
INT,
DOUBLE,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-api/src/trace/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface Span {

/**
* Sets a status to the span. If used, this will override the default Span
* status. Default is {@link StatusCode.UNSET}. SetStatus overrides the value
* status. Default is {@link SpanStatusCode.UNSET}. SetStatus overrides the value
* of previous calls to SetStatus on the Span.
*
* @param status the Status to set.
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-api/src/trace/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
export interface Status {
/** The status code of this message. */
code: StatusCode;
code: SpanStatusCode;
/** A developer-facing error message. */
message?: string;
}

/**
* An enumeration of status codes.
*/
export enum StatusCode {
export enum SpanStatusCode {
/**
* The operation has been validated by an Application developer or
* Operator to have completed successfully.
Expand Down
26 changes: 13 additions & 13 deletions packages/opentelemetry-api/test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@

import * as assert from 'assert';
import api, {
TraceFlags,
NoopSpan,
NoopTracerProvider,
NoopTracer,
SpanOptions,
Span,
context,
trace,
propagation,
Context,
defaultTextMapGetter,
defaultTextMapSetter,
metrics,
propagation,
ROOT_CONTEXT,
Span,
SpanOptions,
TextMapGetter,
TextMapPropagator,
Context,
TextMapSetter,
TextMapGetter,
ROOT_CONTEXT,
defaultTextMapSetter,
defaultTextMapGetter,
trace,
TraceFlags,
} from '../../src';
import { NoopSpan } from '../../src/trace/NoopSpan';
import { NoopTracer } from '../../src/trace/NoopTracer';
import { NoopTracerProvider } from '../../src/trace/NoopTracerProvider';

describe('API', () => {
const functions = ['getCurrentSpan', 'startSpan', 'withSpan'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

import * as assert from 'assert';
import {
NoopMeterProvider,
NOOP_BOUND_COUNTER,
NOOP_BOUND_VALUE_RECORDER,
NOOP_COUNTER_METRIC,
NOOP_BOUND_COUNTER,
NOOP_VALUE_RECORDER_METRIC,
} from '../../src';
NOOP_BOUND_VALUE_RECORDER,
} from '../../src/metrics/NoopMeter';
import { NoopMeterProvider } from '../../src/metrics/NoopMeterProvider';

describe('NoopMeter', () => {
it('should not crash', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/

import * as assert from 'assert';
import { SpanStatusCode, TraceFlags } from '../../src';
import { NoopSpan } from '../../src/trace/NoopSpan';
import {
StatusCode,
INVALID_SPANID,
INVALID_TRACEID,
NoopSpan,
TraceFlags,
} from '../../src';
} from '../../src/trace/spancontext-utils';

describe('NoopSpan', () => {
it('do not crash', () => {
Expand All @@ -39,7 +38,7 @@ describe('NoopSpan', () => {
span.addEvent('sent');
span.addEvent('sent', { id: '42', key: 'value' });

span.setStatus({ code: StatusCode.ERROR });
span.setStatus({ code: SpanStatusCode.ERROR });

span.updateName('my-span');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

import * as assert from 'assert';
import {
NoopTracer,
NOOP_SPAN,
context,
setExtractedSpanContext,
SpanContext,
SpanKind,
TraceFlags,
context,
setExtractedSpanContext,
} from '../../src';
import { NOOP_SPAN } from '../../src/trace/NoopSpan';
import { NoopTracer } from '../../src/trace/NoopTracer';

describe('NoopTracer', () => {
it('should not crash', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@

import * as assert from 'assert';
import * as sinon from 'sinon';
import {
NoopSpan,
NOOP_SPAN,
ProxyTracerProvider,
SpanKind,
TracerProvider,
ProxyTracer,
Tracer,
Span,
NoopTracer,
} from '../../src';
import { Span, SpanKind, Tracer, TracerProvider } from '../../src';
import { NoopSpan, NOOP_SPAN } from '../../src/trace/NoopSpan';
import { NoopTracer } from '../../src/trace/NoopTracer';
import { ProxyTracer } from '../../src/trace/ProxyTracer';
import { ProxyTracerProvider } from '../../src/trace/ProxyTracerProvider';

describe('ProxyTracer', () => {
let provider: ProxyTracerProvider;
Expand Down
46 changes: 39 additions & 7 deletions packages/opentelemetry-core/src/trace/NoRecordingSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,57 @@
*/

import {
Attributes,
AttributeValue,
Exception,
HrTime,
Span,
SpanContext,
NoopSpan,
INVALID_SPAN_CONTEXT,
Status,
TimeInput,
} from '@opentelemetry/api';

/**
* The NoRecordingSpan extends the {@link NoopSpan}, making all operations no-op
* except context propagation.
* The NoRecordingSpan provides context propagation only
*/
export class NoRecordingSpan extends NoopSpan {
export class NoRecordingSpan implements Span {
private readonly _context: SpanContext;

constructor(spanContext: SpanContext) {
super(spanContext);
this._context = spanContext || INVALID_SPAN_CONTEXT;
this._context = spanContext || {
traceId: '00000000000000000000000000000000',
spanId: '0000000000000000',
traceFlags: 0,
};
}

// Returns a SpanContext.
context(): SpanContext {
return this._context;
}

setAttribute(_key: string, _value?: AttributeValue): this {
return this;
}
setAttributes(_attributes: Attributes): this {
return this;
}
addEvent(
_name: string,
_attributesOrStartTime?: number | Attributes | HrTime | Date,
_startTime?: TimeInput
): this {
return this;
}
setStatus(_status: Status): this {
return this;
}
updateName(_name: string): this {
return this;
}
end(_endTime?: TimeInput): void {}
isRecording(): boolean {
return false;
}
recordException(_exception: Exception, _time?: TimeInput): void {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { NoopTracerProvider } from '@opentelemetry/api';
import { NoopTracerProvider } from '@opentelemetry/api/build/src/trace/NoopTracerProvider';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean that NoopTracerProvider is not available or it is in different namespace ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NoopTracer provider is not explicitly exported by the package index so the only way to get it is by its full path. This means it is not part of the API that we claim to be "stable" and could move, change name, be removed, or similar. It also means it will not show up in autocomplete and such when people try to explore the package so it will prevent some confusion.

import * as assert from 'assert';
import * as path from 'path';
import { BasePlugin, NoopLogger } from '../../src';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import { NOOP_TRACER, NoopTracerProvider } from '@opentelemetry/api';
import { NoopTracerProvider } from '@opentelemetry/api/build/src/trace/NoopTracerProvider';
import { NOOP_TRACER } from '@opentelemetry/api/build/src/trace/NoopTracer';
import * as assert from 'assert';
import { BasePlugin, NoopLogger } from '../../../src';

Expand Down
Loading