@tigerdata/mcp-boilerplate 0.2.0 → 0.3.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/dist/cliEntrypoint.js +2 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/instrumentation.d.ts +12 -2
- package/dist/instrumentation.js +57 -47
- package/package.json +5 -1
package/dist/cliEntrypoint.js
CHANGED
|
@@ -17,7 +17,8 @@ export async function cliEntrypoint(stdioEntrypoint, httpEntrypoint, instrumenta
|
|
|
17
17
|
let cleanup;
|
|
18
18
|
if (args.includes('--instrument') ||
|
|
19
19
|
process.env.INSTRUMENT === 'true') {
|
|
20
|
-
|
|
20
|
+
const { instrument } = await import(instrumentation);
|
|
21
|
+
({ cleanup } = instrument());
|
|
21
22
|
}
|
|
22
23
|
// Import and run the HTTP server
|
|
23
24
|
const { registerCleanupFn } = await import(httpEntrypoint);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export { stdioServerFactory } from './stdio.js';
|
|
|
5
5
|
export { type ApiFactory } from './types.js';
|
|
6
6
|
export { StatusError } from './StatusError.js';
|
|
7
7
|
export { type AdditionalSetupArgs } from './mcpServer.js';
|
|
8
|
+
export { withSpan, addAiResultToSpan } from './tracing.js';
|
|
9
|
+
export { registerExitHandlers } from './registerExitHandlers.js';
|
package/dist/index.js
CHANGED
|
@@ -3,3 +3,5 @@ export { httpServerFactory } from './httpServer.js';
|
|
|
3
3
|
export { log } from './logger.js';
|
|
4
4
|
export { stdioServerFactory } from './stdio.js';
|
|
5
5
|
export { StatusError } from './StatusError.js';
|
|
6
|
+
export { withSpan, addAiResultToSpan } from './tracing.js';
|
|
7
|
+
export { registerExitHandlers } from './registerExitHandlers.js';
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node';
|
|
3
|
+
import type { Instrumentation } from '@opentelemetry/instrumentation';
|
|
4
|
+
interface Options {
|
|
5
|
+
environment?: string;
|
|
6
|
+
instrumentations?: Instrumentation[];
|
|
7
|
+
nodeAutoInstrumentationsOptions?: InstrumentationConfigMap;
|
|
8
|
+
}
|
|
9
|
+
export declare const instrument: (options?: Options) => {
|
|
10
|
+
cleanup: () => Promise<void>;
|
|
11
|
+
sdk: NodeSDK;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
package/dist/instrumentation.js
CHANGED
|
@@ -2,57 +2,67 @@ import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
|
2
2
|
import { resourceFromAttributes } from '@opentelemetry/resources';
|
|
3
3
|
import { OTLPTraceExporter as GrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
|
|
4
4
|
import { OTLPTraceExporter as HttpTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
5
|
-
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
5
|
+
import { getNodeAutoInstrumentations, } from '@opentelemetry/auto-instrumentations-node';
|
|
6
6
|
import { BatchSpanProcessor, } from '@opentelemetry/sdk-trace-base';
|
|
7
7
|
import { BatchLogRecordProcessor, } from '@opentelemetry/sdk-logs';
|
|
8
8
|
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';
|
|
9
9
|
import { log } from './logger.js';
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (process.env.JAEGER_TRACES_ENDPOINT) {
|
|
16
|
-
spanProcessors.push(new BatchSpanProcessor(new GrpcTraceExporter({
|
|
17
|
-
url: process.env.JAEGER_TRACES_ENDPOINT,
|
|
18
|
-
})));
|
|
19
|
-
}
|
|
20
|
-
if (process.env.LOGFIRE_TRACES_ENDPOINT) {
|
|
21
|
-
spanProcessors.push(new BatchSpanProcessor(new HttpTraceExporter({
|
|
22
|
-
url: process.env.LOGFIRE_TRACES_ENDPOINT,
|
|
23
|
-
headers: process.env.LOGFIRE_TOKEN
|
|
24
|
-
? { Authorization: `Bearer ${process.env.LOGFIRE_TOKEN}` }
|
|
25
|
-
: {},
|
|
26
|
-
})));
|
|
27
|
-
}
|
|
28
|
-
if (process.env.LOGFIRE_LOGS_ENDPOINT) {
|
|
29
|
-
logRecordProcessors.push(new BatchLogRecordProcessor(new OTLPLogExporter({
|
|
30
|
-
url: process.env.LOGFIRE_LOGS_ENDPOINT,
|
|
31
|
-
headers: process.env.LOGFIRE_TOKEN
|
|
32
|
-
? { Authorization: `Bearer ${process.env.LOGFIRE_TOKEN}` }
|
|
33
|
-
: {},
|
|
34
|
-
})));
|
|
35
|
-
}
|
|
36
|
-
export const sdk = new NodeSDK({
|
|
37
|
-
instrumentations: [getNodeAutoInstrumentations()],
|
|
38
|
-
spanProcessors,
|
|
39
|
-
logRecordProcessors,
|
|
40
|
-
resource: resourceFromAttributes({
|
|
41
|
-
'deployment.environment.name': process.env.LOGFIRE_ENVIRONMENT || process.env.NODE_ENV || 'development',
|
|
42
|
-
'service.instance.id': process.env.HOSTNAME,
|
|
43
|
-
}),
|
|
44
|
-
});
|
|
45
|
-
// Initialize the SDK and register with the OpenTelemetry API
|
|
46
|
-
sdk.start();
|
|
47
|
-
log.info('OpenTelemetry initialized');
|
|
48
|
-
export const cleanup = async () => {
|
|
49
|
-
try {
|
|
50
|
-
await Promise.all(spanProcessors.map((sp) => sp.shutdown()));
|
|
51
|
-
await Promise.all(logRecordProcessors.map((lp) => lp.shutdown()));
|
|
52
|
-
await sdk.shutdown();
|
|
53
|
-
log.info('OpenTelemetry terminated');
|
|
10
|
+
export const instrument = (options = {}) => {
|
|
11
|
+
const spanProcessors = [];
|
|
12
|
+
const logRecordProcessors = [];
|
|
13
|
+
if (process.env.OTEL_EXPORTER_OTLP_ENDPOINT) {
|
|
14
|
+
spanProcessors.push(new BatchSpanProcessor(new GrpcTraceExporter()));
|
|
54
15
|
}
|
|
55
|
-
|
|
56
|
-
|
|
16
|
+
if (process.env.JAEGER_TRACES_ENDPOINT) {
|
|
17
|
+
spanProcessors.push(new BatchSpanProcessor(new GrpcTraceExporter({
|
|
18
|
+
url: process.env.JAEGER_TRACES_ENDPOINT,
|
|
19
|
+
})));
|
|
57
20
|
}
|
|
21
|
+
if (process.env.LOGFIRE_TRACES_ENDPOINT) {
|
|
22
|
+
spanProcessors.push(new BatchSpanProcessor(new HttpTraceExporter({
|
|
23
|
+
url: process.env.LOGFIRE_TRACES_ENDPOINT,
|
|
24
|
+
headers: process.env.LOGFIRE_TOKEN
|
|
25
|
+
? { Authorization: `Bearer ${process.env.LOGFIRE_TOKEN}` }
|
|
26
|
+
: {},
|
|
27
|
+
})));
|
|
28
|
+
}
|
|
29
|
+
if (process.env.LOGFIRE_LOGS_ENDPOINT) {
|
|
30
|
+
logRecordProcessors.push(new BatchLogRecordProcessor(new OTLPLogExporter({
|
|
31
|
+
url: process.env.LOGFIRE_LOGS_ENDPOINT,
|
|
32
|
+
headers: process.env.LOGFIRE_TOKEN
|
|
33
|
+
? { Authorization: `Bearer ${process.env.LOGFIRE_TOKEN}` }
|
|
34
|
+
: {},
|
|
35
|
+
})));
|
|
36
|
+
}
|
|
37
|
+
const sdk = new NodeSDK({
|
|
38
|
+
instrumentations: options.instrumentations || [
|
|
39
|
+
getNodeAutoInstrumentations(options.nodeAutoInstrumentationsOptions),
|
|
40
|
+
],
|
|
41
|
+
spanProcessors,
|
|
42
|
+
logRecordProcessors,
|
|
43
|
+
resource: resourceFromAttributes({
|
|
44
|
+
'deployment.environment.name': options.environment ||
|
|
45
|
+
process.env.LOGFIRE_ENVIRONMENT ||
|
|
46
|
+
process.env.NODE_ENV ||
|
|
47
|
+
'development',
|
|
48
|
+
'service.instance.id': process.env.HOSTNAME,
|
|
49
|
+
}),
|
|
50
|
+
});
|
|
51
|
+
// Initialize the SDK and register with the OpenTelemetry API
|
|
52
|
+
sdk.start();
|
|
53
|
+
log.info('OpenTelemetry initialized');
|
|
54
|
+
return {
|
|
55
|
+
cleanup: async () => {
|
|
56
|
+
try {
|
|
57
|
+
await Promise.all(spanProcessors.map((sp) => sp.shutdown()));
|
|
58
|
+
await Promise.all(logRecordProcessors.map((lp) => lp.shutdown()));
|
|
59
|
+
await sdk.shutdown();
|
|
60
|
+
log.info('OpenTelemetry terminated');
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
log.error('Error terminating OpenTelemetry', error);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
sdk,
|
|
67
|
+
};
|
|
58
68
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tigerdata/mcp-boilerplate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "MCP boilerplate code for Node.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "TigerData",
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
".": {
|
|
17
17
|
"import": "./dist/index.js",
|
|
18
18
|
"types": "./dist/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./instrumentation": {
|
|
21
|
+
"import": "./dist/instrumentation.js",
|
|
22
|
+
"types": "./dist/instrumentation.d.ts"
|
|
19
23
|
}
|
|
20
24
|
},
|
|
21
25
|
"files": [
|