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
@@ -1,66 +0,0 @@
1
- import { DrTrace } from '../src/client';
2
- import { loadConfig } from '../src/config';
3
-
4
- jest.mock('../src/config', () => {
5
- return {
6
- loadConfig: jest.fn(() => ({
7
- project: { name: 'my-app' },
8
- drtrace: {
9
- applicationId: 'app',
10
- daemonUrl: 'http://localhost:8001',
11
- enabled: true,
12
- logLevel: 'info',
13
- batchSize: 2,
14
- flushIntervalMs: 1000,
15
- },
16
- })),
17
- };
18
- });
19
-
20
- // Mock fetch for transport
21
- const mockFetch = jest.fn(async () => ({ body: { pipe: () => {} }, text: async () => '' } as any));
22
- (global as any).fetch = mockFetch as any;
23
-
24
- describe('DrTrace client', () => {
25
- beforeEach(() => {
26
- mockFetch.mockClear();
27
- (loadConfig as jest.Mock).mockClear();
28
- });
29
-
30
- it('initializes from loadConfig and attaches console', async () => {
31
- const client = DrTrace.init();
32
- client.attachToConsole();
33
-
34
- console.log('hello');
35
- console.error('oops');
36
-
37
- // Because batchSize=2, the two logs will trigger flush
38
- expect(mockFetch).toHaveBeenCalledTimes(1);
39
- const url = (mockFetch.mock.calls[0] as any)[0];
40
- expect(url).toBe('http://localhost:8001/logs/ingest');
41
-
42
- await client.shutdown();
43
- });
44
-
45
- it('respects enabled=false', async () => {
46
- (loadConfig as jest.Mock).mockReturnValueOnce({
47
- project: { name: 'my-app' },
48
- drtrace: {
49
- applicationId: 'app',
50
- daemonUrl: 'http://localhost:8001',
51
- enabled: false,
52
- logLevel: 'info',
53
- batchSize: 2,
54
- flushIntervalMs: 1000,
55
- },
56
- });
57
-
58
- const client = DrTrace.init();
59
- client.attachToConsole();
60
-
61
- console.log('hello');
62
- expect(mockFetch).toHaveBeenCalledTimes(0);
63
-
64
- await client.shutdown();
65
- });
66
- });
@@ -1,198 +0,0 @@
1
- /**
2
- * Comprehensive tests for DrTrace JavaScript Config Schema and Init
3
- */
4
-
5
- import * as fs from "fs";
6
- import * as path from "path";
7
- import { ConfigSchema, DrTraceConfig } from "../src/config-schema";
8
- import { ProjectInitializer } from "../src/init";
9
- import * as os from "os";
10
-
11
- describe("ConfigSchema", () => {
12
- describe("getDefaultConfig", () => {
13
- it("should generate default config with required fields", () => {
14
- const config = ConfigSchema.getDefaultConfig({
15
- project_name: "test-app",
16
- application_id: "test-app-123",
17
- });
18
-
19
- expect(config.project_name).toBe("test-app");
20
- expect(config.application_id).toBe("test-app-123");
21
- expect(config.language).toBe("javascript");
22
- expect(config.daemon_url).toBe("http://localhost:8001");
23
- expect(config.enabled).toBe(true);
24
- expect(config.created_at).toBeDefined();
25
- });
26
-
27
- it("should accept custom values", () => {
28
- const config = ConfigSchema.getDefaultConfig({
29
- project_name: "my-project",
30
- application_id: "my-app",
31
- language: "python",
32
- daemon_url: "http://prod:8001",
33
- enabled: false,
34
- environments: ["production", "staging"],
35
- agent_enabled: true,
36
- agent_framework: "langchain",
37
- });
38
-
39
- expect(config.language).toBe("python");
40
- expect(config.daemon_url).toBe("http://prod:8001");
41
- expect(config.enabled).toBe(false);
42
- expect(config.environments).toEqual(["production", "staging"]);
43
- expect(config.agent?.enabled).toBe(true);
44
- expect(config.agent?.framework).toBe("langchain");
45
- });
46
- });
47
-
48
- describe("validate", () => {
49
- it("should require project_name", () => {
50
- const config: any = { application_id: "test" };
51
- expect(() => ConfigSchema.validate(config)).toThrow(
52
- "Missing required field: project_name"
53
- );
54
- });
55
-
56
- it("should require application_id", () => {
57
- const config: any = { project_name: "test" };
58
- expect(() => ConfigSchema.validate(config)).toThrow(
59
- "Missing required field: application_id"
60
- );
61
- });
62
-
63
- it("should accept valid environments", () => {
64
- const config = ConfigSchema.getDefaultConfig({
65
- project_name: "test",
66
- application_id: "test",
67
- environments: ["development", "production"],
68
- });
69
- expect(() => ConfigSchema.validate(config)).not.toThrow();
70
- });
71
-
72
- it("should reject invalid environments", () => {
73
- const config = ConfigSchema.getDefaultConfig({
74
- project_name: "test",
75
- application_id: "test",
76
- environments: ["development", "invalid-env"] as any,
77
- });
78
- expect(() => ConfigSchema.validate(config)).toThrow(
79
- "Invalid environment"
80
- );
81
- });
82
- });
83
-
84
- describe("save and load", () => {
85
- it("should save and load config files", () => {
86
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "drtrace-test-"));
87
- const configPath = path.join(tmpDir, "config.json");
88
-
89
- const original = ConfigSchema.getDefaultConfig({
90
- project_name: "test-app",
91
- application_id: "test-app",
92
- });
93
-
94
- ConfigSchema.save(original, configPath);
95
- expect(fs.existsSync(configPath)).toBe(true);
96
-
97
- const loaded = ConfigSchema.load(configPath);
98
- expect(loaded.project_name).toBe(original.project_name);
99
- expect(loaded.application_id).toBe(original.application_id);
100
-
101
- // Cleanup
102
- fs.rmSync(tmpDir, { recursive: true });
103
- });
104
-
105
- it("should throw on nonexistent file", () => {
106
- expect(() => ConfigSchema.load("/nonexistent/path/config.json")).toThrow(
107
- "Config file not found"
108
- );
109
- });
110
- });
111
- });
112
-
113
- describe("ProjectInitializer", () => {
114
- it("should initialize with custom project root", () => {
115
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "drtrace-test-"));
116
- const initializer = new ProjectInitializer(tmpDir);
117
-
118
- expect((initializer as any).projectRoot).toBe(tmpDir);
119
- expect((initializer as any).drtraceDir).toBe(path.join(tmpDir, "_drtrace"));
120
-
121
- fs.rmSync(tmpDir, { recursive: true });
122
- });
123
-
124
- it("should create directory structure", () => {
125
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "drtrace-test-"));
126
- const initializer = new ProjectInitializer(tmpDir);
127
-
128
- (initializer as any).createDirectoryStructure();
129
-
130
- expect(fs.existsSync(path.join(tmpDir, "_drtrace"))).toBe(true);
131
- expect(fs.existsSync(path.join(tmpDir, "_drtrace", "agents"))).toBe(true);
132
-
133
- fs.rmSync(tmpDir, { recursive: true });
134
- });
135
-
136
- it("should generate environment configs", () => {
137
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "drtrace-test-"));
138
- const initializer = new ProjectInitializer(tmpDir);
139
-
140
- (initializer as any).createDirectoryStructure();
141
-
142
- const config = ConfigSchema.getDefaultConfig({
143
- project_name: "test",
144
- application_id: "test",
145
- environments: ["development", "production"],
146
- });
147
-
148
- (initializer as any).generateEnvironmentConfigs(config);
149
-
150
- expect(
151
- fs.existsSync(path.join(tmpDir, "_drtrace", "config.development.json"))
152
- ).toBe(true);
153
- expect(
154
- fs.existsSync(path.join(tmpDir, "_drtrace", "config.production.json"))
155
- ).toBe(true);
156
-
157
- fs.rmSync(tmpDir, { recursive: true });
158
- });
159
-
160
- it("should generate .env.example", () => {
161
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "drtrace-test-"));
162
- const initializer = new ProjectInitializer(tmpDir);
163
-
164
- (initializer as any).createDirectoryStructure();
165
-
166
- const config = ConfigSchema.getDefaultConfig({
167
- project_name: "test",
168
- application_id: "test-app-123",
169
- });
170
-
171
- (initializer as any).generateEnvExample(config);
172
-
173
- const envFile = path.join(tmpDir, "_drtrace", ".env.example");
174
- expect(fs.existsSync(envFile)).toBe(true);
175
-
176
- const content = fs.readFileSync(envFile, "utf-8");
177
- expect(content).toContain("DRTRACE_APPLICATION_ID=test-app-123");
178
- expect(content).toContain("DRTRACE_DAEMON_URL=http://localhost:8001");
179
-
180
- fs.rmSync(tmpDir, { recursive: true });
181
- });
182
-
183
- it("should generate README", () => {
184
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "drtrace-test-"));
185
- const initializer = new ProjectInitializer(tmpDir);
186
-
187
- (initializer as any).createDirectoryStructure();
188
- (initializer as any).generateReadme();
189
-
190
- const readmeFile = path.join(tmpDir, "_drtrace", "README.md");
191
- expect(fs.existsSync(readmeFile)).toBe(true);
192
-
193
- const content = fs.readFileSync(readmeFile, "utf-8");
194
- expect(content).toContain("DrTrace Configuration Guide");
195
-
196
- fs.rmSync(tmpDir, { recursive: true });
197
- });
198
- });