Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 62ab43d

Browse files
Upgrade @opencensus/core dependency (#13)
1 parent 89561ae commit 62ab43d

20 files changed

Lines changed: 413 additions & 313 deletions

File tree

.circleci/config.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ jobs:
3232
# fallback to using the latest cache if no exact match is found
3333
- v1-dependencies-
3434

35-
# Remove the mocha type references in @opencensus/core. This has been
36-
# fixed in the upstream package on GitHub, but has not been released on
37-
# NPM yet. We can't install the package directly from GitHub because NPM
38-
# only supports that for packages in the root folder of the repo.
39-
# See https://github.com/census-instrumentation/opencensus-node/pull/254
40-
- run: npm install || true
41-
- run: find . -type f | grep '@opencensus/core' | xargs sed -i '/types="mocha"/d'
42-
4335
- run: npm install
4436

4537
- save_cache:

packages/opencensus-web-core/package-lock.json

Lines changed: 7 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/opencensus-web-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"access": "public"
4343
},
4444
"devDependencies": {
45-
"@opencensus/core": "^0.0.8",
45+
"@opencensus/core": "^0.0.9",
4646
"@types/jasmine": "^3.3.4",
4747
"@types/node": "^10.12.18",
4848
"gts": "^0.9.0",

packages/opencensus-web-core/src/common/console-logger.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/opencensus-web-core/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ export {RootSpan} from './trace/model/root-span';
1919
export {Span} from './trace/model/span';
2020
export {Tracer} from './trace/model/tracer';
2121
export {Tracing} from './trace/model/tracing';
22-
export * from './trace/model/types';
22+
export * from './trace/model/enums';
2323
export * from './trace/model/attribute-keys';
2424

2525
// Re-export types this uses from @opencensus/core.
26-
export {Annotation, Attributes, Link, SpanContext, SpanEventListener, TraceState, Propagation, Exporter, TracerConfig, Config} from '@opencensus/core';
26+
export {Annotation, Attributes, Config, Exporter, Link, MessageEvent, Propagation, SpanContext, SpanEventListener, TracerConfig, TraceState} from '@opencensus/core';
2727

2828
export * from './common/time-util';
2929
export * from './common/url-util';
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
/**
2+
* Copyright 2019, OpenCensus Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* @fileoverview Trace related enums. These can't be directly imported from
19+
* `@opencensus/core`, because that will create a runtime dependency on it.
20+
* That is because TypeScript enums have a runtime existence, unlike interfaces.
21+
* A runtime dependency on `@opencensus/core` is not good for OpenCensus Web,
22+
* because then it would need to depend on other Node libraries.
23+
* These enums are based on @opencensus/core and the Trace protos. See:
24+
* https://github.com/census-instrumentation/opencensus-proto/blob/master/src/opencensus/proto/trace/v1/trace.proto
25+
* https://github.com/census-instrumentation/opencensus-node/blob/master/packages/opencensus-core/src/trace/model/types.ts#L44
26+
*/
27+
28+
/**
29+
* Type of link. The relationship of the current span relative to the linked
30+
* span.
31+
*/
32+
export enum LinkType {
33+
/**
34+
* The relationship of the two spans is unknown, or known but other
35+
* than parent-child.
36+
*/
37+
UNSPECIFIED = 0,
38+
/** The linked span is a child of the current span. */
39+
CHILD_LINKED_SPAN = 1,
40+
/** The linked span is a parent of the current span. */
41+
PARENT_LINKED_SPAN = 2,
42+
}
43+
44+
/**
45+
* Type of span. Can be used to specify additional relationships between spans
46+
* in addition to a parent/child relationship.
47+
*/
48+
export enum SpanKind {
49+
/** Unspecified */
50+
UNSPECIFIED = 0,
51+
/**
52+
* Indicates that the span covers server-side handling of an RPC or other
53+
* remote network request.
54+
*/
55+
SERVER = 1,
56+
/**
57+
* Indicates that the span covers the client-side wrapper around an RPC or
58+
* other remote request.
59+
*/
60+
CLIENT = 2,
61+
}
62+
63+
/** An enumeration of canonical status codes. */
64+
export enum CanonicalCode {
65+
/**
66+
* Not an error; returned on success
67+
*/
68+
OK = 0,
69+
/**
70+
* The operation was cancelled (typically by the caller).
71+
*/
72+
CANCELLED = 1,
73+
/**
74+
* Unknown error. An example of where this error may be returned is
75+
* if a status value received from another address space belongs to
76+
* an error-space that is not known in this address space. Also
77+
* errors raised by APIs that do not return enough error information
78+
* may be converted to this error.
79+
*/
80+
UNKNOWN = 2,
81+
/**
82+
* Client specified an invalid argument. Note that this differs
83+
* from FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments
84+
* that are problematic regardless of the state of the system
85+
* (e.g., a malformed file name).
86+
*/
87+
INVALID_ARGUMENT = 3,
88+
/**
89+
* Deadline expired before operation could complete. For operations
90+
* that change the state of the system, this error may be returned
91+
* even if the operation has completed successfully. For example, a
92+
* successful response from a server could have been delayed long
93+
* enough for the deadline to expire.
94+
*/
95+
DEADLINE_EXCEEDED = 4,
96+
/**
97+
* Some requested entity (e.g., file or directory) was not found.
98+
*/
99+
NOT_FOUND = 5,
100+
/**
101+
* Some entity that we attempted to create (e.g., file or directory)
102+
* already exists.
103+
*/
104+
ALREADY_EXISTS = 6,
105+
/**
106+
* The caller does not have permission to execute the specified
107+
* operation. PERMISSION_DENIED must not be used for rejections
108+
* caused by exhausting some resource (use RESOURCE_EXHAUSTED
109+
* instead for those errors). PERMISSION_DENIED must not be
110+
* used if the caller can not be identified (use UNAUTHENTICATED
111+
* instead for those errors).
112+
*/
113+
PERMISSION_DENIED = 7,
114+
/**
115+
* Some resource has been exhausted, perhaps a per-user quota, or
116+
* perhaps the entire file system is out of space.
117+
*/
118+
RESOURCE_EXHAUSTED = 8,
119+
/**
120+
* Operation was rejected because the system is not in a state
121+
* required for the operation's execution. For example, directory
122+
* to be deleted may be non-empty, an rmdir operation is applied to
123+
* a non-directory, etc.
124+
*
125+
* A litmus test that may help a service implementor in deciding
126+
* between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE:
127+
*
128+
* - Use UNAVAILABLE if the client can retry just the failing call.
129+
* - Use ABORTED if the client should retry at a higher-level
130+
* (e.g., restarting a read-modify-write sequence).
131+
* - Use FAILED_PRECONDITION if the client should not retry until
132+
* the system state has been explicitly fixed. E.g., if an "rmdir"
133+
* fails because the directory is non-empty, FAILED_PRECONDITION
134+
* should be returned since the client should not retry unless
135+
* they have first fixed up the directory by deleting files from it.
136+
* - Use FAILED_PRECONDITION if the client performs conditional
137+
* REST Get/Update/Delete on a resource and the resource on the
138+
* server does not match the condition. E.g., conflicting
139+
* read-modify-write on the same resource.
140+
*/
141+
FAILED_PRECONDITION = 9,
142+
/**
143+
* The operation was aborted, typically due to a concurrency issue
144+
* like sequencer check failures, transaction aborts, etc.
145+
*
146+
* See litmus test above for deciding between FAILED_PRECONDITION,
147+
* ABORTED, and UNAVAILABLE.
148+
*/
149+
ABORTED = 10,
150+
/**
151+
* Operation was attempted past the valid range. E.g., seeking or
152+
* reading past end of file.
153+
*
154+
* Unlike INVALID_ARGUMENT, this error indicates a problem that may
155+
* be fixed if the system state changes. For example, a 32-bit file
156+
* system will generate INVALID_ARGUMENT if asked to read at an
157+
* offset that is not in the range [0,2^32-1], but it will generate
158+
* OUT_OF_RANGE if asked to read from an offset past the current
159+
* file size.
160+
*
161+
* There is a fair bit of overlap between FAILED_PRECONDITION and
162+
* OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific
163+
* error) when it applies so that callers who are iterating through
164+
* a space can easily look for an OUT_OF_RANGE error to detect when
165+
* they are done.
166+
*/
167+
OUT_OF_RANGE = 11,
168+
/**
169+
* Operation is not implemented or not supported/enabled in this service.
170+
*/
171+
UNIMPLEMENTED = 12,
172+
/**
173+
* Internal errors. Means some invariants expected by underlying
174+
* system has been broken. If you see one of these errors,
175+
* something is very broken.
176+
*/
177+
INTERNAL = 13,
178+
/**
179+
* The service is currently unavailable. This is a most likely a
180+
* transient condition and may be corrected by retrying with
181+
* a backoff.
182+
*
183+
* See litmus test above for deciding between FAILED_PRECONDITION,
184+
* ABORTED, and UNAVAILABLE.
185+
*/
186+
UNAVAILABLE = 14,
187+
/**
188+
* Unrecoverable data loss or corruption.
189+
*/
190+
DATA_LOSS = 15,
191+
/**
192+
* The request does not have valid authentication credentials for the
193+
* operation.
194+
*/
195+
UNAUTHENTICATED = 16,
196+
}
197+
198+
/** An event describing a message sent/received between Spans. */
199+
export enum MessageEventType {
200+
/** Unknown event type. */
201+
UNSPECIFIED = 0,
202+
/** Indicates a sent message. */
203+
SENT = 1,
204+
/** Indicates a received message. */
205+
RECEIVED = 2,
206+
}

packages/opencensus-web-core/src/trace/model/root-span.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import * as coreTypes from '@opencensus/core';
1818
import {randomTraceId} from '../../internal/util';
19+
import {SpanKind} from './enums';
1920
import {Span} from './span';
20-
import {SpanKind} from './types';
2121

2222
/** Simple mock root span for use in use tests. */
2323
export class RootSpan extends Span implements coreTypes.RootSpan {
@@ -46,13 +46,27 @@ export class RootSpan extends Span implements coreTypes.RootSpan {
4646
}
4747
}
4848

49-
startChildSpan(name?: string, kind?: string): Span {
49+
/**
50+
* Starts a new child span in the root span.
51+
* @param nameOrOptions Span name string or object with `name` and `kind`
52+
* @param kind Span kind if not using options object.
53+
*/
54+
startChildSpan(
55+
nameOrOptions?: string|{name: string, kind: SpanKind},
56+
kind?: SpanKind): Span {
5057
const child = new Span();
5158
child.traceId = this.traceId;
5259
child.traceState = this.traceState;
53-
if (name) child.name = name;
54-
if (kind) child.kind = kind;
60+
61+
const spanName =
62+
typeof nameOrOptions === 'object' ? nameOrOptions.name : nameOrOptions;
63+
const spanKind =
64+
typeof nameOrOptions === 'object' ? nameOrOptions.kind : kind;
65+
if (spanName) child.name = spanName;
66+
if (spanKind) child.kind = spanKind;
67+
5568
child.start();
69+
child.parentSpanId = this.id;
5670
this.spans.push(child);
5771
return child;
5872
}

0 commit comments

Comments
 (0)