Skip to content

Commit

Permalink
More specific api type names (open-telemetry#1874)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Feb 18, 2021
1 parent 1203c11 commit 16f79e0
Show file tree
Hide file tree
Showing 15 changed files with 813 additions and 1,255 deletions.
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,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
1,233 changes: 468 additions & 765 deletions api/packages/opentelemetry-api/package-lock.json

Large diffs are not rendered by default.

753 changes: 304 additions & 449 deletions api/packages/opentelemetry-context-base/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions 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 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
4 changes: 2 additions & 2 deletions api/src/trace/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

import { Attributes } from './attributes';
import { SpanAttributes } from './attributes';

/** A text annotation with a set of attributes. */
export interface Event {
/** The name of the event. */
name: string;
/** The attributes of the event. */
attributes?: Attributes;
attributes?: SpanAttributes;
}
10 changes: 5 additions & 5 deletions api/src/trace/NoopSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import { Exception } from '../common/Exception';
import { TimeInput } from '../common/Time';
import { Attributes } from './attributes';
import { SpanAttributes } from './attributes';
import { Span } from './span';
import { SpanContext } from './span_context';
import { Status } from './status';
import { SpanStatus } from './status';
import { INVALID_SPAN_CONTEXT } from './spancontext-utils';

/**
Expand All @@ -43,17 +43,17 @@ export class NoopSpan implements Span {
}

// By default does nothing
setAttributes(_attributes: Attributes): this {
setAttributes(_attributes: SpanAttributes): this {
return this;
}

// By default does nothing
addEvent(_name: string, _attributes?: Attributes): this {
addEvent(_name: string, _attributes?: SpanAttributes): this {
return this;
}

// By default does nothing
setStatus(_status: Status): this {
setStatus(_status: SpanStatus): this {
return this;
}

Expand Down
6 changes: 3 additions & 3 deletions api/src/trace/Sampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { Context } from '@opentelemetry/context-base';
import { Attributes } from './attributes';
import { SpanAttributes } from './attributes';
import { Link } from './link';
import { SamplingResult } from './SamplingResult';
import { SpanKind } from './span_kind';
Expand All @@ -35,7 +35,7 @@ export interface Sampler {
* span to be created starts a new trace.
* @param spanName of the span to be created.
* @param spanKind of the span to be created.
* @param attributes Initial set of Attributes for the Span being constructed.
* @param attributes Initial set of SpanAttributes for the Span being constructed.
* @param links Collection of links that will be associated with the Span to
* be created. Typically useful for batch operations.
* @returns a {@link SamplingResult}.
Expand All @@ -45,7 +45,7 @@ export interface Sampler {
traceId: string,
spanName: string,
spanKind: SpanKind,
attributes: Attributes,
attributes: SpanAttributes,
links: Link[]
): SamplingResult;

Expand Down
4 changes: 2 additions & 2 deletions api/src/trace/SamplingResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Attributes } from './attributes';
import { SpanAttributes } from './attributes';

/**
* A sampling decision that determines how a {@link Span} will be recorded
Expand Down Expand Up @@ -52,5 +52,5 @@ export interface SamplingResult {
* Caller may call {@link Sampler}.shouldSample any number of times and
* can safely cache the returned value.
*/
attributes?: Readonly<Attributes>;
attributes?: Readonly<SpanAttributes>;
}
4 changes: 2 additions & 2 deletions api/src/trace/SpanOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { TimeInput } from '../common/Time';
import { Attributes } from './attributes';
import { SpanAttributes } from './attributes';
import { Link } from './link';
import { SpanKind } from './span_kind';

Expand All @@ -30,7 +30,7 @@ export interface SpanOptions {
kind?: SpanKind;

/** A span's attributes */
attributes?: Attributes;
attributes?: SpanAttributes;

/** {@link Link}s span to other spans */
links?: Link[];
Expand Down
6 changes: 3 additions & 3 deletions api/src/trace/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/

export interface Attributes {
[attributeKey: string]: AttributeValue | undefined;
export interface SpanAttributes {
[attributeKey: string]: SpanAttributeValue | undefined;
}

/**
* Attribute values may be any non-nullish primitive value except an object.
*
* null or undefined attribute values are invalid and will result in undefined behavior.
*/
export type AttributeValue =
export type SpanAttributeValue =
| string
| number
| boolean
Expand Down
6 changes: 3 additions & 3 deletions api/src/trace/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Attributes } from './attributes';
import { SpanAttributes } from './attributes';
import { LinkContext } from './link_context';

/**
Expand All @@ -35,6 +35,6 @@ import { LinkContext } from './link_context';
export interface Link {
/** The {@link LinkContext} of a linked span. */
context: LinkContext;
/** A set of {@link Attributes} on the link. */
attributes?: Attributes;
/** A set of {@link SpanAttributes} on the link. */
attributes?: SpanAttributes;
}
16 changes: 8 additions & 8 deletions api/src/trace/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import { Exception } from '../common/Exception';
import { TimeInput } from '../common/Time';
import { Attributes, AttributeValue } from './attributes';
import { SpanAttributes, SpanAttributeValue } from './attributes';
import { SpanContext } from './span_context';
import { Status } from './status';
import { SpanStatus } from './status';

/**
* An interface that represents a span. A span represents a single operation
Expand Down Expand Up @@ -50,7 +50,7 @@ export interface Span {
* @param value the value for this attribute. Setting a value null or
* undefined is invalid and will result in undefined behavior.
*/
setAttribute(key: string, value: AttributeValue): this;
setAttribute(key: string, value: SpanAttributeValue): this;

/**
* Sets attributes to the span.
Expand All @@ -59,7 +59,7 @@ export interface Span {
* null or undefined attribute values
* are invalid and will result in undefined behavior.
*/
setAttributes(attributes: Attributes): this;
setAttributes(attributes: SpanAttributes): this;

/**
* Adds an event to the Span.
Expand All @@ -72,18 +72,18 @@ export interface Span {
*/
addEvent(
name: string,
attributesOrStartTime?: Attributes | TimeInput,
attributesOrStartTime?: SpanAttributes | TimeInput,
startTime?: TimeInput
): this;

/**
* 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.
* @param status the SpanStatus to set.
*/
setStatus(status: Status): this;
setStatus(status: SpanStatus): this;

/**
* Updates the Span name.
Expand Down
6 changes: 3 additions & 3 deletions api/src/trace/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface Status {
export interface SpanStatus {
/** 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 default status.
*/
Expand Down
4 changes: 2 additions & 2 deletions api/test/noop-implementations/noop-span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as assert from 'assert';
import {
StatusCode,
SpanStatusCode,
INVALID_SPANID,
INVALID_TRACEID,
NoopSpan,
Expand All @@ -39,7 +39,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

0 comments on commit 16f79e0

Please sign in to comment.