@twin.org/tracing-service 0.9.2-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -0
  3. package/dist/es/index.js +7 -0
  4. package/dist/es/index.js.map +1 -0
  5. package/dist/es/models/ITracingServiceConstructorOptions.js +4 -0
  6. package/dist/es/models/ITracingServiceConstructorOptions.js.map +1 -0
  7. package/dist/es/restEntryPoints.js +13 -0
  8. package/dist/es/restEntryPoints.js.map +1 -0
  9. package/dist/es/tracingRoutes.js +298 -0
  10. package/dist/es/tracingRoutes.js.map +1 -0
  11. package/dist/es/tracingService.js +147 -0
  12. package/dist/es/tracingService.js.map +1 -0
  13. package/dist/types/index.d.ts +4 -0
  14. package/dist/types/models/ITracingServiceConstructorOptions.d.ts +10 -0
  15. package/dist/types/restEntryPoints.d.ts +5 -0
  16. package/dist/types/tracingRoutes.d.ts +45 -0
  17. package/dist/types/tracingService.d.ts +72 -0
  18. package/docs/changelog.md +25 -0
  19. package/docs/examples.md +37 -0
  20. package/docs/open-api/spec.json +847 -0
  21. package/docs/reference/classes/TracingService.md +224 -0
  22. package/docs/reference/functions/generateRestRoutesTracing.md +25 -0
  23. package/docs/reference/functions/tracingGetTrace.md +31 -0
  24. package/docs/reference/functions/tracingList.md +31 -0
  25. package/docs/reference/functions/tracingSpanEnd.md +31 -0
  26. package/docs/reference/functions/tracingSpanStart.md +31 -0
  27. package/docs/reference/index.md +22 -0
  28. package/docs/reference/interfaces/ITracingServiceConstructorOptions.md +17 -0
  29. package/docs/reference/variables/restEntryPoints.md +5 -0
  30. package/docs/reference/variables/tagsTracing.md +5 -0
  31. package/locales/en.json +7 -0
  32. package/package.json +55 -0
