From dff68bbd40b21a73e946f7f037f177dc75047c1f Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Thu, 13 Jun 2019 14:24:03 -0700 Subject: [PATCH 01/12] Add initial span interface --- packages/opentelemetry-types/src/index.ts | 5 + .../opentelemetry-types/src/trace/span.ts | 105 ++++++++++++ .../src/trace/span_context.ts | 30 ++++ .../src/trace/span_kind.ts | 50 ++++++ .../opentelemetry-types/src/trace/status.ts | 161 ++++++++++++++++++ 5 files changed, 351 insertions(+) create mode 100644 packages/opentelemetry-types/src/trace/span.ts create mode 100644 packages/opentelemetry-types/src/trace/span_context.ts create mode 100644 packages/opentelemetry-types/src/trace/span_kind.ts create mode 100644 packages/opentelemetry-types/src/trace/status.ts diff --git a/packages/opentelemetry-types/src/index.ts b/packages/opentelemetry-types/src/index.ts index 62fb100a20..99e37437e9 100644 --- a/packages/opentelemetry-types/src/index.ts +++ b/packages/opentelemetry-types/src/index.ts @@ -13,3 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +export * from './trace/span'; +export * from './trace/span_context'; +export * from './trace/span_kind'; +export * from './trace/status'; diff --git a/packages/opentelemetry-types/src/trace/span.ts b/packages/opentelemetry-types/src/trace/span.ts new file mode 100644 index 0000000000..8f438b5199 --- /dev/null +++ b/packages/opentelemetry-types/src/trace/span.ts @@ -0,0 +1,105 @@ +/** + * 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 + * + * 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 { SpanContext } from './span_context'; +import { Status } from './status'; + +/** + * An interface that represents a span. A span represents a single operation + * within a trace. Examples of span might include remote procedure calls or a + * in-process function calls to sub-components. A Trace has a single, top-level + * "root" Span that in turn may have zero or more child Spans, which in turn + * may have children. + */ +export interface Span { + /** + * Returns the SpanContext object associated with this Span. + * + * @returns the SpanContext object associated with this Span. + */ + context(): SpanContext; + + // /** + // * # TODO + // * Returns the Tracer object used to create this Span. + // * https://github.com/open-telemetry/opentelemetry-specification/issues/21 + // */ + // tracer(): Tracer; + + /** + * Sets an attribute to the span. + * + * @param key the key for this attribute. + * @param value the value for this attribute. + */ + setAttribute(key: string, value: string | number | boolean | object): void; + + /** + * Adds an event to the Span. + * + * @param name the name of the event. + * @param [attributes] the attributes that will be added; these are + * associated with this event. + */ + addEvent( + name: string, + attributes?: { [key: string]: string | number | boolean } + ): void; + + /** + * Adds a link to the Span. + * + * @param spanContext the context of the linked span. + * @param [attributes] the attributes that will be added; these are + * associated with this link. + */ + addLink( + spanContext: SpanContext, + attributes?: { [key: string]: string | number | boolean } + ): void; + + /** + * Sets a status to the span. If used, this will override the default Span + * status. Default is 'OK'. + * + * @param status the Status to set. + */ + setStatus(status: Status): void; + + /** + * Updates the Span name. + * + * @param name the Span name. + */ + updateName(name: string): void; + + /** + * Marks the end of Span execution and sets the current time as the span's + * end time. + * + * Call to End of a Span MUST not have any effects on child spans. Those may + * still be running and can be ended later. + */ + end(): void; + + /** + * Returns the flag whether this span will be recorded. + * + * @returns true if this Span is active and recording information like events + * with the AddEvent operation and attributes using setAttributes. + */ + isRecordingEvents(): boolean; +} diff --git a/packages/opentelemetry-types/src/trace/span_context.ts b/packages/opentelemetry-types/src/trace/span_context.ts new file mode 100644 index 0000000000..474b9a9513 --- /dev/null +++ b/packages/opentelemetry-types/src/trace/span_context.ts @@ -0,0 +1,30 @@ +/** + * 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 + * + * 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. + */ + +/** + * A SpanContext represents the portion of a Span which must be serialized and + * propagated along side of a distributed context. + */ +export interface SpanContext { + /** The ID of the trace that this span belongs to. */ + traceId: string; + /** The ID of the Span. */ + spanId: string; + /** Trace options to propagate. */ + traceOptions?: number; + /** Tracing-system-specific info to propagate. */ + traceState?: string; +} diff --git a/packages/opentelemetry-types/src/trace/span_kind.ts b/packages/opentelemetry-types/src/trace/span_kind.ts new file mode 100644 index 0000000000..688650f2be --- /dev/null +++ b/packages/opentelemetry-types/src/trace/span_kind.ts @@ -0,0 +1,50 @@ +/** + * 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 + * + * 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. + */ + +/** + * Type of span. Can be used to specify additional relationships between spans + * in addition to a parent/child relationship. + */ +export enum SpanKind { + /** Default value. Indicates that the span is used internally. */ + INTERNAL = 0, + + /** + * Indicates that the span covers server-side handling of an RPC or other + * remote request. + */ + SERVER = 1, + + /** + * Indicates that the span covers the client-side wrapper around an RPC or + * other remote request. + */ + CLIENT = 2, + + /** + * Indicates that the span describes producer sending a message to a + * broker. Unlike client and server, there is no direct critical path latency + * relationship between producer and consumer spans. + */ + PRODUCER = 3, + + /** + * Indicates that the span describes consumer receiving a message from a + * broker. Unlike client and server, there is no direct critical path latency + * relationship between producer and consumer spans. + */ + CONSUMER = 4, +} diff --git a/packages/opentelemetry-types/src/trace/status.ts b/packages/opentelemetry-types/src/trace/status.ts new file mode 100644 index 0000000000..e34dbf4cc9 --- /dev/null +++ b/packages/opentelemetry-types/src/trace/status.ts @@ -0,0 +1,161 @@ +/** + * 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 + * + * 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. + */ + +/** + * The status of a Span by providing a standard CanonicalCode in conjunction + * with an optional descriptive message. + */ +export interface Status { + /** The canonical code of this message. */ + code: CanonicalCode; + /** A developer-facing error message. */ + message?: string; +} + +/** An enumeration of canonical status codes. */ +export enum CanonicalCode { + /** + * Not an error; returned on success + */ + OK = 0, + /** + * The operation was cancelled (typically by the caller). + */ + CANCELLED = 1, + /** + * Unknown error. An example of where this error may be returned is + * if a status value received from another address space belongs to + * an error-space that is not known in this address space. Also + * errors raised by APIs that do not return enough error information + * may be converted to this error. + */ + UNKNOWN = 2, + /** + * Client specified an invalid argument. Note that this differs + * from FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments + * that are problematic regardless of the state of the system + * (e.g., a malformed file name). + */ + INVALID_ARGUMENT = 3, + /** + * Deadline expired before operation could complete. For operations + * that change the state of the system, this error may be returned + * even if the operation has completed successfully. For example, a + * successful response from a server could have been delayed long + * enough for the deadline to expire. + */ + DEADLINE_EXCEEDED = 4, + /** + * Some requested entity (e.g., file or directory) was not found. + */ + NOT_FOUND = 5, + /** + * Some entity that we attempted to create (e.g., file or directory) + * already exists. + */ + ALREADY_EXISTS = 6, + /** + * The caller does not have permission to execute the specified + * operation. PERMISSION_DENIED must not be used for rejections + * caused by exhausting some resource (use RESOURCE_EXHAUSTED + * instead for those errors). PERMISSION_DENIED must not be + * used if the caller can not be identified (use UNAUTHENTICATED + * instead for those errors). + */ + PERMISSION_DENIED = 7, + /** + * Some resource has been exhausted, perhaps a per-user quota, or + * perhaps the entire file system is out of space. + */ + RESOURCE_EXHAUSTED = 8, + /** + * Operation was rejected because the system is not in a state + * required for the operation's execution. For example, directory + * to be deleted may be non-empty, an rmdir operation is applied to + * a non-directory, etc. + * + * A litmus test that may help a service implementor in deciding + * between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: + * + * - Use UNAVAILABLE if the client can retry just the failing call. + * - Use ABORTED if the client should retry at a higher-level + * (e.g., restarting a read-modify-write sequence). + * - Use FAILED_PRECONDITION if the client should not retry until + * the system state has been explicitly fixed. E.g., if an "rmdir" + * fails because the directory is non-empty, FAILED_PRECONDITION + * should be returned since the client should not retry unless + * they have first fixed up the directory by deleting files from it. + * - Use FAILED_PRECONDITION if the client performs conditional + * REST Get/Update/Delete on a resource and the resource on the + * server does not match the condition. E.g., conflicting + * read-modify-write on the same resource. + */ + FAILED_PRECONDITION = 9, + /** + * The operation was aborted, typically due to a concurrency issue + * like sequencer check failures, transaction aborts, etc. + * + * See litmus test above for deciding between FAILED_PRECONDITION, + * ABORTED, and UNAVAILABLE. + */ + ABORTED = 10, + /** + * Operation was attempted past the valid range. E.g., seeking or + * reading past end of file. + * + * Unlike INVALID_ARGUMENT, this error indicates a problem that may + * be fixed if the system state changes. For example, a 32-bit file + * system will generate INVALID_ARGUMENT if asked to read at an + * offset that is not in the range [0,2^32-1], but it will generate + * OUT_OF_RANGE if asked to read from an offset past the current + * file size. + * + * There is a fair bit of overlap between FAILED_PRECONDITION and + * OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific + * error) when it applies so that callers who are iterating through + * a space can easily look for an OUT_OF_RANGE error to detect when + * they are done. + */ + OUT_OF_RANGE = 11, + /** + * Operation is not implemented or not supported/enabled in this service. + */ + UNIMPLEMENTED = 12, + /** + * Internal errors. Means some invariants expected by underlying + * system has been broken. If you see one of these errors, + * something is very broken. + */ + INTERNAL = 13, + /** + * The service is currently unavailable. This is a most likely a + * transient condition and may be corrected by retrying with + * a backoff. + * + * See litmus test above for deciding between FAILED_PRECONDITION, + * ABORTED, and UNAVAILABLE. + */ + UNAVAILABLE = 14, + /** + * Unrecoverable data loss or corruption. + */ + DATA_LOSS = 15, + /** + * The request does not have valid authentication credentials for the + * operation. + */ + UNAUTHENTICATED = 16, +} From 231109577478d57e5b6de9526718946c4711e6ca Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Thu, 13 Jun 2019 21:04:56 -0700 Subject: [PATCH 02/12] Add object type attribute --- packages/opentelemetry-types/src/trace/span.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/opentelemetry-types/src/trace/span.ts b/packages/opentelemetry-types/src/trace/span.ts index 8f438b5199..1fecd97ac3 100644 --- a/packages/opentelemetry-types/src/trace/span.ts +++ b/packages/opentelemetry-types/src/trace/span.ts @@ -43,7 +43,8 @@ export interface Span { * Sets an attribute to the span. * * @param key the key for this attribute. - * @param value the value for this attribute. + * @param value the value for this attribute. If the value is a typeof object + * it has to be JSON.stringify-able otherwise it will raise an exception. */ setAttribute(key: string, value: string | number | boolean | object): void; @@ -56,7 +57,7 @@ export interface Span { */ addEvent( name: string, - attributes?: { [key: string]: string | number | boolean } + attributes?: { [key: string]: string | number | boolean | object } ): void; /** @@ -68,7 +69,7 @@ export interface Span { */ addLink( spanContext: SpanContext, - attributes?: { [key: string]: string | number | boolean } + attributes?: { [key: string]: string | number | boolean | object } ): void; /** From fafce9fdcfa776be42479dab2402bbbe00cd14f9 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Fri, 14 Jun 2019 10:47:57 -0700 Subject: [PATCH 03/12] return this and add optional endTime --- .../opentelemetry-types/src/trace/span.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/opentelemetry-types/src/trace/span.ts b/packages/opentelemetry-types/src/trace/span.ts index 1fecd97ac3..c3a4bccc8d 100644 --- a/packages/opentelemetry-types/src/trace/span.ts +++ b/packages/opentelemetry-types/src/trace/span.ts @@ -43,10 +43,9 @@ export interface Span { * Sets an attribute to the span. * * @param key the key for this attribute. - * @param value the value for this attribute. If the value is a typeof object - * it has to be JSON.stringify-able otherwise it will raise an exception. + * @param value the value for this attribute. */ - setAttribute(key: string, value: string | number | boolean | object): void; + setAttribute(key: string, value: string | number | boolean | object): this; /** * Adds an event to the Span. @@ -58,7 +57,7 @@ export interface Span { addEvent( name: string, attributes?: { [key: string]: string | number | boolean | object } - ): void; + ): this; /** * Adds a link to the Span. @@ -70,7 +69,7 @@ export interface Span { addLink( spanContext: SpanContext, attributes?: { [key: string]: string | number | boolean | object } - ): void; + ): this; /** * Sets a status to the span. If used, this will override the default Span @@ -78,23 +77,28 @@ export interface Span { * * @param status the Status to set. */ - setStatus(status: Status): void; + setStatus(status: Status): this; /** * Updates the Span name. * * @param name the Span name. */ - updateName(name: string): void; + updateName(name: string): this; /** - * Marks the end of Span execution and sets the current time as the span's - * end time. + * Marks the end of Span execution. * * Call to End of a Span MUST not have any effects on child spans. Those may * still be running and can be ended later. + * + * Do not return `this`. The Span generally should not be used after it + * is ended so chaining is not desired in this context. + * + * @param [endTime] the timestamp to set as Span's end time. If not provided, + * use the current time as the span's end time. */ - end(): void; + end(endTime?: number): void; /** * Returns the flag whether this span will be recorded. From db13c94a38c96bbf9ec0ed8e12e88ee7804da545 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Fri, 14 Jun 2019 14:19:31 -0700 Subject: [PATCH 04/12] Use any and add TODO --- packages/opentelemetry-types/src/trace/span.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/opentelemetry-types/src/trace/span.ts b/packages/opentelemetry-types/src/trace/span.ts index c3a4bccc8d..4e79217cae 100644 --- a/packages/opentelemetry-types/src/trace/span.ts +++ b/packages/opentelemetry-types/src/trace/span.ts @@ -45,7 +45,8 @@ export interface Span { * @param key the key for this attribute. * @param value the value for this attribute. */ - setAttribute(key: string, value: string | number | boolean | object): this; + //tslint:disable-next-line:no-any + setAttribute(key: string, value: any): this; /** * Adds an event to the Span. @@ -54,10 +55,8 @@ export interface Span { * @param [attributes] the attributes that will be added; these are * associated with this event. */ - addEvent( - name: string, - attributes?: { [key: string]: string | number | boolean | object } - ): this; + //tslint:disable-next-line:no-any + addEvent(name: string, attributes?: { [key: string]: any }): this; /** * Adds a link to the Span. @@ -66,10 +65,8 @@ export interface Span { * @param [attributes] the attributes that will be added; these are * associated with this link. */ - addLink( - spanContext: SpanContext, - attributes?: { [key: string]: string | number | boolean | object } - ): this; + //tslint:disable-next-line:no-any + addLink(spanContext: SpanContext, attributes?: { [key: string]: any }): this; /** * Sets a status to the span. If used, this will override the default Span @@ -82,6 +79,8 @@ export interface Span { /** * Updates the Span name. * + * TODO (revision): https://github.com/open-telemetry/opentelemetry-specification/issues/119 + * * @param name the Span name. */ updateName(name: string): this; From 52e53abd9d8e93f470bcba66db47d3edf39fe242 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Fri, 14 Jun 2019 15:23:57 -0700 Subject: [PATCH 05/12] Update TraceState with examples and add TODO --- .../src/trace/span_context.ts | 25 +++++++++++++++++-- .../opentelemetry-types/src/trace/status.ts | 6 ++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/opentelemetry-types/src/trace/span_context.ts b/packages/opentelemetry-types/src/trace/span_context.ts index 474b9a9513..e136f74b01 100644 --- a/packages/opentelemetry-types/src/trace/span_context.ts +++ b/packages/opentelemetry-types/src/trace/span_context.ts @@ -23,8 +23,29 @@ export interface SpanContext { traceId: string; /** The ID of the Span. */ spanId: string; - /** Trace options to propagate. */ + /** + * Trace options to propagate. + * + * It is represented as 1 byte (bitmap). Bit to represent whether trace is + * sampled or not. + * SAMPLED_VALUE = 0x1 and NOT_SAMPLED_VALUE = 0x0; + */ traceOptions?: number; - /** Tracing-system-specific info to propagate. */ + /** + * Tracing-system-specific info to propagate. + * + * The tracestate field value is a `list` as defined below. The `list` is a + * series of `list-members` separated by commas `,`, and a list-member is a + * key/value pair separated by an equals sign `=`. Spaces and horizontal tabs + * surrounding `list-members` are ignored. There can be a maximum of 32 + * `list-members` in a `list`. + * More Info: https://www.w3.org/TR/trace-context/#tracestate-field + * + * Examples: + * Single tracing system (generic format): + * tracestate: rojo=00f067aa0ba902b7 + * Multiple tracing systems (with different formatting): + * tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE + */ traceState?: string; } diff --git a/packages/opentelemetry-types/src/trace/status.ts b/packages/opentelemetry-types/src/trace/status.ts index e34dbf4cc9..be84093ce1 100644 --- a/packages/opentelemetry-types/src/trace/status.ts +++ b/packages/opentelemetry-types/src/trace/status.ts @@ -25,7 +25,11 @@ export interface Status { message?: string; } -/** An enumeration of canonical status codes. */ +/** + * An enumeration of canonical status codes. + * + * TODO (revision): https://github.com/open-telemetry/opentelemetry-specification/issues/59 + */ export enum CanonicalCode { /** * Not an error; returned on success From 424c9fde98a16f69f6893f6e5550695be2c9cb32 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Sun, 16 Jun 2019 23:02:52 -0700 Subject: [PATCH 06/12] specify traceId and spanId format --- .../opentelemetry-types/src/trace/span_context.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry-types/src/trace/span_context.ts b/packages/opentelemetry-types/src/trace/span_context.ts index e136f74b01..f2a183aa90 100644 --- a/packages/opentelemetry-types/src/trace/span_context.ts +++ b/packages/opentelemetry-types/src/trace/span_context.ts @@ -19,9 +19,18 @@ * propagated along side of a distributed context. */ export interface SpanContext { - /** The ID of the trace that this span belongs to. */ + /** + * The ID of the trace that this span belongs to. It is worldwide unique + * with practically sufficient probability by being made as 16 randomly + * generated bytes, encoded as a 32 lowercase hex characters corresponding to + * 128 bits. + */ traceId: string; - /** The ID of the Span. */ + /** + * The ID of the Span. It is globally unique with practically sufficient + * probability by being made as 8 randomly generated bytes, encoded as a 16 + * lowercase hex characters corresponding to 64 bits. + */ spanId: string; /** * Trace options to propagate. From d969247a07cc2f0d8652209fc4c83a530684879e Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Mon, 17 Jun 2019 10:22:25 -0700 Subject: [PATCH 07/12] use unknown instead of any --- packages/opentelemetry-types/src/trace/span.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/opentelemetry-types/src/trace/span.ts b/packages/opentelemetry-types/src/trace/span.ts index 4e79217cae..9f2188266c 100644 --- a/packages/opentelemetry-types/src/trace/span.ts +++ b/packages/opentelemetry-types/src/trace/span.ts @@ -45,8 +45,7 @@ export interface Span { * @param key the key for this attribute. * @param value the value for this attribute. */ - //tslint:disable-next-line:no-any - setAttribute(key: string, value: any): this; + setAttribute(key: string, value: unknown): this; /** * Adds an event to the Span. @@ -55,8 +54,7 @@ export interface Span { * @param [attributes] the attributes that will be added; these are * associated with this event. */ - //tslint:disable-next-line:no-any - addEvent(name: string, attributes?: { [key: string]: any }): this; + addEvent(name: string, attributes?: { [key: string]: unknown }): this; /** * Adds a link to the Span. @@ -65,8 +63,7 @@ export interface Span { * @param [attributes] the attributes that will be added; these are * associated with this link. */ - //tslint:disable-next-line:no-any - addLink(spanContext: SpanContext, attributes?: { [key: string]: any }): this; + addLink(spanContext: SpanContext, attributes?: { [key: string]: unknown }): this; /** * Sets a status to the span. If used, this will override the default Span From 01d1340a0ada291b60970a8abe8927a463b6a898 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Mon, 17 Jun 2019 17:08:54 -0700 Subject: [PATCH 08/12] Add TraceOptions and TraceState empty class --- .../src/trace/span_context.ts | 7 +++++-- .../src/trace/traceoptions.ts | 19 +++++++++++++++++++ .../src/trace/tracestate.ts | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 packages/opentelemetry-types/src/trace/traceoptions.ts create mode 100644 packages/opentelemetry-types/src/trace/tracestate.ts diff --git a/packages/opentelemetry-types/src/trace/span_context.ts b/packages/opentelemetry-types/src/trace/span_context.ts index f2a183aa90..98d06dfa46 100644 --- a/packages/opentelemetry-types/src/trace/span_context.ts +++ b/packages/opentelemetry-types/src/trace/span_context.ts @@ -14,6 +14,9 @@ * limitations under the License. */ +import { TraceState } from './tracestate'; +import { TraceOptions } from './traceoptions'; + /** * A SpanContext represents the portion of a Span which must be serialized and * propagated along side of a distributed context. @@ -39,7 +42,7 @@ export interface SpanContext { * sampled or not. * SAMPLED_VALUE = 0x1 and NOT_SAMPLED_VALUE = 0x0; */ - traceOptions?: number; + traceOptions?: TraceOptions; /** * Tracing-system-specific info to propagate. * @@ -56,5 +59,5 @@ export interface SpanContext { * Multiple tracing systems (with different formatting): * tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE */ - traceState?: string; + traceState?: TraceState; } diff --git a/packages/opentelemetry-types/src/trace/traceoptions.ts b/packages/opentelemetry-types/src/trace/traceoptions.ts new file mode 100644 index 0000000000..f80d46cabb --- /dev/null +++ b/packages/opentelemetry-types/src/trace/traceoptions.ts @@ -0,0 +1,19 @@ +/** + * 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 + * + * 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. + */ + +export class TraceOptions { + // TODO +} diff --git a/packages/opentelemetry-types/src/trace/tracestate.ts b/packages/opentelemetry-types/src/trace/tracestate.ts new file mode 100644 index 0000000000..95fbd90969 --- /dev/null +++ b/packages/opentelemetry-types/src/trace/tracestate.ts @@ -0,0 +1,19 @@ +/** + * 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 + * + * 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. + */ + +export class TraceState { + // TODO +} From 53b8093f149276b1adc54ce37bd71e377085a5e7 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Mon, 17 Jun 2019 22:42:45 -0700 Subject: [PATCH 09/12] Add Link and Attributes interfaces --- .../src/trace/attributes.ts | 20 +++++++++++++ .../opentelemetry-types/src/trace/link.ts | 29 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 packages/opentelemetry-types/src/trace/attributes.ts create mode 100644 packages/opentelemetry-types/src/trace/link.ts diff --git a/packages/opentelemetry-types/src/trace/attributes.ts b/packages/opentelemetry-types/src/trace/attributes.ts new file mode 100644 index 0000000000..b2758be2ba --- /dev/null +++ b/packages/opentelemetry-types/src/trace/attributes.ts @@ -0,0 +1,20 @@ +/** + * 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 + * + * 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. + */ + + /** Defines a attributes interface. */ +export interface Attributes { + [attributeKey: string]: unknown; +} diff --git a/packages/opentelemetry-types/src/trace/link.ts b/packages/opentelemetry-types/src/trace/link.ts new file mode 100644 index 0000000000..0bc4763d8a --- /dev/null +++ b/packages/opentelemetry-types/src/trace/link.ts @@ -0,0 +1,29 @@ +/** + * 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 + * + * 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 { Attributes } from './attributes'; +import { SpanContext } from './span_context'; + +/** + * A pointer from the current span to another span in the same trace or in a + * different trace. + */ +export interface Link { + /** The SpanContext of a linked span. */ + spanContext: SpanContext; + /** A set of attributes on the link. */ + attributes: Attributes; +} From 595465cc1d61e5cf0033c9aee0fbb8dc767b4a0a Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Mon, 17 Jun 2019 22:45:49 -0700 Subject: [PATCH 10/12] update index.ts --- packages/opentelemetry-types/src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/opentelemetry-types/src/index.ts b/packages/opentelemetry-types/src/index.ts index 99e37437e9..d1274a20a3 100644 --- a/packages/opentelemetry-types/src/index.ts +++ b/packages/opentelemetry-types/src/index.ts @@ -18,3 +18,7 @@ export * from './trace/span'; export * from './trace/span_context'; export * from './trace/span_kind'; export * from './trace/status'; +export * from './trace/link'; +export * from './trace/attributes'; +export * from './trace/traceoptions'; +export * from './trace/tracestate'; From f1d2b7e6f9b023cae44710157e99ec9f2d803f6b Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Tue, 18 Jun 2019 13:21:59 -0700 Subject: [PATCH 11/12] Change Link:attributes as optional property --- packages/opentelemetry-types/src/trace/link.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opentelemetry-types/src/trace/link.ts b/packages/opentelemetry-types/src/trace/link.ts index 0bc4763d8a..aafbef2bbd 100644 --- a/packages/opentelemetry-types/src/trace/link.ts +++ b/packages/opentelemetry-types/src/trace/link.ts @@ -25,5 +25,5 @@ export interface Link { /** The SpanContext of a linked span. */ spanContext: SpanContext; /** A set of attributes on the link. */ - attributes: Attributes; + attributes?: Attributes; } From 5c92e516b752424ab48cce739b24b814553eb021 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Tue, 18 Jun 2019 20:01:40 -0700 Subject: [PATCH 12/12] Fix review comments --- packages/opentelemetry-types/src/index.ts | 4 ++-- packages/opentelemetry-types/src/trace/attributes.ts | 2 +- packages/opentelemetry-types/src/trace/span.ts | 6 +++++- packages/opentelemetry-types/src/trace/span_context.ts | 4 ++-- .../src/trace/{tracestate.ts => trace_options.ts} | 2 +- .../src/trace/{traceoptions.ts => trace_state.ts} | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) rename packages/opentelemetry-types/src/trace/{tracestate.ts => trace_options.ts} (95%) rename packages/opentelemetry-types/src/trace/{traceoptions.ts => trace_state.ts} (95%) diff --git a/packages/opentelemetry-types/src/index.ts b/packages/opentelemetry-types/src/index.ts index d1274a20a3..9f68cbb66f 100644 --- a/packages/opentelemetry-types/src/index.ts +++ b/packages/opentelemetry-types/src/index.ts @@ -20,5 +20,5 @@ export * from './trace/span_kind'; export * from './trace/status'; export * from './trace/link'; export * from './trace/attributes'; -export * from './trace/traceoptions'; -export * from './trace/tracestate'; +export * from './trace/trace_options'; +export * from './trace/trace_state'; diff --git a/packages/opentelemetry-types/src/trace/attributes.ts b/packages/opentelemetry-types/src/trace/attributes.ts index b2758be2ba..a9fecfac5f 100644 --- a/packages/opentelemetry-types/src/trace/attributes.ts +++ b/packages/opentelemetry-types/src/trace/attributes.ts @@ -14,7 +14,7 @@ * limitations under the License. */ - /** Defines a attributes interface. */ +/** Defines a attributes interface. */ export interface Attributes { [attributeKey: string]: unknown; } diff --git a/packages/opentelemetry-types/src/trace/span.ts b/packages/opentelemetry-types/src/trace/span.ts index 9f2188266c..d5831a1c08 100644 --- a/packages/opentelemetry-types/src/trace/span.ts +++ b/packages/opentelemetry-types/src/trace/span.ts @@ -63,7 +63,10 @@ export interface Span { * @param [attributes] the attributes that will be added; these are * associated with this link. */ - addLink(spanContext: SpanContext, attributes?: { [key: string]: unknown }): this; + addLink( + spanContext: SpanContext, + attributes?: { [key: string]: unknown } + ): this; /** * Sets a status to the span. If used, this will override the default Span @@ -93,6 +96,7 @@ export interface Span { * * @param [endTime] the timestamp to set as Span's end time. If not provided, * use the current time as the span's end time. + * TODO (Add timestamp format): https://github.com/open-telemetry/opentelemetry-js/issues/19 */ end(endTime?: number): void; diff --git a/packages/opentelemetry-types/src/trace/span_context.ts b/packages/opentelemetry-types/src/trace/span_context.ts index 98d06dfa46..142db46c6c 100644 --- a/packages/opentelemetry-types/src/trace/span_context.ts +++ b/packages/opentelemetry-types/src/trace/span_context.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { TraceState } from './tracestate'; -import { TraceOptions } from './traceoptions'; +import { TraceState } from './trace_state'; +import { TraceOptions } from './trace_options'; /** * A SpanContext represents the portion of a Span which must be serialized and diff --git a/packages/opentelemetry-types/src/trace/tracestate.ts b/packages/opentelemetry-types/src/trace/trace_options.ts similarity index 95% rename from packages/opentelemetry-types/src/trace/tracestate.ts rename to packages/opentelemetry-types/src/trace/trace_options.ts index 95fbd90969..dfefc751ba 100644 --- a/packages/opentelemetry-types/src/trace/tracestate.ts +++ b/packages/opentelemetry-types/src/trace/trace_options.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -export class TraceState { +export interface TraceOptions { // TODO } diff --git a/packages/opentelemetry-types/src/trace/traceoptions.ts b/packages/opentelemetry-types/src/trace/trace_state.ts similarity index 95% rename from packages/opentelemetry-types/src/trace/traceoptions.ts rename to packages/opentelemetry-types/src/trace/trace_state.ts index f80d46cabb..03c52af68b 100644 --- a/packages/opentelemetry-types/src/trace/traceoptions.ts +++ b/packages/opentelemetry-types/src/trace/trace_state.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -export class TraceOptions { +export interface TraceState { // TODO }