@unito/integration-sdk 5.1.0 → 5.1.1
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/src/index.cjs +48 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/integration.d.ts +1 -0
- package/dist/src/integration.js +2 -0
- package/dist/src/resources/tracer.d.ts +16 -0
- package/dist/src/resources/tracer.js +45 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/index.ts +1 -0
- package/src/integration.ts +3 -0
- package/src/resources/tracer.ts +50 -0
package/dist/src/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var integrationApi = require('@unito/integration-api');
|
|
|
4
4
|
var cachette = require('cachette');
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var util = require('util');
|
|
7
|
+
var tracer = require('dd-trace');
|
|
7
8
|
var express = require('express');
|
|
8
9
|
var busboy = require('busboy');
|
|
9
10
|
var fs = require('fs');
|
|
@@ -299,6 +300,51 @@ function create(redisUrl) {
|
|
|
299
300
|
}
|
|
300
301
|
const Cache = { create };
|
|
301
302
|
|
|
303
|
+
if (process.env.NODE_ENV === 'production' && process.env.DD_TRACE_ENABLED === 'true') {
|
|
304
|
+
// List of options available to the tracer: https://datadoghq.dev/dd-trace-js/interfaces/export_.TracerOptions.html
|
|
305
|
+
const apmConfig = { logInjection: false, profiling: false, sampleRate: 0 };
|
|
306
|
+
if (process.env.DD_APM_ENABLED == 'true') {
|
|
307
|
+
apmConfig.logInjection = true;
|
|
308
|
+
apmConfig.sampleRate = 1;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
// The "enable tracing" boolean is not exposed as part of the TracerOptions so we
|
|
312
|
+
// have to do so through env vars. Setting here instead of in services' config
|
|
313
|
+
// to avoid too many env vars to "flip" when enabling / disabling APM.
|
|
314
|
+
process.env.DD_TRACING_ENABLED = 'false';
|
|
315
|
+
}
|
|
316
|
+
// Profiling is extra $$$ so we're setting it as an "extra" when needed
|
|
317
|
+
if (process.env.DD_APM_PROFILING_ENABLED == 'true') {
|
|
318
|
+
apmConfig.profiling = true;
|
|
319
|
+
}
|
|
320
|
+
const tags = {};
|
|
321
|
+
// Using DD_TRACE_AGENT_URL as a hack to know if we're running inside of Kubernetes
|
|
322
|
+
// since this variable is not needed in Elastic Beanstalk of Lambda
|
|
323
|
+
if (process.env.DD_TRACE_AGENT_URL) {
|
|
324
|
+
tags.pod_name = process.env.HOSTNAME;
|
|
325
|
+
}
|
|
326
|
+
tracer.init({
|
|
327
|
+
...apmConfig, // Conditionally enable APM tracing & profiling
|
|
328
|
+
runtimeMetrics: true, // Always enable runtime metrics https://docs.datadoghq.com/tracing/metrics/runtime_metrics/nodejs/?tab=environmentvariables
|
|
329
|
+
tags,
|
|
330
|
+
}); // initialized in a different file to avoid hoisting.
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* WARNING to projects importing this
|
|
334
|
+
* Even if dd-tracer documents that instrumentation happens at **.init() time**
|
|
335
|
+
* (see https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#import-and-initialize-the-tracer ),
|
|
336
|
+
* 1. dd-tracer has no choice but to do some stuff **at import time**
|
|
337
|
+
* 2. dd-tracer is not exempt from bugs, like https://github.com/DataDog/dd-trace-js/issues/5211
|
|
338
|
+
*
|
|
339
|
+
* So, do not assume that dd-trace is *fully off* by default! Some of it runs!
|
|
340
|
+
* If you want to entirely disable all of dd-trace (e.g. during unit tests),
|
|
341
|
+
* then you must set `DD_TRACE_ENABLED=false`
|
|
342
|
+
*
|
|
343
|
+
* Q: Why not move the dd-trace import inside the `if DD_TRACE_ENABLED` condition, then?
|
|
344
|
+
* A: Because the future is ESM, and ESM imports must be static and top-level.
|
|
345
|
+
*/
|
|
346
|
+
const DD_TRACER = tracer;
|
|
347
|
+
|
|
302
348
|
/**
|
|
303
349
|
* Error class meant to be returned by integrations in case of exceptions. These errors will be caught and handled
|
|
304
350
|
* appropriately. Any other error would result in an unhandled server error accompanied by a 500 status code.
|
|
@@ -1062,6 +1108,7 @@ function onHealthCheck(_req, res) {
|
|
|
1062
1108
|
res.status(200).json({});
|
|
1063
1109
|
}
|
|
1064
1110
|
|
|
1111
|
+
// Must be the very first import so dd-trace instruments all subsequent modules.
|
|
1065
1112
|
function printErrorMessage(message) {
|
|
1066
1113
|
console.error();
|
|
1067
1114
|
console.error(`\x1b[31m Oops! Something went wrong! \x1b[0m`);
|
|
@@ -1830,6 +1877,7 @@ function buildCollectionQueryParams(params) {
|
|
|
1830
1877
|
|
|
1831
1878
|
exports.Api = integrationApi__namespace;
|
|
1832
1879
|
exports.Cache = Cache;
|
|
1880
|
+
exports.DD_TRACER = DD_TRACER;
|
|
1833
1881
|
exports.Handler = Handler;
|
|
1834
1882
|
exports.HttpErrors = httpErrors;
|
|
1835
1883
|
exports.Integration = Integration;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export * as HttpErrors from './httpErrors.js';
|
|
|
11
11
|
export { buildCollectionQueryParams, getApplicableFilters } from './helpers.js';
|
|
12
12
|
export * from './resources/context.js';
|
|
13
13
|
export { type default as Logger, NULL_LOGGER } from './resources/logger.js';
|
|
14
|
+
export { DD_TRACER } from './resources/tracer.js';
|
package/dist/src/index.js
CHANGED
|
@@ -9,4 +9,5 @@ export * as HttpErrors from './httpErrors.js';
|
|
|
9
9
|
export { buildCollectionQueryParams, getApplicableFilters } from './helpers.js';
|
|
10
10
|
export * from './resources/context.js';
|
|
11
11
|
export { NULL_LOGGER } from './resources/logger.js';
|
|
12
|
+
export { DD_TRACER } from './resources/tracer.js';
|
|
12
13
|
/* c8 ignore stop */
|
package/dist/src/integration.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import tracer from 'dd-trace';
|
|
2
|
+
/**
|
|
3
|
+
* WARNING to projects importing this
|
|
4
|
+
* Even if dd-tracer documents that instrumentation happens at **.init() time**
|
|
5
|
+
* (see https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#import-and-initialize-the-tracer ),
|
|
6
|
+
* 1. dd-tracer has no choice but to do some stuff **at import time**
|
|
7
|
+
* 2. dd-tracer is not exempt from bugs, like https://github.com/DataDog/dd-trace-js/issues/5211
|
|
8
|
+
*
|
|
9
|
+
* So, do not assume that dd-trace is *fully off* by default! Some of it runs!
|
|
10
|
+
* If you want to entirely disable all of dd-trace (e.g. during unit tests),
|
|
11
|
+
* then you must set `DD_TRACE_ENABLED=false`
|
|
12
|
+
*
|
|
13
|
+
* Q: Why not move the dd-trace import inside the `if DD_TRACE_ENABLED` condition, then?
|
|
14
|
+
* A: Because the future is ESM, and ESM imports must be static and top-level.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DD_TRACER: tracer.Tracer;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import tracer from 'dd-trace';
|
|
2
|
+
if (process.env.NODE_ENV === 'production' && process.env.DD_TRACE_ENABLED === 'true') {
|
|
3
|
+
// List of options available to the tracer: https://datadoghq.dev/dd-trace-js/interfaces/export_.TracerOptions.html
|
|
4
|
+
const apmConfig = { logInjection: false, profiling: false, sampleRate: 0 };
|
|
5
|
+
if (process.env.DD_APM_ENABLED == 'true') {
|
|
6
|
+
apmConfig.logInjection = true;
|
|
7
|
+
apmConfig.sampleRate = 1;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
// The "enable tracing" boolean is not exposed as part of the TracerOptions so we
|
|
11
|
+
// have to do so through env vars. Setting here instead of in services' config
|
|
12
|
+
// to avoid too many env vars to "flip" when enabling / disabling APM.
|
|
13
|
+
process.env.DD_TRACING_ENABLED = 'false';
|
|
14
|
+
}
|
|
15
|
+
// Profiling is extra $$$ so we're setting it as an "extra" when needed
|
|
16
|
+
if (process.env.DD_APM_PROFILING_ENABLED == 'true') {
|
|
17
|
+
apmConfig.profiling = true;
|
|
18
|
+
}
|
|
19
|
+
const tags = {};
|
|
20
|
+
// Using DD_TRACE_AGENT_URL as a hack to know if we're running inside of Kubernetes
|
|
21
|
+
// since this variable is not needed in Elastic Beanstalk of Lambda
|
|
22
|
+
if (process.env.DD_TRACE_AGENT_URL) {
|
|
23
|
+
tags.pod_name = process.env.HOSTNAME;
|
|
24
|
+
}
|
|
25
|
+
tracer.init({
|
|
26
|
+
...apmConfig, // Conditionally enable APM tracing & profiling
|
|
27
|
+
runtimeMetrics: true, // Always enable runtime metrics https://docs.datadoghq.com/tracing/metrics/runtime_metrics/nodejs/?tab=environmentvariables
|
|
28
|
+
tags,
|
|
29
|
+
}); // initialized in a different file to avoid hoisting.
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* WARNING to projects importing this
|
|
33
|
+
* Even if dd-tracer documents that instrumentation happens at **.init() time**
|
|
34
|
+
* (see https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#import-and-initialize-the-tracer ),
|
|
35
|
+
* 1. dd-tracer has no choice but to do some stuff **at import time**
|
|
36
|
+
* 2. dd-tracer is not exempt from bugs, like https://github.com/DataDog/dd-trace-js/issues/5211
|
|
37
|
+
*
|
|
38
|
+
* So, do not assume that dd-trace is *fully off* by default! Some of it runs!
|
|
39
|
+
* If you want to entirely disable all of dd-trace (e.g. during unit tests),
|
|
40
|
+
* then you must set `DD_TRACE_ENABLED=false`
|
|
41
|
+
*
|
|
42
|
+
* Q: Why not move the dd-trace import inside the `if DD_TRACE_ENABLED` condition, then?
|
|
43
|
+
* A: Because the future is ESM, and ESM imports must be static and top-level.
|
|
44
|
+
*/
|
|
45
|
+
export const DD_TRACER = tracer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/errors.ts","../src/handler.ts","../src/helpers.ts","../src/httpErrors.ts","../src/index.ts","../src/integration.ts","../src/middlewares/correlationId.ts","../src/middlewares/credentials.ts","../src/middlewares/errors.ts","../src/middlewares/filters.ts","../src/middlewares/finish.ts","../src/middlewares/health.ts","../src/middlewares/logger.ts","../src/middlewares/notFound.ts","../src/middlewares/relations.ts","../src/middlewares/search.ts","../src/middlewares/secrets.ts","../src/middlewares/selects.ts","../src/middlewares/signal.ts","../src/middlewares/start.ts","../src/resources/cache.ts","../src/resources/context.ts","../src/resources/logger.ts","../src/resources/provider.ts","../src/resources/requestMetrics.ts","../test/errors.test.ts","../test/handler.test.ts","../test/helpers.test.ts","../test/integration.test.ts","../test/middlewares/correlationId.test.ts","../test/middlewares/credentials.test.ts","../test/middlewares/errors.test.ts","../test/middlewares/filters.test.ts","../test/middlewares/finish.test.ts","../test/middlewares/health.test.ts","../test/middlewares/logger.test.ts","../test/middlewares/notFound.test.ts","../test/middlewares/relations.test.ts","../test/middlewares/search.test.ts","../test/middlewares/secrets.test.ts","../test/middlewares/selects.test.ts","../test/middlewares/signal.test.ts","../test/middlewares/start.test.ts","../test/resources/cache.test.ts","../test/resources/logger.test.ts","../test/resources/provider.test.ts","../test/resources/requestMetrics.test.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["../src/errors.ts","../src/handler.ts","../src/helpers.ts","../src/httpErrors.ts","../src/index.ts","../src/integration.ts","../src/middlewares/correlationId.ts","../src/middlewares/credentials.ts","../src/middlewares/errors.ts","../src/middlewares/filters.ts","../src/middlewares/finish.ts","../src/middlewares/health.ts","../src/middlewares/logger.ts","../src/middlewares/notFound.ts","../src/middlewares/relations.ts","../src/middlewares/search.ts","../src/middlewares/secrets.ts","../src/middlewares/selects.ts","../src/middlewares/signal.ts","../src/middlewares/start.ts","../src/resources/cache.ts","../src/resources/context.ts","../src/resources/logger.ts","../src/resources/provider.ts","../src/resources/requestMetrics.ts","../src/resources/tracer.ts","../test/errors.test.ts","../test/handler.test.ts","../test/helpers.test.ts","../test/integration.test.ts","../test/middlewares/correlationId.test.ts","../test/middlewares/credentials.test.ts","../test/middlewares/errors.test.ts","../test/middlewares/filters.test.ts","../test/middlewares/finish.test.ts","../test/middlewares/health.test.ts","../test/middlewares/logger.test.ts","../test/middlewares/notFound.test.ts","../test/middlewares/relations.test.ts","../test/middlewares/search.test.ts","../test/middlewares/secrets.test.ts","../test/middlewares/selects.test.ts","../test/middlewares/signal.test.ts","../test/middlewares/start.test.ts","../test/resources/cache.test.ts","../test/resources/logger.test.ts","../test/resources/provider.test.ts","../test/resources/requestMetrics.test.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unito/integration-sdk",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.1",
|
|
4
4
|
"description": "Integration SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"@unito/integration-api": "7.x",
|
|
57
57
|
"busboy": "^1.6.0",
|
|
58
58
|
"cachette": "4.x",
|
|
59
|
+
"dd-trace": "5.x",
|
|
59
60
|
"express": "^5.1",
|
|
60
61
|
"form-data": "^4.0.0"
|
|
61
62
|
},
|
package/src/index.ts
CHANGED
|
@@ -18,4 +18,5 @@ export * as HttpErrors from './httpErrors.js';
|
|
|
18
18
|
export { buildCollectionQueryParams, getApplicableFilters } from './helpers.js';
|
|
19
19
|
export * from './resources/context.js';
|
|
20
20
|
export { type default as Logger, NULL_LOGGER } from './resources/logger.js';
|
|
21
|
+
export { DD_TRACER } from './resources/tracer.js';
|
|
21
22
|
/* c8 ignore stop */
|
package/src/integration.ts
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import tracer, { TracerOptions } from 'dd-trace';
|
|
2
|
+
|
|
3
|
+
if (process.env.NODE_ENV === 'production' && process.env.DD_TRACE_ENABLED === 'true') {
|
|
4
|
+
// List of options available to the tracer: https://datadoghq.dev/dd-trace-js/interfaces/export_.TracerOptions.html
|
|
5
|
+
const apmConfig: TracerOptions = { logInjection: false, profiling: false, sampleRate: 0 };
|
|
6
|
+
|
|
7
|
+
if (process.env.DD_APM_ENABLED == 'true') {
|
|
8
|
+
apmConfig.logInjection = true;
|
|
9
|
+
apmConfig.sampleRate = 1;
|
|
10
|
+
} else {
|
|
11
|
+
// The "enable tracing" boolean is not exposed as part of the TracerOptions so we
|
|
12
|
+
// have to do so through env vars. Setting here instead of in services' config
|
|
13
|
+
// to avoid too many env vars to "flip" when enabling / disabling APM.
|
|
14
|
+
process.env.DD_TRACING_ENABLED = 'false';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Profiling is extra $$$ so we're setting it as an "extra" when needed
|
|
18
|
+
if (process.env.DD_APM_PROFILING_ENABLED == 'true') {
|
|
19
|
+
apmConfig.profiling = true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const tags: { [key: string]: any } = {};
|
|
23
|
+
// Using DD_TRACE_AGENT_URL as a hack to know if we're running inside of Kubernetes
|
|
24
|
+
// since this variable is not needed in Elastic Beanstalk of Lambda
|
|
25
|
+
if (process.env.DD_TRACE_AGENT_URL) {
|
|
26
|
+
tags.pod_name = process.env.HOSTNAME;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
tracer.init({
|
|
30
|
+
...apmConfig, // Conditionally enable APM tracing & profiling
|
|
31
|
+
runtimeMetrics: true, // Always enable runtime metrics https://docs.datadoghq.com/tracing/metrics/runtime_metrics/nodejs/?tab=environmentvariables
|
|
32
|
+
tags,
|
|
33
|
+
}); // initialized in a different file to avoid hoisting.
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* WARNING to projects importing this
|
|
38
|
+
* Even if dd-tracer documents that instrumentation happens at **.init() time**
|
|
39
|
+
* (see https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/nodejs/#import-and-initialize-the-tracer ),
|
|
40
|
+
* 1. dd-tracer has no choice but to do some stuff **at import time**
|
|
41
|
+
* 2. dd-tracer is not exempt from bugs, like https://github.com/DataDog/dd-trace-js/issues/5211
|
|
42
|
+
*
|
|
43
|
+
* So, do not assume that dd-trace is *fully off* by default! Some of it runs!
|
|
44
|
+
* If you want to entirely disable all of dd-trace (e.g. during unit tests),
|
|
45
|
+
* then you must set `DD_TRACE_ENABLED=false`
|
|
46
|
+
*
|
|
47
|
+
* Q: Why not move the dd-trace import inside the `if DD_TRACE_ENABLED` condition, then?
|
|
48
|
+
* A: Because the future is ESM, and ESM imports must be static and top-level.
|
|
49
|
+
*/
|
|
50
|
+
export const DD_TRACER = tracer;
|