@@ -0,0 +1,147 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { Guards, Is } from "@twin.org/core";
4
+ import { ComparisonOperator, LogicalOperator, SortDirection } from "@twin.org/entity";
5
+ import { TracingConnectorFactory } from "@twin.org/tracing-models";
6
+ /**
7
+ * Service for performing tracing operations to a connector.
8
+ */
9
+ export class TracingService {
10
+ /**
11
+ * Runtime name for the class.
12
+ */
13
+ static CLASS_NAME = "TracingService";
14
+ /**
15
+ * The maximum number of pages `getTrace` will request before stopping. A safety bound that
16
+ * prevents an unexpectedly large trace or a non-terminating connector cursor from looping
17
+ * unbounded; with the default page size this still covers very large traces.
18
+ */
19
+ static MAX_GET_TRACE_PAGES = 1000;
20
+ /**
21
+ * Tracing connector used by the service.
22
+ * @internal
23
+ */
24
+ _tracingConnector;
25
+ /**
26
+ * Create a new instance of TracingService.
27
+ * @param options The options for the connector.
28
+ */
29
+ constructor(options) {
30
+ this._tracingConnector = TracingConnectorFactory.get(options?.tracingConnectorType ?? "tracing");
31
+ }
32
+ /**
33
+ * Returns the class name of the component.
34
+ * @returns The class name of the component.
35
+ */
36
+ className() {
37
+ return TracingService.CLASS_NAME;
38
+ }
39
+ /**
40
+ * Start a new span.
41
+ * @param name The name of the span.
42
+ * @param options The options for the span.
43
+ * @returns The started span, including its minted context.
44
+ */
45
+ async startSpan(name, options) {
46
+ Guards.stringValue(TracingService.CLASS_NAME, "name", name);
47
+ return this._tracingConnector.startSpan(name, options);
48
+ }
49
+ /**
50
+ * End a span, finalizing its status and duration.
51
+ * @param span The span to end.
52
+ * @param status The status to set on the span, defaults to ok.
53
+ * @returns A promise that resolves when the span has been ended.
54
+ */
55
+ async endSpan(span, status) {
56
+ Guards.object(TracingService.CLASS_NAME, "span", span);
57
+ await this._tracingConnector.endSpan(span, status);
58
+ }
59
+ /**
60
+ * Query the spans.
61
+ * @param traceId The id of the trace to filter by.
62
+ * @param spanId The id of the span to filter by.
63
+ * @param status The status to filter by.
64
+ * @param kind The kind to filter by.
65
+ * @param timeStart The inclusive start time to filter the span start by, as a timestamp in ms.
66
+ * @param timeEnd The inclusive end time to filter the span start by, as a timestamp in ms.
67
+ * @param cursor The cursor to request the next chunk of entities.
68
+ * @param limit Limit the number of entities to return.
69
+ * @returns All the entities for the storage matching the conditions,
70
+ * and a cursor which can be used to request more entities.
71
+ */
72
+ async query(traceId, spanId, status, kind, timeStart, timeEnd, cursor, limit) {
73
+ const condition = {
74
+ conditions: [],
75
+ logicalOperator: LogicalOperator.And
76
+ };
77
+ if (Is.stringValue(traceId)) {
78
+ condition.conditions.push({
79
+ property: "traceId",
80
+ comparison: ComparisonOperator.Equals,
81
+ value: traceId
82
+ });
83
+ }
84
+ if (Is.stringValue(spanId)) {
85
+ condition.conditions.push({
86
+ property: "spanId",
87
+ comparison: ComparisonOperator.Equals,
88
+ value: spanId
89
+ });
90
+ }
91
+ if (Is.stringValue(status)) {
92
+ condition.conditions.push({
93
+ property: "status",
94
+ comparison: ComparisonOperator.Equals,
95
+ value: status
96
+ });
97
+ }
98
+ if (Is.stringValue(kind)) {
99
+ condition.conditions.push({
100
+ property: "kind",
101
+ comparison: ComparisonOperator.Equals,
102
+ value: kind
103
+ });
104
+ }
105
+ if (Is.number(timeStart)) {
106
+ condition.conditions.push({
107
+ property: "startTs",
108
+ comparison: ComparisonOperator.GreaterThanOrEqual,
109
+ value: timeStart
110
+ });
111
+ }
112
+ if (Is.number(timeEnd)) {
113
+ condition.conditions.push({
114
+ property: "startTs",
115
+ comparison: ComparisonOperator.LessThanOrEqual,
116
+ value: timeEnd
117
+ });
118
+ }
119
+ const queryConnector = this._tracingConnector?.query?.bind(this._tracingConnector);
120
+ if (Is.function(queryConnector)) {
121
+ const result = await queryConnector(condition, [{ property: "startTs", sortDirection: SortDirection.Descending }], cursor, limit);
122
+ return { entities: result.entities, cursor: result.cursor };
123
+ }
124
+ return { entities: [] };
125
+ }
126
+ /**
127
+ * Get all the spans belonging to a trace, ordered by their start time. The whole trace is paged
128
+ * into memory; paging is bounded by {@link TracingService.MAX_GET_TRACE_PAGES} as a safeguard
129
+ * against a pathologically large trace or a non-terminating cursor.
130
+ * @param traceId The id of the trace to retrieve.
131
+ * @returns The spans belonging to the trace, ordered by their start time ascending.
132
+ */
133
+ async getTrace(traceId) {
134
+ Guards.stringValue(TracingService.CLASS_NAME, "traceId", traceId);
135
+ const spans = [];
136
+ let cursor;
137
+ let pages = 0;
138
+ do {
139
+ const result = await this.query(traceId, undefined, undefined, undefined, undefined, undefined, cursor);
140
+ spans.push(...result.entities);
141
+ cursor = result.cursor;
142
+ pages++;
143
+ } while (Is.stringValue(cursor) && pages < TracingService.MAX_GET_TRACE_PAGES);
144
+ return spans.sort((a, b) => a.startTs - b.startTs);
145
+ }
146
+ }
147
+ //# sourceMappingURL=tracingService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracingService.js","sourceRoot":"","sources":["../../src/tracingService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACN,kBAAkB,EAClB,eAAe,EACf,aAAa,EAEb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,uBAAuB,EAOvB,MAAM,0BAA0B,CAAC;AAGlC;;GAEG;AACH,MAAM,OAAO,cAAc;IAC1B;;OAEG;IACI,MAAM,CAAU,UAAU,oBAAoC;IAErE;;;;OAIG;IACI,MAAM,CAAU,mBAAmB,GAAW,IAAI,CAAC;IAE1D;;;OAGG;IACc,iBAAiB,CAAoB;IAEtD;;;OAGG;IACH,YAAY,OAA2C;QACtD,IAAI,CAAC,iBAAiB,GAAG,uBAAuB,CAAC,GAAG,CACnD,OAAO,EAAE,oBAAoB,IAAI,SAAS,CAC1C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,cAAc,CAAC,UAAU,CAAC;IAClC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,OAAsB;QAC1D,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,UAAU,UAAgB,IAAI,CAAC,C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,OAAe;QACpC,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAExE,MAAM,KAAK,GAAY,EAAE,CAAC;QAC1B,IAAI,MAA0B,CAAC;QAC/B,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,GAAG,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAC9B,OAAO,EACP,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,MAAM,CACN,CAAC;YACF,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC/B,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YACvB,KAAK,EAAE,CAAC;QACT,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,KAAK,GAAG,cAAc,CAAC,mBAAmB,EAAE;QAE/E,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Guards, Is } from \"@twin.org/core\";\nimport {\n\tComparisonOperator,\n\tLogicalOperator,\n\tSortDirection,\n\ttype EntityCondition\n} from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tTracingConnectorFactory,\n\ttype ISpan,\n\ttype ISpanOptions,\n\ttype ITracingComponent,\n\ttype ITracingConnector,\n\ttype SpanKind,\n\ttype SpanStatus\n} from \"@twin.org/tracing-models\";\nimport type { ITracingServiceConstructorOptions } from \"./models/ITracingServiceConstructorOptions.js\";\n\n/**\n * Service for performing tracing operations to a connector.\n */\nexport class TracingService implements ITracingComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TracingService>();\n\n\t/**\n\t * The maximum number of pages `getTrace` will request before stopping. A safety bound that\n\t * prevents an unexpectedly large trace or a non-terminating connector cursor from looping\n\t * unbounded; with the default page size this still covers very large traces.\n\t */\n\tpublic static readonly MAX_GET_TRACE_PAGES: number = 1000;\n\n\t/**\n\t * Tracing connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _tracingConnector: ITracingConnector;\n\n\t/**\n\t * Create a new instance of TracingService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: ITracingServiceConstructorOptions) {\n\t\tthis._tracingConnector = TracingConnectorFactory.get(\n\t\t\toptions?.tracingConnectorType ?? \"tracing\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TracingService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Start a new span.\n\t * @param name The name of the span.\n\t * @param options The options for the span.\n\t * @returns The started span, including its minted context.\n\t */\n\tpublic async startSpan(name: string, options?: ISpanOptions): Promise<ISpan> {\n\t\tGuards.stringValue(TracingService.CLASS_NAME, nameof(name), name);\n\n\t\treturn this._tracingConnector.startSpan(name, options);\n\t}\n\n\t/**\n\t * End a span, finalizing its status and duration.\n\t * @param span The span to end.\n\t * @param status The status to set on the span, defaults to ok.\n\t * @returns A promise that resolves when the span has been ended.\n\t */\n\tpublic async endSpan(span: ISpan, status?: SpanStatus): Promise<void> {\n\t\tGuards.object<ISpan>(TracingService.CLASS_NAME, nameof(span), span);\n\n\t\tawait this._tracingConnector.endSpan(span, status);\n\t}\n\n\t/**\n\t * Query the spans.\n\t * @param traceId The id of the trace to filter by.\n\t * @param spanId The id of the span to filter by.\n\t * @param status The status to filter by.\n\t * @param kind The kind to filter by.\n\t * @param timeStart The inclusive start time to filter the span start by, as a timestamp in ms.\n\t * @param timeEnd The inclusive end time to filter the span start by, as a timestamp in ms.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\ttraceId?: string,\n\t\tspanId?: string,\n\t\tstatus?: SpanStatus,\n\t\tkind?: SpanKind,\n\t\ttimeStart?: number,\n\t\ttimeEnd?: number,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The spans.\n\t\t */\n\t\tentities: ISpan[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call query to get more entities.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tconst condition: EntityCondition<ISpan> = {\n\t\t\tconditions: [],\n\t\t\tlogicalOperator: LogicalOperator.And\n\t\t};\n\n\t\tif (Is.stringValue(traceId)) {\n\t\t\tcondition.conditions.push({\n\t\t\t\tproperty: \"traceId\",\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: traceId\n\t\t\t});\n\t\t}\n\n\t\tif (Is.stringValue(spanId)) {\n\t\t\tcondition.conditions.push({\n\t\t\t\tproperty: \"spanId\",\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: spanId\n\t\t\t});\n\t\t}\n\n\t\tif (Is.stringValue(status)) {\n\t\t\tcondition.conditions.push({\n\t\t\t\tproperty: \"status\",\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: status\n\t\t\t});\n\t\t}\n\n\t\tif (Is.stringValue(kind)) {\n\t\t\tcondition.conditions.push({\n\t\t\t\tproperty: \"kind\",\n\t\t\t\tcomparison: ComparisonOperator.Equals,\n\t\t\t\tvalue: kind\n\t\t\t});\n\t\t}\n\n\t\tif (Is.number(timeStart)) {\n\t\t\tcondition.conditions.push({\n\t\t\t\tproperty: \"startTs\",\n\t\t\t\tcomparison: ComparisonOperator.GreaterThanOrEqual,\n\t\t\t\tvalue: timeStart\n\t\t\t});\n\t\t}\n\n\t\tif (Is.number(timeEnd)) {\n\t\t\tcondition.conditions.push({\n\t\t\t\tproperty: \"startTs\",\n\t\t\t\tcomparison: ComparisonOperator.LessThanOrEqual,\n\t\t\t\tvalue: timeEnd\n\t\t\t});\n\t\t}\n\n\t\tconst queryConnector = this._tracingConnector?.query?.bind(this._tracingConnector);\n\t\tif (Is.function(queryConnector)) {\n\t\t\tconst result = await queryConnector(\n\t\t\t\tcondition,\n\t\t\t\t[{ property: \"startTs\", sortDirection: SortDirection.Descending }],\n\t\t\t\tcursor,\n\t\t\t\tlimit\n\t\t\t);\n\n\t\t\treturn { entities: result.entities, cursor: result.cursor };\n\t\t}\n\n\t\treturn { entities: [] };\n\t}\n\n\t/**\n\t * Get all the spans belonging to a trace, ordered by their start time. The whole trace is paged\n\t * into memory; paging is bounded by {@link TracingService.MAX_GET_TRACE_PAGES} as a safeguard\n\t * against a pathologically large trace or a non-terminating cursor.\n\t * @param traceId The id of the trace to retrieve.\n\t * @returns The spans belonging to the trace, ordered by their start time ascending.\n\t */\n\tpublic async getTrace(traceId: string): Promise<ISpan[]> {\n\t\tGuards.stringValue(TracingService.CLASS_NAME, nameof(traceId), traceId);\n\n\t\tconst spans: ISpan[] = [];\n\t\tlet cursor: string | undefined;\n\t\tlet pages = 0;\n\n\t\tdo {\n\t\t\tconst result = await this.query(\n\t\t\t\ttraceId,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\tundefined,\n\t\t\t\tcursor\n\t\t\t);\n\t\t\tspans.push(...result.entities);\n\t\t\tcursor = result.cursor;\n\t\t\tpages++;\n\t\t} while (Is.stringValue(cursor) && pages < TracingService.MAX_GET_TRACE_PAGES);\n\n\t\treturn spans.sort((a, b) => a.startTs - b.startTs);\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export * from "./models/ITracingServiceConstructorOptions.js";
2
+ export * from "./restEntryPoints.js";
3
+ export * from "./tracingRoutes.js";
4
+ export * from "./tracingService.js";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Options for the tracing service constructor.
3
+ */
4
+ export interface ITracingServiceConstructorOptions {
5
+ /**
6
+ * The type of the tracing connector to use.
7
+ * @default tracing
8
+ */
9
+ tracingConnectorType?: string;
10
+ }
@@ -0,0 +1,5 @@
1
+ import type { IRestRouteEntryPoint } from "@twin.org/api-models";
2
+ /**
3
+ * REST entry points for the tracing service.
4
+ */
5
+ export declare const restEntryPoints: IRestRouteEntryPoint[];
@@ -0,0 +1,45 @@
1
+ import type { IHttpRequestContext, INoContentResponse, IRestRoute, ITag } from "@twin.org/api-models";
2
+ import type { ITracingGetTraceRequest, ITracingGetTraceResponse, ITracingListRequest, ITracingListResponse, ITracingSpanEndRequest, ITracingSpanStartRequest, ITracingSpanStartResponse } from "@twin.org/tracing-models";
3
+ /**
4
+ * The tag to associate with the routes.
5
+ */
6
+ export declare const tagsTracing: ITag[];
7
+ /**
8
+ * The REST routes for tracing.
9
+ * @param baseRouteName Prefix to prepend to the paths.
10
+ * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
11
+ * @returns The generated routes.
12
+ */
13
+ export declare function generateRestRoutesTracing(baseRouteName: string, componentName: string): IRestRoute[];
14
+ /**
15
+ * Start a new span.
16
+ * @param httpRequestContext The request context for the API.
17
+ * @param componentName The name of the component to use in the routes.
18
+ * @param request The request.
19
+ * @returns A promise that resolves to the started span.
20
+ */
21
+ export declare function tracingSpanStart(httpRequestContext: IHttpRequestContext, componentName: string, request: ITracingSpanStartRequest): Promise<ITracingSpanStartResponse>;
22
+ /**
23
+ * End a span.
24
+ * @param httpRequestContext The request context for the API.
25
+ * @param componentName The name of the component to use in the routes.
26
+ * @param request The request.
27
+ * @returns A promise that resolves to a no-content response when the span has been ended.
28
+ */
29
+ export declare function tracingSpanEnd(httpRequestContext: IHttpRequestContext, componentName: string, request: ITracingSpanEndRequest): Promise<INoContentResponse>;
30
+ /**
31
+ * Get a list of the spans.
32
+ * @param httpRequestContext The request context for the API.
33
+ * @param componentName The name of the component to use in the routes.
34
+ * @param request The request.
35
+ * @returns A promise that resolves to the matching spans and an optional pagination cursor.
36
+ */
37
+ export declare function tracingList(httpRequestContext: IHttpRequestContext, componentName: string, request: ITracingListRequest): Promise<ITracingListResponse>;
38
+ /**
39
+ * Get all the spans belonging to a trace.
40
+ * @param httpRequestContext The request context for the API.
41
+ * @param componentName The name of the component to use in the routes.
42
+ * @param request The request.
43
+ * @returns A promise that resolves to the spans belonging to the trace.
44
+ */
45
+ export declare function tracingGetTrace(httpRequestContext: IHttpRequestContext, componentName: string, request: ITracingGetTraceRequest): Promise<ITracingGetTraceResponse>;
@@ -0,0 +1,72 @@
1
+ import { type ISpan, type ISpanOptions, type ITracingComponent, type SpanKind, type SpanStatus } from "@twin.org/tracing-models";
2
+ import type { ITracingServiceConstructorOptions } from "./models/ITracingServiceConstructorOptions.js";
3
+ /**
4
+ * Service for performing tracing operations to a connector.
5
+ */
6
+ export declare class TracingService implements ITracingComponent {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static readonly CLASS_NAME: string;
11
+ /**
12
+ * The maximum number of pages `getTrace` will request before stopping. A safety bound that
13
+ * prevents an unexpectedly large trace or a non-terminating connector cursor from looping
14
+ * unbounded; with the default page size this still covers very large traces.
15
+ */
16
+ static readonly MAX_GET_TRACE_PAGES: number;
17
+ /**
18
+ * Create a new instance of TracingService.
19
+ * @param options The options for the connector.
20
+ */
21
+ constructor(options?: ITracingServiceConstructorOptions);
22
+ /**
23
+ * Returns the class name of the component.
24
+ * @returns The class name of the component.
25
+ */
26
+ className(): string;
27
+ /**
28
+ * Start a new span.
29
+ * @param name The name of the span.
30
+ * @param options The options for the span.
31
+ * @returns The started span, including its minted context.
32
+ */
33
+ startSpan(name: string, options?: ISpanOptions): Promise<ISpan>;
34
+ /**
35
+ * End a span, finalizing its status and duration.
36
+ * @param span The span to end.
37
+ * @param status The status to set on the span, defaults to ok.
38
+ * @returns A promise that resolves when the span has been ended.
39
+ */
40
+ endSpan(span: ISpan, status?: SpanStatus): Promise<void>;
41
+ /**
42
+ * Query the spans.
43
+ * @param traceId The id of the trace to filter by.
44
+ * @param spanId The id of the span to filter by.
45
+ * @param status The status to filter by.
46
+ * @param kind The kind to filter by.
47
+ * @param timeStart The inclusive start time to filter the span start by, as a timestamp in ms.
48
+ * @param timeEnd The inclusive end time to filter the span start by, as a timestamp in ms.
49
+ * @param cursor The cursor to request the next chunk of entities.
50
+ * @param limit Limit the number of entities to return.
51
+ * @returns All the entities for the storage matching the conditions,
52
+ * and a cursor which can be used to request more entities.
53
+ */
54
+ query(traceId?: string, spanId?: string, status?: SpanStatus, kind?: SpanKind, timeStart?: number, timeEnd?: number, cursor?: string, limit?: number): Promise<{
55
+ /**
56
+ * The spans.
57
+ */
58
+ entities: ISpan[];
59
+ /**
60
+ * An optional cursor, when defined can be used to call query to get more entities.
61
+ */
62
+ cursor?: string;
63
+ }>;
64
+ /**
65
+ * Get all the spans belonging to a trace, ordered by their start time. The whole trace is paged
66
+ * into memory; paging is bounded by {@link TracingService.MAX_GET_TRACE_PAGES} as a safeguard
67
+ * against a pathologically large trace or a non-terminating cursor.
68
+ * @param traceId The id of the trace to retrieve.
69
+ * @returns The spans belonging to the trace, ordered by their start time ascending.
70
+ */
71
+ getTrace(traceId: string): Promise<ISpan[]>;
72
+ }
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ ## [0.9.2-next.1](https://github.com/iotaledger/twin-tracing/compare/tracing-service-v0.9.2-next.0...tracing-service-v0.9.2-next.1) (2026-08-07)
4
+
5
+
6
+ ### Features
7
+
8
+ * add twin-tracing repository with OTel-aligned tracing API ([59b914c](https://github.com/iotaledger/twin-tracing/commit/59b914ca631c0b765973dfa5099a8f4e6115e325))
9
+ * add twin-tracing repository with OTel-aligned tracing API ([affcd6c](https://github.com/iotaledger/twin-tracing/commit/affcd6c1cf2fbfd34d9a8849e860e5fe66a011e3))
10
+ * linting and dependency update ([c1a2b98](https://github.com/iotaledger/twin-tracing/commit/c1a2b988441deb59592d69c7d3b6527bcb9018b2))
11
+ * linting and dependency update ([b65c083](https://github.com/iotaledger/twin-tracing/commit/b65c083d4f8f83c2046d29d53444b45c7a4188c7))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * address PR review on tracing packages ([0832b5f](https://github.com/iotaledger/twin-tracing/commit/0832b5fc0e7414b4e0fd2393532df00e07ff1f43))
17
+
18
+
19
+ ### Dependencies
20
+
21
+ * The following workspace dependencies were updated
22
+ * dependencies
23
+ * @twin.org/tracing-models bumped from 0.9.2-next.0 to 0.9.2-next.1
24
+
25
+ ## Changelog
@@ -0,0 +1,37 @@
1
+ # Tracing Service Examples
2
+
3
+ The service implements the tracing component contract and resolves a connector from the factory.
4
+
5
+ ## Construct the service
6
+
7
+ ```typescript
8
+ import { TracingConnectorFactory } from '@twin.org/tracing-models';
9
+ import { EntityStorageTracingConnector } from '@twin.org/tracing-connector-entity-storage';
10
+ import { TracingService } from '@twin.org/tracing-service';
11
+
12
+ TracingConnectorFactory.register('tracing', () => new EntityStorageTracingConnector());
13
+
14
+ const service = new TracingService();
15
+ ```
16
+
17
+ ## Record and query spans
18
+
19
+ ```typescript
20
+ import { SpanKind, SpanStatus } from '@twin.org/tracing-models';
21
+
22
+ const span = await service.startSpan('handle-request', { kind: SpanKind.Server });
23
+
24
+ await service.endSpan(span, SpanStatus.Ok);
25
+
26
+ const spans = await service.query(span.context.traceId);
27
+
28
+ const trace = await service.getTrace(span.context.traceId);
29
+ ```
30
+
31
+ ## Register the REST routes
32
+
33
+ ```typescript
34
+ import { generateRestRoutesTracing, tagsTracing } from '@twin.org/tracing-service';
35
+
36
+ const routes = generateRestRoutesTracing('tracing', 'tracing');
37
+ ```