Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/node/internal/internal_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,3 +983,12 @@ export class ERR_PERFORMANCE_INVALID_TIMESTAMP extends NodeTypeError {
);
}
}

export class ERR_TRACE_EVENTS_CATEGORY_REQUIRED extends NodeTypeError {
constructor() {
super(
'ERR_TRACE_EVENTS_CATEGORY_REQUIRED',
'At least one category is required'
);
}
}
39 changes: 23 additions & 16 deletions src/node/trace_events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,39 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

import { ERR_METHOD_NOT_IMPLEMENTED } from 'node-internal:internal_errors';

import type * as TraceEvents from 'node:trace_events';
import { ERR_TRACE_EVENTS_CATEGORY_REQUIRED } from 'node-internal:internal_errors';
import { validateObject, validateStringArray } from 'node-internal:validators';

import { format, customInspectSymbol } from 'node-internal:internal_inspect';

import type { CreateTracingOptions } from 'node:trace_events';

// TODO(soon): It is conceivable that we might implement this as part of
// the workers observability features in the future. For now it's a non
// functional stub.

class Tracing {
constructor(_: string[]) {
throw new ERR_METHOD_NOT_IMPLEMENTED('Tracing');
class Tracing implements TraceEvents.Tracing {
#categories: string[];
#enabled = false;

constructor(categories: string[]) {
this.#categories = categories;
}

enable(): void {
this.#enabled = true;
// non-op
}

disable(): void {
this.#enabled = false;
// non-op
}

get enabled(): boolean {
return false;
return this.#enabled;
}

get categories(): string[] {
return [];
get categories(): string {
return this.#categories.join(',');
}

[customInspectSymbol](depth?: number, _: object = {}): string | object {
Expand All @@ -66,17 +68,22 @@ class Tracing {
}
}

export function createTracing(options: CreateTracingOptions): Tracing {
export function createTracing(
options: TraceEvents.CreateTracingOptions
): Tracing {
validateObject(options, 'options');
validateStringArray(options.categories, 'options.categories');
throw new ERR_METHOD_NOT_IMPLEMENTED('trace_events.createTracing');
if (options.categories.length <= 0) {
throw new ERR_TRACE_EVENTS_CATEGORY_REQUIRED();
}
return new Tracing(options.categories);
}

export function getEnabledCategories(): string[] {
return [];
export function getEnabledCategories(): string | undefined {
return undefined;
}

export default {
createTracing,
getEnabledCategories,
};
} satisfies typeof TraceEvents;
Loading