@comprehend/telemetry-node 0.1.3 → 0.2.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.
- package/.claude/settings.local.json +2 -1
- package/.idea/telemetry-node.iml +0 -1
- package/DEVELOPMENT.md +69 -0
- package/README.md +173 -0
- package/dist/ComprehendDevSpanProcessor.d.ts +9 -6
- package/dist/ComprehendDevSpanProcessor.js +146 -87
- package/dist/ComprehendDevSpanProcessor.test.d.ts +1 -0
- package/dist/ComprehendDevSpanProcessor.test.js +495 -0
- package/dist/ComprehendMetricsExporter.d.ts +18 -0
- package/dist/ComprehendMetricsExporter.js +178 -0
- package/dist/ComprehendMetricsExporter.test.d.ts +1 -0
- package/dist/ComprehendMetricsExporter.test.js +266 -0
- package/dist/ComprehendSDK.d.ts +18 -0
- package/dist/ComprehendSDK.js +56 -0
- package/dist/ComprehendSDK.test.d.ts +1 -0
- package/dist/ComprehendSDK.test.js +126 -0
- package/dist/WebSocketConnection.d.ts +23 -3
- package/dist/WebSocketConnection.js +106 -12
- package/dist/WebSocketConnection.test.d.ts +1 -0
- package/dist/WebSocketConnection.test.js +473 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -1
- package/dist/sql-analyzer.js +2 -11
- package/dist/sql-analyzer.test.js +0 -12
- package/dist/util.d.ts +2 -0
- package/dist/util.js +7 -0
- package/dist/wire-protocol.d.ts +168 -28
- package/jest.config.js +1 -0
- package/package.json +4 -2
- package/src/ComprehendDevSpanProcessor.test.ts +626 -0
- package/src/ComprehendDevSpanProcessor.ts +170 -105
- package/src/ComprehendMetricsExporter.test.ts +334 -0
- package/src/ComprehendMetricsExporter.ts +225 -0
- package/src/ComprehendSDK.test.ts +160 -0
- package/src/ComprehendSDK.ts +63 -0
- package/src/WebSocketConnection.test.ts +616 -0
- package/src/WebSocketConnection.ts +135 -13
- package/src/index.ts +3 -2
- package/src/util.ts +6 -0
- package/src/wire-protocol.ts +204 -29
- package/src/sql-analyzer.test.ts +0 -599
- package/src/sql-analyzer.ts +0 -439
package/.idea/telemetry-node.iml
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
<component name="NewModuleRootManager">
|
|
4
4
|
<content url="file://$MODULE_DIR$">
|
|
5
5
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
|
-
<excludeFolder url="file://$MODULE_DIR$/dist" />
|
|
7
6
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
8
7
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
9
8
|
</content>
|
package/DEVELOPMENT.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Development Guide
|
|
2
|
+
|
|
3
|
+
## Development Setup
|
|
4
|
+
|
|
5
|
+
1. Install dependencies:
|
|
6
|
+
```bash
|
|
7
|
+
npm install
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
2. Run tests:
|
|
11
|
+
```bash
|
|
12
|
+
npm test
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
3. Build the package:
|
|
16
|
+
```bash
|
|
17
|
+
npm run build
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Making a New Release
|
|
21
|
+
|
|
22
|
+
Follow these steps to release a new version:
|
|
23
|
+
|
|
24
|
+
### 1. Update Version Number
|
|
25
|
+
Edit `package.json` and update the version:
|
|
26
|
+
```json
|
|
27
|
+
{
|
|
28
|
+
"version": "0.1.4"
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### 2. Run Tests
|
|
33
|
+
Ensure all tests pass:
|
|
34
|
+
```bash
|
|
35
|
+
npm test
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 3. Build Distribution Package
|
|
39
|
+
Build the TypeScript files:
|
|
40
|
+
```bash
|
|
41
|
+
npm run build
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 4. Publish to npm
|
|
45
|
+
Publish the package (requires npm authentication):
|
|
46
|
+
```bash
|
|
47
|
+
npm publish
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 5. Verify Release
|
|
51
|
+
Check that the package is available:
|
|
52
|
+
```bash
|
|
53
|
+
# View on npm
|
|
54
|
+
open https://www.npmjs.com/package/@comprehend/telemetry-node
|
|
55
|
+
|
|
56
|
+
# Test installation
|
|
57
|
+
npm install @comprehend/telemetry-node@NEW_VERSION
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Version Strategy
|
|
61
|
+
- **Patch** (0.1.0 → 0.1.1): Bug fixes, small improvements
|
|
62
|
+
- **Minor** (0.1.0 → 0.2.0): New features, backward compatible
|
|
63
|
+
- **Major** (0.1.0 → 1.0.0): Breaking changes
|
|
64
|
+
|
|
65
|
+
### Prerequisites for Release
|
|
66
|
+
- npm account with publish access to @comprehend scope
|
|
67
|
+
- Authenticated with npm (`npm login`)
|
|
68
|
+
- All tests passing
|
|
69
|
+
- Clean working directory (no uncommitted changes recommended)
|
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# @comprehend/telemetry-node
|
|
2
|
+
|
|
3
|
+
OpenTelemetry integration for [comprehend.dev](https://comprehend.dev) - automatically capture and analyze your Node.js application's architecture, performance, and runtime metrics.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @comprehend/telemetry-node
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Starting from scratch
|
|
14
|
+
|
|
15
|
+
If you don't have OpenTelemetry set up yet, here's a complete setup:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @comprehend/telemetry-node @opentelemetry/sdk-node @opentelemetry/sdk-metrics @opentelemetry/auto-instrumentations-node
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { ComprehendSDK } from '@comprehend/telemetry-node';
|
|
23
|
+
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
24
|
+
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
|
|
25
|
+
import { Resource } from '@opentelemetry/resources';
|
|
26
|
+
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
27
|
+
|
|
28
|
+
const comprehend = new ComprehendSDK({
|
|
29
|
+
organization: 'your-org',
|
|
30
|
+
token: process.env.COMPREHEND_SDK_TOKEN!,
|
|
31
|
+
debug: true // Optional: enable debug logging (or pass a custom logger function)
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const sdk = new NodeSDK({
|
|
35
|
+
resource: new Resource({
|
|
36
|
+
'service.name': 'my-node-service',
|
|
37
|
+
'service.namespace': 'production',
|
|
38
|
+
'deployment.environment': 'prod'
|
|
39
|
+
}),
|
|
40
|
+
spanProcessors: [comprehend.getSpanProcessor()],
|
|
41
|
+
metricReader: new PeriodicExportingMetricReader({
|
|
42
|
+
exporter: comprehend.getMetricsExporter(),
|
|
43
|
+
exportIntervalMillis: 15000
|
|
44
|
+
}),
|
|
45
|
+
instrumentations: [getNodeAutoInstrumentations()],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
sdk.start();
|
|
49
|
+
|
|
50
|
+
// Graceful shutdown
|
|
51
|
+
process.on('SIGTERM', () => {
|
|
52
|
+
sdk.shutdown().then(() => console.log('Telemetry terminated'));
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Adding to existing OpenTelemetry setup
|
|
57
|
+
|
|
58
|
+
If you already have OpenTelemetry configured, create a `ComprehendSDK` instance and add its processor and exporter:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { ComprehendSDK } from '@comprehend/telemetry-node';
|
|
62
|
+
|
|
63
|
+
const comprehend = new ComprehendSDK({
|
|
64
|
+
organization: 'your-org',
|
|
65
|
+
token: process.env.COMPREHEND_SDK_TOKEN!,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Add to your NodeSDK config:
|
|
69
|
+
const sdk = new NodeSDK({
|
|
70
|
+
// ... your existing config
|
|
71
|
+
spanProcessors: [
|
|
72
|
+
// ... your existing processors
|
|
73
|
+
comprehend.getSpanProcessor()
|
|
74
|
+
],
|
|
75
|
+
metricReader: new PeriodicExportingMetricReader({
|
|
76
|
+
exporter: comprehend.getMetricsExporter(),
|
|
77
|
+
exportIntervalMillis: 15000
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Process and runtime metrics
|
|
83
|
+
|
|
84
|
+
For process-level and V8 runtime metrics (memory usage, event loop delay, GC duration, etc.), include `@opentelemetry/instrumentation-runtime-node` in your instrumentations:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm install @opentelemetry/instrumentation-runtime-node
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { RuntimeNodeInstrumentation } from '@opentelemetry/instrumentation-runtime-node';
|
|
92
|
+
|
|
93
|
+
const sdk = new NodeSDK({
|
|
94
|
+
// ...
|
|
95
|
+
instrumentations: [
|
|
96
|
+
getNodeAutoInstrumentations(),
|
|
97
|
+
new RuntimeNodeInstrumentation(),
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Host metrics (CPU and memory)
|
|
103
|
+
|
|
104
|
+
For process-level CPU utilization and memory usage, add `@opentelemetry/host-metrics`:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm install @opentelemetry/host-metrics
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { HostMetrics } from '@opentelemetry/host-metrics';
|
|
112
|
+
|
|
113
|
+
// Start after sdk.start()
|
|
114
|
+
const hostMetrics = new HostMetrics({
|
|
115
|
+
metricGroups: ['process.cpu', 'process.memory'],
|
|
116
|
+
});
|
|
117
|
+
hostMetrics.start();
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
This collects `process.cpu.time`, `process.cpu.utilization`, and `process.memory.usage`. The `metricGroups` option limits collection to process-level metrics only, avoiding the overhead of system-wide CPU, memory, and network data gathering.
|
|
121
|
+
|
|
122
|
+
## Configuration
|
|
123
|
+
|
|
124
|
+
Set your comprehend.dev SDK token as an environment variable:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
export COMPREHEND_SDK_TOKEN=your-token-here
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Note:** In production environments, the token should be stored in a secure secret management system (such as AWS Secrets Manager, HashiCorp Vault, Azure Key Vault, Kubernetes Secrets, or your cloud provider's secret management service) and injected into the environment through your container orchestrator's workload definition or service configuration.
|
|
131
|
+
|
|
132
|
+
## What it captures
|
|
133
|
+
|
|
134
|
+
This integration automatically captures:
|
|
135
|
+
|
|
136
|
+
- **HTTP Routes** - API endpoints and their usage patterns
|
|
137
|
+
- **Database Operations** - SQL queries (analysis done server-side)
|
|
138
|
+
- **Service Dependencies** - HTTP client calls to external services
|
|
139
|
+
- **Performance Metrics** - Request durations, response codes, error rates
|
|
140
|
+
- **Service Architecture** - Automatically maps your service relationships
|
|
141
|
+
- **Trace Spans** - Span identity and parent relationships for connecting observations to traces
|
|
142
|
+
- **Runtime Metrics** - Node.js memory, event loop, and V8 metrics
|
|
143
|
+
- **Custom Metrics** - Server-configured custom metric and span collection
|
|
144
|
+
|
|
145
|
+
## Requirements
|
|
146
|
+
|
|
147
|
+
- Node.js 14+
|
|
148
|
+
- OpenTelemetry SDK (peer dependencies: `@opentelemetry/api`, `@opentelemetry/sdk-trace-base`, `@opentelemetry/sdk-metrics`)
|
|
149
|
+
|
|
150
|
+
## Framework Support
|
|
151
|
+
|
|
152
|
+
Works with any Node.js framework that supports OpenTelemetry auto-instrumentation:
|
|
153
|
+
|
|
154
|
+
- Express
|
|
155
|
+
- Fastify
|
|
156
|
+
- Koa
|
|
157
|
+
- NestJS
|
|
158
|
+
- PostgreSQL
|
|
159
|
+
- MySQL
|
|
160
|
+
- MongoDB
|
|
161
|
+
- Prisma
|
|
162
|
+
- Sequelize
|
|
163
|
+
- TypeORM
|
|
164
|
+
- And more...
|
|
165
|
+
|
|
166
|
+
## Learn More
|
|
167
|
+
|
|
168
|
+
- Visit [comprehend.dev](https://comprehend.dev) for documentation and to get your ingestion token
|
|
169
|
+
- [OpenTelemetry JavaScript Documentation](https://opentelemetry.io/docs/languages/js/)
|
|
170
|
+
|
|
171
|
+
## Development
|
|
172
|
+
|
|
173
|
+
See [DEVELOPMENT.md](DEVELOPMENT.md) for development setup and release instructions.
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { Context } from "@opentelemetry/api";
|
|
2
2
|
import { ReadableSpan, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
3
|
+
import { SpanMatcherRule, CustomMetricSpecification } from "./wire-protocol";
|
|
4
|
+
import { WebSocketConnection } from "./WebSocketConnection";
|
|
3
5
|
export declare class ComprehendDevSpanProcessor implements SpanProcessor {
|
|
4
6
|
private readonly connection;
|
|
5
7
|
private observedServices;
|
|
6
8
|
private observedDatabases;
|
|
7
9
|
private observedHttpServices;
|
|
8
10
|
private observedInteractions;
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
debug?: boolean | ((message: string) => void);
|
|
14
|
-
});
|
|
11
|
+
private processContextSet;
|
|
12
|
+
private spanObservationSpecs;
|
|
13
|
+
constructor(connection: WebSocketConnection);
|
|
14
|
+
updateCustomMetrics(specs: CustomMetricSpecification[]): void;
|
|
15
15
|
onStart(span: Span, parentContext: Context): void;
|
|
16
16
|
onEnd(span: ReadableSpan): void;
|
|
17
17
|
private discoverService;
|
|
18
18
|
private processHTTPRoute;
|
|
19
19
|
private processDatabaseOperation;
|
|
20
20
|
private processHttpRequest;
|
|
21
|
+
private reportTraceSpan;
|
|
22
|
+
private checkCustomSpanMatching;
|
|
21
23
|
private getInteractions;
|
|
22
24
|
private ingestMessage;
|
|
23
25
|
forceFlush(): Promise<void>;
|
|
24
26
|
shutdown(): Promise<void>;
|
|
25
27
|
}
|
|
28
|
+
export declare function matchSpanRule(span: ReadableSpan, rule: SpanMatcherRule): boolean;
|