drtrace 0.2.0 → 0.4.0

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 (53) hide show
  1. package/README.md +74 -4
  2. package/agents/CONTRIBUTING.md +296 -0
  3. package/agents/README.md +174 -0
  4. package/agents/daemon-method-selection.md +370 -0
  5. package/agents/integration-guides/cpp-best-practices.md +218 -0
  6. package/agents/integration-guides/cpp-ros-integration.md +88 -0
  7. package/agents/log-analysis.md +218 -0
  8. package/agents/log-help.md +226 -0
  9. package/agents/log-init.md +933 -0
  10. package/agents/log-it.md +1126 -0
  11. package/bin/init.js +4 -4
  12. package/dist/bin/init.js +31 -0
  13. package/dist/browser.d.ts +28 -0
  14. package/dist/browser.js +91 -0
  15. package/dist/config-schema.d.ts +2 -2
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +2 -2
  18. package/dist/init.d.ts +44 -2
  19. package/dist/init.js +460 -30
  20. package/dist/logger.d.ts +7 -0
  21. package/dist/logger.js +30 -4
  22. package/dist/node.d.ts +13 -0
  23. package/dist/node.js +67 -0
  24. package/dist/resources/agents/CONTRIBUTING.md +296 -0
  25. package/dist/resources/agents/README.md +174 -0
  26. package/dist/resources/agents/daemon-method-selection.md +370 -0
  27. package/dist/resources/agents/integration-guides/cpp-best-practices.md +218 -0
  28. package/dist/resources/agents/integration-guides/cpp-ros-integration.md +88 -0
  29. package/dist/resources/agents/log-analysis.md +218 -0
  30. package/dist/resources/agents/log-help.md +226 -0
  31. package/dist/resources/agents/log-init.md +933 -0
  32. package/dist/resources/agents/log-it.md +1126 -0
  33. package/dist/resources/cpp/drtrace_sink.hpp +1249 -0
  34. package/dist/transport.js +5 -1
  35. package/dist/types.d.ts +8 -2
  36. package/package.json +28 -4
  37. package/.eslintrc.js +0 -20
  38. package/jest.config.js +0 -11
  39. package/src/client.ts +0 -68
  40. package/src/config-schema.ts +0 -115
  41. package/src/config.ts +0 -326
  42. package/src/index.ts +0 -3
  43. package/src/init.ts +0 -451
  44. package/src/logger.ts +0 -56
  45. package/src/queue.ts +0 -105
  46. package/src/transport.ts +0 -60
  47. package/src/types.ts +0 -20
  48. package/tests/client.test.ts +0 -66
  49. package/tests/config-schema.test.ts +0 -198
  50. package/tests/config.test.ts +0 -456
  51. package/tests/queue.test.ts +0 -72
  52. package/tests/transport.test.ts +0 -52
  53. package/tsconfig.json +0 -18
package/bin/init.js CHANGED
@@ -5,9 +5,9 @@
5
5
  * Usage: npx drtrace init [--project-root <path>]
6
6
  */
7
7
 
8
- import yargs from "yargs";
9
- import { hideBin } from "yargs/helpers";
10
- import { runInitProject } from "./init";
8
+ const yargs = require("yargs");
9
+ const { hideBin } = require("yargs/helpers");
10
+ const { runInitProject } = require("../init");
11
11
 
12
12
  yargs(hideBin(process.argv))
13
13
  .command(
@@ -20,7 +20,7 @@ yargs(hideBin(process.argv))
20
20
  description: "Project root directory (default: current directory)",
21
21
  }),
22
22
  async (argv) => {
23
- const exitCode = await runInitProject(argv["project-root"] as string);
23
+ const exitCode = await runInitProject(argv["project-root"]);
24
24
  process.exit(exitCode);
25
25
  }
