Skip to content

Commit b8470f0

Browse files
feat/otel tracing structures
1 parent 5cacc81 commit b8470f0

7 files changed

Lines changed: 268 additions & 16 deletions

File tree

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@
1717
"packages/vue"
1818
],
1919
"devDependencies": {
20+
"@types/jest": "^29.2.0",
2021
"@types/node": "10.17.0",
22+
"@types/react": "^16.9.49",
23+
"@types/react-dom": "^16.9.8",
2124
"@types/rimraf": "^3.0.2",
22-
"jsdom": "^19.0.0",
23-
"lerna": "6.5.0-alpha.2",
24-
"tslib": "^2.3.1",
25-
"ts-loader": "^9.4.2",
26-
"typescript": "^4.7.4",
27-
"@types/jest": "^29.2.0",
2825
"eslint": "^8.8.0",
2926
"jest": "^26.5.5",
30-
"os": "^0.1.2",
31-
"prettier-check": "^2.0.0",
32-
"rollup": "^2.66.1",
33-
"ts-node": "^10.4.0",
34-
"tslint": "^5.11.0",
35-
"@types/react": "^16.9.49",
36-
"@types/react-dom": "^16.9.8",
27+
"jsdom": "^19.0.0",
28+
"lerna": "6.5.0-alpha.2",
3729
"lint-staged": "^10.5.3",
3830
"npm-run-all": "^4.1.5",
31+
"os": "^0.1.2",
3932
"prettier": "2.1.2",
33+
"prettier-check": "^2.0.0",
4034
"react": "^18.1.0",
4135
"react-dom": "^18.1.0",
4236
"rimraf": "^3.0.2",
37+
"rollup": "^2.66.1",
38+
"ts-loader": "^9.4.2",
39+
"ts-node": "^10.4.0",
40+
"tslib": "^2.3.1",
41+
"tslint": "^5.11.0",
42+
"typescript": "^4.7.4",
4343
"webpack": "^5.11.0"
4444
},
4545
"jest": {

packages/node-core/src/types/http.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ export enum CAPTURE_ENDPOINT {
2626
LOG = "/api/capture/log",
2727
INCIDENT = "/api/capture/incident",
2828
RUNTIME = "/api/capture/runtime",
29-
METRICS = "/api/capture/metrics"
29+
METRICS = "/api/capture/metrics",
30+
TRACING = "/api/capture/traces"
3031
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./metrics";
2+
export * from "./tracing";
File renamed without changes.
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
import { Attributes, HrTime } from "./metrics";
2+
3+
/**
4+
* Types from Open Telemetry repository: https://github.com/open-telemetry/opentelemetry-js
5+
*/
6+
7+
8+
export declare enum SpanKind {
9+
/** Default value. Indicates that the span is used internally. */
10+
INTERNAL = 0,
11+
/**
12+
* Indicates that the span covers server-side handling of an RPC or other
13+
* remote request.
14+
*/
15+
SERVER = 1,
16+
/**
17+
* Indicates that the span covers the client-side wrapper around an RPC or
18+
* other remote request.
19+
*/
20+
CLIENT = 2,
21+
/**
22+
* Indicates that the span describes producer sending a message to a
23+
* broker. Unlike client and server, there is no direct critical path latency
24+
* relationship between producer and consumer spans.
25+
*/
26+
PRODUCER = 3,
27+
/**
28+
* Indicates that the span describes consumer receiving a message from a
29+
* broker. Unlike client and server, there is no direct critical path latency
30+
* relationship between producer and consumer spans.
31+
*/
32+
CONSUMER = 4
33+
}
34+
35+
export interface TraceState {
36+
/**
37+
* Create a new TraceState which inherits from this TraceState and has the
38+
* given key set.
39+
* The new entry will always be added in the front of the list of states.
40+
*
41+
* @param key key of the TraceState entry.
42+
* @param value value of the TraceState entry.
43+
*/
44+
set(key: string, value: string): TraceState;
45+
/**
46+
* Return a new TraceState which inherits from this TraceState but does not
47+
* contain the given key.
48+
*
49+
* @param key the key for the TraceState entry to be removed.
50+
*/
51+
unset(key: string): TraceState;
52+
/**
53+
* Returns the value to which the specified key is mapped, or `undefined` if
54+
* this map contains no mapping for the key.
55+
*
56+
* @param key with which the specified value is to be associated.
57+
* @returns the value to which the specified key is mapped, or `undefined` if
58+
* this map contains no mapping for the key.
59+
*/
60+
get(key: string): string | undefined;
61+
/**
62+
* Serializes the TraceState to a `list` as defined below. The `list` is a
63+
* series of `list-members` separated by commas `,`, and a list-member is a
64+
* key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
65+
* surrounding `list-members` are ignored. There can be a maximum of 32
66+
* `list-members` in a `list`.
67+
*
68+
* @returns the serialized string.
69+
*/
70+
serialize(): string;
71+
}
72+
73+
/**
74+
* A SpanContext represents the portion of a {@link Span} which must be
75+
* serialized and propagated along side of a {@link Baggage}.
76+
*/
77+
export interface SpanContext {
78+
/**
79+
* The ID of the trace that this span belongs to. It is worldwide unique
80+
* with practically sufficient probability by being made as 16 randomly
81+
* generated bytes, encoded as a 32 lowercase hex characters corresponding to
82+
* 128 bits.
83+
*/
84+
traceId: string;
85+
/**
86+
* The ID of the Span. It is globally unique with practically sufficient
87+
* probability by being made as 8 randomly generated bytes, encoded as a 16
88+
* lowercase hex characters corresponding to 64 bits.
89+
*/
90+
spanId: string;
91+
/**
92+
* Only true if the SpanContext was propagated from a remote parent.
93+
*/
94+
isRemote?: boolean;
95+
/**
96+
* Trace flags to propagate.
97+
*
98+
* It is represented as 1 byte (bitmap). Bit to represent whether trace is
99+
* sampled or not. When set, the least significant bit documents that the
100+
* caller may have recorded trace data. A caller who does not record trace
101+
* data out-of-band leaves this flag unset.
102+
*
103+
* see {@link TraceFlags} for valid flag values.
104+
*/
105+
traceFlags: number;
106+
/**
107+
* Tracing-system-specific info to propagate.
108+
*
109+
* The tracestate field value is a `list` as defined below. The `list` is a
110+
* series of `list-members` separated by commas `,`, and a list-member is a
111+
* key/value pair separated by an equals sign `=`. Spaces and horizontal tabs
112+
* surrounding `list-members` are ignored. There can be a maximum of 32
113+
* `list-members` in a `list`.
114+
* More Info: https://www.w3.org/TR/trace-context/#tracestate-field
115+
*
116+
* Examples:
117+
* Single tracing system (generic format):
118+
* tracestate: rojo=00f067aa0ba902b7
119+
* Multiple tracing systems (with different formatting):
120+
* tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE
121+
*/
122+
traceState?: TraceState;
123+
}
124+
125+
export interface SpanStatus {
126+
/** The status code of this message. */
127+
code: SpanStatusCode;
128+
/** A developer-facing error message. */
129+
message?: string;
130+
}
131+
/**
132+
* An enumeration of status codes.
133+
*/
134+
export declare enum SpanStatusCode {
135+
/**
136+
* The default status.
137+
*/
138+
UNSET = 0,
139+
/**
140+
* The operation has been validated by an Application developer or
141+
* Operator to have completed successfully.
142+
*/
143+
OK = 1,
144+
/**
145+
* The operation contains an error.
146+
*/
147+
ERROR = 2
148+
}
149+
150+
/**
151+
* A pointer from the current {@link Span} to another span in the same trace or
152+
* in a different trace.
153+
* Few examples of Link usage.
154+
* 1. Batch Processing: A batch of elements may contain elements associated
155+
* with one or more traces/spans. Since there can only be one parent
156+
* SpanContext, Link is used to keep reference to SpanContext of all
157+
* elements in the batch.
158+
* 2. Public Endpoint: A SpanContext in incoming client request on a public
159+
* endpoint is untrusted from service provider perspective. In such case it
160+
* is advisable to start a new trace with appropriate sampling decision.
161+
* However, it is desirable to associate incoming SpanContext to new trace
162+
* initiated on service provider side so two traces (from Client and from
163+
* Service Provider) can be correlated.
164+
*/
165+
export interface Link {
166+
/** The {@link SpanContext} of a linked span. */
167+
context: SpanContext;
168+
/** A set of {@link Attributes} on the link. */
169+
attributes?: Attributes;
170+
/** Count of attributes of the link that were dropped due to collection limits */
171+
droppedAttributesCount?: number;
172+
}
173+
174+
/**
175+
* Represents a timed event.
176+
* A timed event is an event with a timestamp.
177+
*/
178+
export interface TimedEvent {
179+
time: HrTime;
180+
/** The name of the event. */
181+
name: string;
182+
/** The attributes of the event. */
183+
attributes?: Attributes;
184+
}
185+
186+
/**
187+
* A Resource describes the entity for which a signals (metrics or trace) are
188+
* collected.
189+
*/
190+
export declare class Resource {
191+
/**
192+
* A dictionary of attributes with string keys and values that provide
193+
* information about the entity as numbers, strings or booleans
194+
* TODO: Consider to add check/validation on attributes.
195+
*/
196+
readonly attributes: Attributes;
197+
static readonly EMPTY: Resource;
198+
/**
199+
* Returns an empty Resource
200+
*/
201+
static empty(): Resource;
202+
/**
203+
* Returns a Resource that indentifies the SDK in use.
204+
*/
205+
static default(): Resource;
206+
constructor(
207+
/**
208+
* A dictionary of attributes with string keys and values that provide
209+
* information about the entity as numbers, strings or booleans
210+
* TODO: Consider to add check/validation on attributes.
211+
*/
212+
attributes: Attributes);
213+
/**
214+
* Returns a new, merged {@link Resource} by merging the current Resource
215+
* with the other Resource. In case of a collision, other Resource takes
216+
* precedence.
217+
*
218+
* @param other the Resource that will be merged with this.
219+
* @returns the newly merged Resource.
220+
*/
221+
merge(other: Resource | null): Resource;
222+
}
223+
224+
/**
225+
* An instrumentation library consists of the name and and optional version
226+
* used to obtain a tracer or meter from a provider. This metadata is made
227+
* available on ReadableSpan and MetricRecord for use by the export pipeline.
228+
*/
229+
export interface InstrumentationLibrary {
230+
readonly name: string;
231+
readonly version?: string;
232+
}
233+
234+
export interface ReadableSpan {
235+
readonly name: string;
236+
readonly kind: SpanKind;
237+
readonly spanContext: () => SpanContext;
238+
readonly parentSpanId?: string;
239+
readonly startTime: HrTime;
240+
readonly endTime: HrTime;
241+
readonly status: SpanStatus;
242+
readonly attributes: Attributes;
243+
readonly links: Link[];
244+
readonly events: TimedEvent[];
245+
readonly duration: HrTime;
246+
readonly ended: boolean;
247+
readonly resource: Resource;
248+
readonly instrumentationLibrary: InstrumentationLibrary;
249+
}

packages/opentelemetry-node/src/exporters/metrics-exporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
export class TraceoMetricExporter extends OTLPMetricExporter {
1717
private client: INodeClient;
1818

19-
constructor(config?: OTLPExporterNodeConfigBase) {
19+
constructor(config: OTLPExporterNodeConfigBase = {}) {
2020
super({
2121
...config,
2222
temporalityPreference: AggregationTemporality.DELTA

packages/opentelemetry-node/src/exporters/tracing-exporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
export class TraceoTracingExporter extends OTLPTraceExporter {
1414
private client: INodeClient;
1515

16-
constructor(config: OTLPExporterNodeConfigBase) {
16+
constructor(config: OTLPExporterNodeConfigBase = {}) {
1717
super(config);
1818

1919
this.client = utils.getGlobalTraceo();

0 commit comments

Comments
 (0)