@loglayer/plugin-datadog-apm-trace-injector 1.0.6 → 1.0.7
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/index.cjs +26 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -14
- package/dist/index.d.ts +18 -14
- package/dist/index.js +27 -25
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region src/plugin.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new Datadog trace injector plugin.
|
|
5
|
+
*
|
|
6
|
+
* This plugin injects the current Datadog APM trace context into the log data.
|
|
7
|
+
*
|
|
8
|
+
* @param config - The datadog trace injector plugin configuration
|
|
9
|
+
* @returns A LogLayer plugin instance
|
|
10
|
+
*/
|
|
2
11
|
function datadogTraceInjectorPlugin(config) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
config.onError(error, data);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
12
|
+
const tracer = config.tracerInstance;
|
|
13
|
+
return {
|
|
14
|
+
id: config.id,
|
|
15
|
+
disabled: config.disabled,
|
|
16
|
+
onBeforeDataOut({ data }) {
|
|
17
|
+
if (!data) data = {};
|
|
18
|
+
try {
|
|
19
|
+
const span = tracer.scope().active();
|
|
20
|
+
if (span) tracer.inject(span.context(), "log", data);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (config.onError && error instanceof Error) config.onError(error, data);
|
|
23
|
+
}
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
//#endregion
|
|
27
30
|
exports.datadogTraceInjectorPlugin = datadogTraceInjectorPlugin;
|
|
28
31
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { LogLayerPlugin, PluginBeforeDataOutParams } from \"@loglayer/plugin\";\nimport type { DatadogTraceInjectorPluginParams } from \"./types.js\";\n\n/**\n * Creates a new Datadog trace injector plugin.\n *\n * This plugin injects the current Datadog APM trace context into the log data.\n *\n * @param config - The datadog trace injector plugin configuration\n * @returns A LogLayer plugin instance\n */\nexport function datadogTraceInjectorPlugin(config: DatadogTraceInjectorPluginParams): LogLayerPlugin {\n const tracer = config.tracerInstance;\n\n return {\n id: config.id,\n disabled: config.disabled,\n onBeforeDataOut({ data }: PluginBeforeDataOutParams): Record<string, any> {\n if (!data) {\n data = {};\n }\n\n try {\n // Associates log with APM trace\n // https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/nodejs/\n const span = tracer.scope().active();\n\n if (span) {\n tracer.inject(span.context(), \"log\", data);\n }\n } catch (error) {\n // Call error handler if provided, otherwise silently continue\n if (config.onError && error instanceof Error) {\n config.onError(error, data);\n }\n // Continue logging even if tracer operations fail\n // This ensures logging doesn't break if dd-trace has issues\n }\n\n return data;\n },\n };\n}\n"],"mappings":";;;;;;;;;;AAWA,SAAgB,2BAA2B,QAA0D;CACnG,MAAM,SAAS,OAAO;AAEtB,QAAO;EACL,IAAI,OAAO;EACX,UAAU,OAAO;EACjB,gBAAgB,EAAE,QAAwD;AACxE,OAAI,CAAC,KACH,QAAO,EAAE;AAGX,OAAI;IAGF,MAAM,OAAO,OAAO,OAAO,CAAC,QAAQ;AAEpC,QAAI,KACF,QAAO,OAAO,KAAK,SAAS,EAAE,OAAO,KAAK;YAErC,OAAO;AAEd,QAAI,OAAO,WAAW,iBAAiB,MACrC,QAAO,QAAQ,OAAO,KAAK;;AAM/B,UAAO;;EAEV"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Tracer } from
|
|
1
|
+
import { LogLayerPlugin, LogLayerPluginParams } from "@loglayer/plugin";
|
|
2
|
+
import { Tracer } from "dd-trace";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Configuration parameters for the datadog trace injector plugin.
|
|
6
8
|
*/
|
|
7
9
|
interface DatadogTraceInjectorPluginParams extends LogLayerPluginParams {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
/**
|
|
11
|
+
* dd-trace tracer instance
|
|
12
|
+
*/
|
|
13
|
+
tracerInstance: Tracer;
|
|
14
|
+
/**
|
|
15
|
+
* Optional error handler for tracer operation failures
|
|
16
|
+
* @param error - The error that occurred during tracer operations
|
|
17
|
+
* @param data - The log data that was being processed when the error occurred
|
|
18
|
+
*/
|
|
19
|
+
onError?: (error: Error, data?: Record<string, any>) => void;
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/plugin.d.ts
|
|
20
23
|
/**
|
|
21
24
|
* Creates a new Datadog trace injector plugin.
|
|
22
25
|
*
|
|
@@ -26,5 +29,6 @@ interface DatadogTraceInjectorPluginParams extends LogLayerPluginParams {
|
|
|
26
29
|
* @returns A LogLayer plugin instance
|
|
27
30
|
*/
|
|
28
31
|
declare function datadogTraceInjectorPlugin(config: DatadogTraceInjectorPluginParams): LogLayerPlugin;
|
|
29
|
-
|
|
32
|
+
//#endregion
|
|
30
33
|
export { type DatadogTraceInjectorPluginParams, datadogTraceInjectorPlugin };
|
|
34
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Tracer } from
|
|
1
|
+
import { LogLayerPlugin, LogLayerPluginParams } from "@loglayer/plugin";
|
|
2
|
+
import { Tracer } from "dd-trace";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Configuration parameters for the datadog trace injector plugin.
|
|
6
8
|
*/
|
|
7
9
|
interface DatadogTraceInjectorPluginParams extends LogLayerPluginParams {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
/**
|
|
11
|
+
* dd-trace tracer instance
|
|
12
|
+
*/
|
|
13
|
+
tracerInstance: Tracer;
|
|
14
|
+
/**
|
|
15
|
+
* Optional error handler for tracer operation failures
|
|
16
|
+
* @param error - The error that occurred during tracer operations
|
|
17
|
+
* @param data - The log data that was being processed when the error occurred
|
|
18
|
+
*/
|
|
19
|
+
onError?: (error: Error, data?: Record<string, any>) => void;
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/plugin.d.ts
|
|
20
23
|
/**
|
|
21
24
|
* Creates a new Datadog trace injector plugin.
|
|
22
25
|
*
|
|
@@ -26,5 +29,6 @@ interface DatadogTraceInjectorPluginParams extends LogLayerPluginParams {
|
|
|
26
29
|
* @returns A LogLayer plugin instance
|
|
27
30
|
*/
|
|
28
31
|
declare function datadogTraceInjectorPlugin(config: DatadogTraceInjectorPluginParams): LogLayerPlugin;
|
|
29
|
-
|
|
32
|
+
//#endregion
|
|
30
33
|
export { type DatadogTraceInjectorPluginParams, datadogTraceInjectorPlugin };
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/plugin.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new Datadog trace injector plugin.
|
|
4
|
+
*
|
|
5
|
+
* This plugin injects the current Datadog APM trace context into the log data.
|
|
6
|
+
*
|
|
7
|
+
* @param config - The datadog trace injector plugin configuration
|
|
8
|
+
* @returns A LogLayer plugin instance
|
|
9
|
+
*/
|
|
2
10
|
function datadogTraceInjectorPlugin(config) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
config.onError(error, data);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
11
|
+
const tracer = config.tracerInstance;
|
|
12
|
+
return {
|
|
13
|
+
id: config.id,
|
|
14
|
+
disabled: config.disabled,
|
|
15
|
+
onBeforeDataOut({ data }) {
|
|
16
|
+
if (!data) data = {};
|
|
17
|
+
try {
|
|
18
|
+
const span = tracer.scope().active();
|
|
19
|
+
if (span) tracer.inject(span.context(), "log", data);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (config.onError && error instanceof Error) config.onError(error, data);
|
|
22
|
+
}
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { datadogTraceInjectorPlugin };
|
|
28
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { LogLayerPlugin, PluginBeforeDataOutParams } from \"@loglayer/plugin\";\nimport type { DatadogTraceInjectorPluginParams } from \"./types.js\";\n\n/**\n * Creates a new Datadog trace injector plugin.\n *\n * This plugin injects the current Datadog APM trace context into the log data.\n *\n * @param config - The datadog trace injector plugin configuration\n * @returns A LogLayer plugin instance\n */\nexport function datadogTraceInjectorPlugin(config: DatadogTraceInjectorPluginParams): LogLayerPlugin {\n const tracer = config.tracerInstance;\n\n return {\n id: config.id,\n disabled: config.disabled,\n onBeforeDataOut({ data }: PluginBeforeDataOutParams): Record<string, any> {\n if (!data) {\n data = {};\n }\n\n try {\n // Associates log with APM trace\n // https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/nodejs/\n const span = tracer.scope().active();\n\n if (span) {\n tracer.inject(span.context(), \"log\", data);\n }\n } catch (error) {\n // Call error handler if provided, otherwise silently continue\n if (config.onError && error instanceof Error) {\n config.onError(error, data);\n }\n // Continue logging even if tracer operations fail\n // This ensures logging doesn't break if dd-trace has issues\n }\n\n return data;\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { LogLayerPlugin, PluginBeforeDataOutParams } from \"@loglayer/plugin\";\nimport type { DatadogTraceInjectorPluginParams } from \"./types.js\";\n\n/**\n * Creates a new Datadog trace injector plugin.\n *\n * This plugin injects the current Datadog APM trace context into the log data.\n *\n * @param config - The datadog trace injector plugin configuration\n * @returns A LogLayer plugin instance\n */\nexport function datadogTraceInjectorPlugin(config: DatadogTraceInjectorPluginParams): LogLayerPlugin {\n const tracer = config.tracerInstance;\n\n return {\n id: config.id,\n disabled: config.disabled,\n onBeforeDataOut({ data }: PluginBeforeDataOutParams): Record<string, any> {\n if (!data) {\n data = {};\n }\n\n try {\n // Associates log with APM trace\n // https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/nodejs/\n const span = tracer.scope().active();\n\n if (span) {\n tracer.inject(span.context(), \"log\", data);\n }\n } catch (error) {\n // Call error handler if provided, otherwise silently continue\n if (config.onError && error instanceof Error) {\n config.onError(error, data);\n }\n // Continue logging even if tracer operations fail\n // This ensures logging doesn't break if dd-trace has issues\n }\n\n return data;\n },\n };\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,2BAA2B,QAA0D;CACnG,MAAM,SAAS,OAAO;AAEtB,QAAO;EACL,IAAI,OAAO;EACX,UAAU,OAAO;EACjB,gBAAgB,EAAE,QAAwD;AACxE,OAAI,CAAC,KACH,QAAO,EAAE;AAGX,OAAI;IAGF,MAAM,OAAO,OAAO,OAAO,CAAC,QAAQ;AAEpC,QAAI,KACF,QAAO,OAAO,KAAK,SAAS,EAAE,OAAO,KAAK;YAErC,OAAO;AAEd,QAAI,OAAO,WAAW,iBAAiB,MACrC,QAAO,QAAQ,OAAO,KAAK;;AAM/B,UAAO;;EAEV"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loglayer/plugin-datadog-apm-trace-injector",
|
|
3
3
|
"description": "Injects DataDog APM traces to logs in LogLayer.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.7",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"dd-trace"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@loglayer/plugin": "2.1.
|
|
40
|
-
"@loglayer/shared": "2.5.
|
|
39
|
+
"@loglayer/plugin": "2.1.6",
|
|
40
|
+
"@loglayer/shared": "2.5.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@types/node": "24.
|
|
43
|
+
"@types/node": "24.7.2",
|
|
44
|
+
"dd-trace": "5.71.0",
|
|
44
45
|
"express": "5.1.0",
|
|
45
|
-
"
|
|
46
|
-
"tsup": "8.5.0",
|
|
46
|
+
"tsdown": "0.15.7",
|
|
47
47
|
"tsx": "4.20.6",
|
|
48
48
|
"typescript": "5.9.3",
|
|
49
49
|
"vitest": "3.2.4",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
50
|
+
"@internal/tsconfig": "2.1.0",
|
|
51
|
+
"loglayer": "6.9.1"
|
|
52
52
|
},
|
|
53
53
|
"bugs": "https://github.com/loglayer/loglayer/issues",
|
|
54
54
|
"engines": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
],
|
|
60
60
|
"homepage": "https://loglayer.dev",
|
|
61
61
|
"scripts": {
|
|
62
|
-
"build": "
|
|
62
|
+
"build": "tsdown src/index.ts",
|
|
63
63
|
"test": "vitest --run",
|
|
64
64
|
"livetest": "tsx src/__tests__/livetest.ts",
|
|
65
65
|
"clean": "rm -rf .turbo node_modules dist",
|