26
26
  )
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * CLI entry point for drtrace init command
5
+ * Usage: npx drtrace init [--project-root <path>]
6
+ */
7
+
8
+ const yargs = require("yargs");
9
+ const { hideBin } = require("yargs/helpers");
10
+ const { runInitProject } = require("../init");
11
+
12
+ yargs(hideBin(process.argv))
13
+ .command(
14
+ "init",
15
+ "Interactive DrTrace project initialization with config and templates",
16
+ (yargs) =>
17
+ yargs.option("project-root", {
18
+ alias: "p",
19
+ type: "string",
20
+ description: "Project root directory (default: current directory)",
21
+ }),
22
+ async (argv) => {
23
+ const exitCode = await runInitProject(argv["project-root"]);
24
+ process.exit(exitCode);
25
+ }
26
+ )
27
+ .demandCommand()
28
+ .strict()
29
+ .help()
30
+ .alias("h", "help")
31
+ .parse();
@@ -0,0 +1,28 @@
1
+ import type { ClientOptions, LogLevel } from './types';
2
+ /**
3
+ * DrTrace client for browser environments.
4
+ *
5
+ * Unlike the Node.js client, this does NOT load configuration from files.
6
+ * All options must be passed explicitly to init().
7
+ */
8
+ export declare class DrTrace {
9
+ private queue;
10
+ private logger;
11
+ private enabled;
12
+ private constructor();
13
+ /**
14
+ * Initialize DrTrace for browser environments.
15
+ * Unlike Node.js, browser does not load config from files.
16
+ * All options must be passed explicitly.
17
+ *
18
+ * @param opts - Client options (applicationId and daemonUrl are required)
19
+ * @throws Error if applicationId or daemonUrl are not provided
20
+ */
21
+ static init(opts: ClientOptions): DrTrace;
22
+ attachToConsole(): void;
23
+ detachFromConsole(): void;
24
+ log(message: string, level?: LogLevel, context?: Record<string, unknown>): void;
25
+ error(message: string, context?: Record<string, unknown>): void;
26
+ shutdown(): Promise<void>;
27
+ }
28
+ export * from './types';
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.DrTrace = void 0;
18
+ const transport_1 = require("./transport");
19
+ const queue_1 = require("./queue");
20
+ const logger_1 = require("./logger");
21
+ /**
22
+ * DrTrace client for browser environments.
23
+ *
24
+ * Unlike the Node.js client, this does NOT load configuration from files.
25
+ * All options must be passed explicitly to init().
26
+ */
27
+ class DrTrace {
28
+ constructor(opts) {
29
+ const transport = new transport_1.Transport({
30
+ daemonUrl: opts.daemonUrl,
31
+ maxRetries: opts.maxRetries ?? 3,
32
+ timeoutMs: 5000,
33
+ });
34
+ this.queue = new queue_1.LogQueue({
35
+ transport,
36
+ batchSize: opts.batchSize ?? 50,
37
+ flushIntervalMs: opts.flushIntervalMs ?? 1000,
38
+ maxQueueSize: opts.maxQueueSize ?? 10000,
39
+ });
40
+ this.queue.start();
41
+ this.enabled = opts.enabled ?? true;
42
+ this.logger = new logger_1.DrTraceLogger({
43
+ queue: this.queue,
44
+ applicationId: opts.applicationId,
45
+ moduleName: opts.moduleName,
46
+ logLevel: (opts.logLevel ?? 'info'),
47
+ });
48
+ }
49
+ /**
50
+ * Initialize DrTrace for browser environments.
51
+ * Unlike Node.js, browser does not load config from files.
52
+ * All options must be passed explicitly.
53
+ *
54
+ * @param opts - Client options (applicationId and daemonUrl are required)
55
+ * @throws Error if applicationId or daemonUrl are not provided
56
+ */
57
+ static init(opts) {
58
+ if (!opts.applicationId) {
59
+ throw new Error('applicationId is required for browser usage');
60
+ }
61
+ if (!opts.daemonUrl) {
62
+ throw new Error('daemonUrl is required for browser usage');
63
+ }
64
+ return new DrTrace(opts);
65
+ }
66
+ attachToConsole() {
67
+ if (!this.enabled)
68
+ return;
69
+ this.logger.attachToConsole();
70
+ }
71
+ detachFromConsole() {
72
+ this.logger.detachFromConsole();
73
+ }
74
+ log(message, level = 'info', context) {
75
+ if (!this.enabled)
76
+ return;
77
+ this.logger.log(level, message, context);
78
+ }
79
+ error(message, context) {
80
+ if (!this.enabled)
81
+ return;
82
+ this.logger.log('error', message, context);
83
+ }
84
+ async shutdown() {
85
+ await this.queue.flush();
86
+ this.queue.stop();
87
+ this.detachFromConsole();
88
+ }
89
+ }
90
+ exports.DrTrace = DrTrace;
91
+ __exportStar(require("./types"), exports);
@@ -5,7 +5,7 @@
5
5
  export interface DrTraceConfig {
6
6
  project_name: string;
7
7
  application_id: string;
8
- language?: "python" | "javascript" | "both";
8
+ language?: "python" | "javascript" | "cpp" | "both";
9
9
  daemon_url?: string;
10
10
  enabled?: boolean;
11
11
  environments?: string[];
@@ -23,7 +23,7 @@ export declare class ConfigSchema {
23
23
  static getDefaultConfig(options: {
24
24
  project_name: string;
25
25
  application_id: string;
26
- language?: "python" | "javascript" | "both";
26
+ language?: "python" | "javascript" | "cpp" | "both";
27
27
  daemon_url?: string;
28
28
  enabled?: boolean;
29
29
  environments?: string[];
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { DrTrace } from './client';
1
+ export { DrTrace } from './node';
2
2
  export { loadConfig } from './config';
3
3
  export * from './types';
package/dist/index.js CHANGED
@@ -15,8 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.loadConfig = exports.DrTrace = void 0;
18
- var client_1 = require("./client");
19
- Object.defineProperty(exports, "DrTrace", { enumerable: true, get: function () { return client_1.DrTrace; } });
18
+ var node_1 = require("./node");
19
+ Object.defineProperty(exports, "DrTrace", { enumerable: true, get: function () { return node_1.DrTrace; } });
20
20
  var config_1 = require("./config");
21
21
  Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_1.loadConfig; } });
22
22
  __exportStar(require("./types"), exports);
package/dist/init.d.ts CHANGED
@@ -12,6 +12,7 @@ export declare class ProjectInitializer {
12
12
  private projectRoot;
13
13
  private drtraceDir;
14
14
  private configPath;
15
+ private copiedAgentFiles;
15
16
  constructor(projectRoot?: string);
16
17
  /**
17
18
  * Run the interactive initialization workflow
@@ -34,7 +35,9 @@ export declare class ProjectInitializer {
34
35
  */
35
36
  private promptMultiSelect;
36
37
  /**
37
- * Handle existing config
38
+ * Handle existing config - prompt user before overwriting
39
+ *
40
+ * Returns true if initialization should proceed, false if user declined.
38
41
  */
39
42
  private handleExistingConfig;
40
43
  /**
@@ -46,19 +49,58 @@ export declare class ProjectInitializer {
46
49
  */
47
50
  private generateEnvironmentConfigs;
48
51
  /**
49
- * Copy agent spec to _drtrace/agents/
52
+ * Copy all agent files from packaged resources to _drtrace/agents/
53
+ * Copies everything from agents/ directory including:
54
+ * - Agent spec files (*.md)
55
+ * - Integration guides (integration-guides/*.md)
56
+ * - Any other files (README.md, CONTRIBUTING.md, etc.)
50
57
  */
51
58
  private copyAgentSpec;
59
+ /**
60
+ * Recursively copy all files from sourceDir to targetDir
61
+ * Returns list of relative file paths copied (for summary display)
62
+ */
63
+ private copyAgentsRecursive;
64
+ /**
65
+ * Copy framework-specific integration guides to _drtrace/agents/integration-guides/
66
+ * Dynamically discovers all .md files in agents/integration-guides/ directory
67
+ * Guides are stored in agents folder so agents can access them on client side
68
+ */
69
+ private copyFrameworkGuides;
70
+ /**
71
+ * Copy C++ header file to third_party/drtrace/ for C++ projects.
72
+ *
73
+ * This enables header-only integration:
74
+ * - Header is copied to third_party/drtrace/drtrace_sink.hpp
75
+ * - Users include it via #include "third_party/drtrace/drtrace_sink.hpp"
76
+ * - Note: third_party/drtrace/ should be committed to git (unlike _drtrace/ which is gitignored)
77
+ */
78
+ private copyCppHeader;
79
+ /**
80
+ * Find drtrace_sink.hpp source file for header-only C++ integration.
81
+ *
82
+ * Search order:
83
+ * 1. npm package location: dist/resources/cpp/drtrace_sink.hpp (production mode)
84
+ * 2. Monorepo development layout: packages/cpp/drtrace-client/src/drtrace_sink.hpp
85
+ * 3. pip package location: site-packages/drtrace_service/.../packages/cpp/drtrace-client/src/drtrace_sink.hpp (if Python available)
86
+ *
87
+ * @returns Path to header file if found, null otherwise
88
+ */
89
+ private findCppHeaderSource;
52
90
  /**
53
91
  * Get default agent spec from shared agents/ or bundled resources
54
92
  *
55
93
  * Search order:
56
94
  * 1. Root repo agents/ directory (development)
57
95
  * 2. Bundled default agent from node_modules
96
+ *
97
+ * @param agentName - Name of the agent: "log-analysis", "log-it", "log-init", or "log-help"
58
98
  */
59
99
  private getDefaultAgentSpec;
60
100
  /**
61
101
  * Get bundled agent spec (fallback when root agents/ not available)
102
+ *
103
+ * @param agentName - Name of the agent: "log-analysis", "log-it", "log-init", or "log-help"
62
104
  */
63
105
  private getBundledAgentSpec;
64
106
  private generateEnvExample;