@pagopa/azure-tracing 0.4.3 → 0.4.4-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/azure-tracing",
3
- "version": "0.4.3",
3
+ "version": "0.4.4-beta.0",
4
4
  "type": "module",
5
5
  "description": "A package that contains some utilities to enable Azure tracing on Node.js applications.",
6
6
  "repository": {
@@ -36,12 +36,12 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@azure/functions": "^4.7.2",
39
- "@azure/monitor-opentelemetry": "^1.11.0",
40
- "@azure/monitor-opentelemetry-exporter": "^1.0.0-beta.31",
39
+ "@azure/monitor-opentelemetry": "^1.11.1",
40
+ "@azure/monitor-opentelemetry-exporter": "^1.0.0-beta.32",
41
41
  "@opentelemetry/api": "^1.9.0",
42
- "@opentelemetry/api-logs": "^0.201.1",
43
- "@opentelemetry/instrumentation": "^0.201.1",
44
- "@opentelemetry/instrumentation-undici": "^0.12.0",
42
+ "@opentelemetry/api-logs": "^0.202.0",
43
+ "@opentelemetry/instrumentation": "^0.202.0",
44
+ "@opentelemetry/instrumentation-undici": "^0.13.0",
45
45
  "@t3-oss/env-core": "^0.13.4",
46
46
  "import-in-the-middle": "^1.13.2",
47
47
  "zod": "^3.25.28"
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/azure/functions/hooks.ts
21
- var hooks_exports = {};
22
- __export(hooks_exports, {
23
- registerAzureFunctionHooks: () => registerAzureFunctionHooks
24
- });
25
- module.exports = __toCommonJS(hooks_exports);
26
- var import_api = require("@opentelemetry/api");
27
- var registerAzureFunctionHooks = ({ hook }) => {
28
- hook.preInvocation((context) => {
29
- const traceContext = context.invocationContext.traceContext;
30
- if (traceContext) {
31
- context.functionHandler = import_api.context.bind(
32
- import_api.propagation.extract(import_api.context.active(), {
33
- traceparent: traceContext.traceParent,
34
- tracestate: traceContext.traceState
35
- }),
36
- context.functionHandler
37
- );
38
- }
39
- });
40
- };
41
- // Annotate the CommonJS export names for ESM import in node:
42
- 0 && (module.exports = {
43
- registerAzureFunctionHooks
44
- });
45
- //# sourceMappingURL=hooks.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/azure/functions/hooks.ts"],"sourcesContent":["import { app } from \"@azure/functions\";\nimport { context as otelContext, propagation } from \"@opentelemetry/api\";\n\n/**\n * Registers Azure Function hooks to enable OpenTelemetry tracing.\n * These hooks extract trace context from the Azure Function context\n * and bind it to the function handler, ensuring that traces are\n * properly propagated across function invocations.\n *\n * Once the issues that causes this workaround are resolved, it will be possible\n * to add the [azure-functions-nodejs-opentelemetry](https://github.com/Azure/azure-functions-nodejs-opentelemetry/tree/main)\n * to the instrumentation package and remove this workaround.\n *\n * @example\n * In your application, where you add the Azure Functions hooks (like `app.http() and so on), you\n * can add the following code:\n *\n * registerAzureFunctionHooks(app);\n *\n */\nexport const registerAzureFunctionHooks = ({ hook }: typeof app) => {\n hook.preInvocation((context) => {\n const traceContext = context.invocationContext.traceContext;\n if (traceContext) {\n context.functionHandler = otelContext.bind(\n propagation.extract(otelContext.active(), {\n traceparent: traceContext.traceParent,\n tracestate: traceContext.traceState,\n }),\n context.functionHandler,\n );\n }\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAoD;AAmB7C,IAAM,6BAA6B,CAAC,EAAE,KAAK,MAAkB;AAClE,OAAK,cAAc,CAAC,YAAY;AAC9B,UAAM,eAAe,QAAQ,kBAAkB;AAC/C,QAAI,cAAc;AAChB,cAAQ,kBAAkB,WAAAA,QAAY;AAAA,QACpC,uBAAY,QAAQ,WAAAA,QAAY,OAAO,GAAG;AAAA,UACxC,aAAa,aAAa;AAAA,UAC1B,YAAY,aAAa;AAAA,QAC3B,CAAC;AAAA,QACD,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["otelContext"]}
@@ -1,22 +0,0 @@
1
- import { app } from '@azure/functions';
2
-
3
- /**
4
- * Registers Azure Function hooks to enable OpenTelemetry tracing.
5
- * These hooks extract trace context from the Azure Function context
6
- * and bind it to the function handler, ensuring that traces are
7
- * properly propagated across function invocations.
8
- *
9
- * Once the issues that causes this workaround are resolved, it will be possible
10
- * to add the [azure-functions-nodejs-opentelemetry](https://github.com/Azure/azure-functions-nodejs-opentelemetry/tree/main)
11
- * to the instrumentation package and remove this workaround.
12
- *
13
- * @example
14
- * In your application, where you add the Azure Functions hooks (like `app.http() and so on), you
15
- * can add the following code:
16
- *
17
- * registerAzureFunctionHooks(app);
18
- *
19
- */
20
- declare const registerAzureFunctionHooks: ({ hook }: typeof app) => void;
21
-
22
- export { registerAzureFunctionHooks };
@@ -1,22 +0,0 @@
1
- import { app } from '@azure/functions';
2
-
3
- /**
4
- * Registers Azure Function hooks to enable OpenTelemetry tracing.
5
- * These hooks extract trace context from the Azure Function context
6
- * and bind it to the function handler, ensuring that traces are
7
- * properly propagated across function invocations.
8
- *
9
- * Once the issues that causes this workaround are resolved, it will be possible
10
- * to add the [azure-functions-nodejs-opentelemetry](https://github.com/Azure/azure-functions-nodejs-opentelemetry/tree/main)
11
- * to the instrumentation package and remove this workaround.
12
- *
13
- * @example
14
- * In your application, where you add the Azure Functions hooks (like `app.http() and so on), you
15
- * can add the following code:
16
- *
17
- * registerAzureFunctionHooks(app);
18
- *
19
- */
20
- declare const registerAzureFunctionHooks: ({ hook }: typeof app) => void;
21
-
22
- export { registerAzureFunctionHooks };
@@ -1,20 +0,0 @@
1
- // src/azure/functions/hooks.ts
2
- import { context as otelContext, propagation } from "@opentelemetry/api";
3
- var registerAzureFunctionHooks = ({ hook }) => {
4
- hook.preInvocation((context) => {
5
- const traceContext = context.invocationContext.traceContext;
6
- if (traceContext) {
7
- context.functionHandler = otelContext.bind(
8
- propagation.extract(otelContext.active(), {
9
- traceparent: traceContext.traceParent,
10
- tracestate: traceContext.traceState
11
- }),
12
- context.functionHandler
13
- );
14
- }
15
- });
16
- };
17
- export {
18
- registerAzureFunctionHooks
19
- };
20
- //# sourceMappingURL=hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/azure/functions/hooks.ts"],"sourcesContent":["import { app } from \"@azure/functions\";\nimport { context as otelContext, propagation } from \"@opentelemetry/api\";\n\n/**\n * Registers Azure Function hooks to enable OpenTelemetry tracing.\n * These hooks extract trace context from the Azure Function context\n * and bind it to the function handler, ensuring that traces are\n * properly propagated across function invocations.\n *\n * Once the issues that causes this workaround are resolved, it will be possible\n * to add the [azure-functions-nodejs-opentelemetry](https://github.com/Azure/azure-functions-nodejs-opentelemetry/tree/main)\n * to the instrumentation package and remove this workaround.\n *\n * @example\n * In your application, where you add the Azure Functions hooks (like `app.http() and so on), you\n * can add the following code:\n *\n * registerAzureFunctionHooks(app);\n *\n */\nexport const registerAzureFunctionHooks = ({ hook }: typeof app) => {\n hook.preInvocation((context) => {\n const traceContext = context.invocationContext.traceContext;\n if (traceContext) {\n context.functionHandler = otelContext.bind(\n propagation.extract(otelContext.active(), {\n traceparent: traceContext.traceParent,\n tracestate: traceContext.traceState,\n }),\n context.functionHandler,\n );\n }\n });\n};\n"],"mappings":";AACA,SAAS,WAAW,aAAa,mBAAmB;AAmB7C,IAAM,6BAA6B,CAAC,EAAE,KAAK,MAAkB;AAClE,OAAK,cAAc,CAAC,YAAY;AAC9B,UAAM,eAAe,QAAQ,kBAAkB;AAC/C,QAAI,cAAc;AAChB,cAAQ,kBAAkB,YAAY;AAAA,QACpC,YAAY,QAAQ,YAAY,OAAO,GAAG;AAAA,UACxC,aAAa,aAAa;AAAA,UAC1B,YAAY,aAAa;AAAA,QAC3B,CAAC;AAAA,QACD,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- // src/azure/functions/index.mts
4
- var import_import_in_the_middle = require("import-in-the-middle");
5
- var import_module = require("module");
6
- var import_api = require("@opentelemetry/api");
7
- var import_instrumentation = require("@opentelemetry/instrumentation");
8
-
9
- // src/azure/monitor/start-from-env.ts
10
- var import_monitor_opentelemetry = require("@azure/monitor-opentelemetry");
11
-
12
- // src/azure/monitor/env.ts
13
- var import_env_core = require("@t3-oss/env-core");
14
- var import_zod = require("zod");
15
- var loadEnv = () => (0, import_env_core.createEnv)({
16
- emptyStringAsUndefined: true,
17
- onValidationError: (errors) => {
18
- throw new Error(
19
- errors.map(
20
- (error) => `Environment variable ${error.path} - ${error.message}`
21
- ).join(", ")
22
- );
23
- },
24
- runtimeEnv: process.env,
25
- server: {
26
- APPINSIGHTS_SAMPLING_PERCENTAGE: import_zod.z.optional(
27
- import_zod.z.coerce.number().min(0).max(100).default(5).describe(
28
- "Application Insights sampling percentage between 0 and 100. If not set, defaults to 5."
29
- )
30
- ).transform((value) => {
31
- const percentage = Number(value);
32
- return isNaN(percentage) ? 5 : percentage;
33
- }).transform((value) => value / 100),
34
- APPLICATIONINSIGHTS_CONNECTION_STRING: import_zod.z.string().describe("The connection string for Application Insights.")
35
- }
36
- });
37
-
38
- // src/azure/monitor/start-from-env.ts
39
- var initFromEnv = () => {
40
- const env = loadEnv();
41
- return (0, import_monitor_opentelemetry.useAzureMonitor)({
42
- azureMonitorExporterOptions: {
43
- connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING
44
- },
45
- enableLiveMetrics: true,
46
- samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE
47
- });
48
- };
49
-
50
- // src/azure/opentelemetry/azure-undici-instrumentation.ts
51
- var import_instrumentation_undici = require("@opentelemetry/instrumentation-undici");
52
- var registerUndiciInstrumentation = () => new import_instrumentation_undici.UndiciInstrumentation({
53
- requestHook: (span, requestInfo) => {
54
- const { method, origin, path } = requestInfo;
55
- span.setAttributes({
56
- "http.host": origin,
57
- "http.method": method,
58
- "http.target": path,
59
- "http.url": `${origin}${path}`
60
- });
61
- },
62
- responseHook: (span, { response }) => {
63
- span.setAttribute("http.status_code", response.statusCode);
64
- }
65
- });
66
-
67
- // src/azure/functions/index.mts
68
- var import_meta = {};
69
- var { registerOptions, waitForAllMessagesAcknowledged } = (0, import_import_in_the_middle.createAddHookMessageChannel)();
70
- (0, import_module.register)("import-in-the-middle/hook.mjs", import_meta.url, registerOptions);
71
- initFromEnv();
72
- (0, import_instrumentation.registerInstrumentations)({
73
- instrumentations: [registerUndiciInstrumentation()],
74
- meterProvider: import_api.metrics.getMeterProvider(),
75
- tracerProvider: import_api.trace.getTracerProvider()
76
- });
77
- (async () => {
78
- await waitForAllMessagesAcknowledged();
79
- })();
80
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/azure/functions/index.mts","../../src/azure/monitor/start-from-env.ts","../../src/azure/monitor/env.ts","../../src/azure/opentelemetry/azure-undici-instrumentation.ts"],"sourcesContent":["/*\nThis file is required to instrument ESM application to use OpenTelemetry.\nThis file must be pre-loaded through the `NODE_OPTIONS` environment variable to\nhave a fully instrumented application.\n */\n\nimport { createAddHookMessageChannel } from \"import-in-the-middle\";\nimport { register } from \"module\";\n\nconst { registerOptions, waitForAllMessagesAcknowledged } =\n createAddHookMessageChannel();\n\nregister(\"import-in-the-middle/hook.mjs\", import.meta.url, registerOptions);\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { registerInstrumentations } from \"@opentelemetry/instrumentation\";\n\nimport { initFromEnv } from \"../monitor/start-from-env\";\nimport { registerUndiciInstrumentation } from \"../opentelemetry/azure-undici-instrumentation\";\n\ninitFromEnv();\n\nregisterInstrumentations({\n instrumentations: [registerUndiciInstrumentation()],\n meterProvider: metrics.getMeterProvider(),\n tracerProvider: trace.getTracerProvider(),\n});\n\n(async () => {\n await waitForAllMessagesAcknowledged();\n})();\n","import { useAzureMonitor } from \"@azure/monitor-opentelemetry\";\n\nimport { loadEnv } from \"./env\";\n\nexport const initFromEnv = () => {\n const env = loadEnv();\n\n return useAzureMonitor({\n azureMonitorExporterOptions: {\n connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING,\n },\n enableLiveMetrics: true,\n samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE,\n });\n};\n","// Load and type check environment variables on runtime\nimport { createEnv } from \"@t3-oss/env-core\";\nimport { z } from \"zod\";\n\nexport const loadEnv = () =>\n createEnv({\n emptyStringAsUndefined: true,\n onValidationError: (errors) => {\n throw new Error(\n errors\n .map(\n (error) => `Environment variable ${error.path} - ${error.message}`,\n )\n .join(\", \"),\n );\n },\n runtimeEnv: process.env,\n server: {\n APPINSIGHTS_SAMPLING_PERCENTAGE: z\n .optional(\n z.coerce\n .number()\n .min(0)\n .max(100)\n .default(5)\n .describe(\n \"Application Insights sampling percentage between 0 and 100. If not set, defaults to 5.\",\n ),\n )\n .transform((value) => {\n const percentage = Number(value);\n return isNaN(percentage) ? 5 : percentage;\n })\n .transform((value) => value / 100),\n APPLICATIONINSIGHTS_CONNECTION_STRING: z\n .string()\n .describe(\"The connection string for Application Insights.\"),\n },\n });\n","import { UndiciInstrumentation } from \"@opentelemetry/instrumentation-undici\";\n\n// instrument native node fetch\nexport const registerUndiciInstrumentation = () =>\n new UndiciInstrumentation({\n requestHook: (span, requestInfo) => {\n const { method, origin, path } = requestInfo;\n // Default instrumented attributes don't feed well into AppInsights,\n // so we set them manually.\n span.setAttributes({\n \"http.host\": origin,\n \"http.method\": method,\n \"http.target\": path,\n \"http.url\": `${origin}${path}`,\n });\n },\n responseHook: (span, { response }) => {\n // Same as above, set the status code manually.\n span.setAttribute(\"http.status_code\", response.statusCode);\n },\n });\n"],"mappings":";;;AAMA,kCAA4C;AAC5C,oBAAyB;AAOzB,iBAA+B;AAC/B,6BAAyC;;;ACfzC,mCAAgC;;;ACChC,sBAA0B;AAC1B,iBAAkB;AAEX,IAAM,UAAU,UACrB,2BAAU;AAAA,EACR,wBAAwB;AAAA,EACxB,mBAAmB,CAAC,WAAW;AAC7B,UAAM,IAAI;AAAA,MACR,OACG;AAAA,QACC,CAAC,UAAU,wBAAwB,MAAM,IAAI,MAAM,MAAM,OAAO;AAAA,MAClE,EACC,KAAK,IAAI;AAAA,IACd;AAAA,EACF;AAAA,EACA,YAAY,QAAQ;AAAA,EACpB,QAAQ;AAAA,IACN,iCAAiC,aAC9B;AAAA,MACC,aAAE,OACC,OAAO,EACP,IAAI,CAAC,EACL,IAAI,GAAG,EACP,QAAQ,CAAC,EACT;AAAA,QACC;AAAA,MACF;AAAA,IACJ,EACC,UAAU,CAAC,UAAU;AACpB,YAAM,aAAa,OAAO,KAAK;AAC/B,aAAO,MAAM,UAAU,IAAI,IAAI;AAAA,IACjC,CAAC,EACA,UAAU,CAAC,UAAU,QAAQ,GAAG;AAAA,IACnC,uCAAuC,aACpC,OAAO,EACP,SAAS,iDAAiD;AAAA,EAC/D;AACF,CAAC;;;ADlCI,IAAM,cAAc,MAAM;AAC/B,QAAM,MAAM,QAAQ;AAEpB,aAAO,8CAAgB;AAAA,IACrB,6BAA6B;AAAA,MAC3B,kBAAkB,IAAI;AAAA,IACxB;AAAA,IACA,mBAAmB;AAAA,IACnB,eAAe,IAAI;AAAA,EACrB,CAAC;AACH;;;AEdA,oCAAsC;AAG/B,IAAM,gCAAgC,MAC3C,IAAI,oDAAsB;AAAA,EACxB,aAAa,CAAC,MAAM,gBAAgB;AAClC,UAAM,EAAE,QAAQ,QAAQ,KAAK,IAAI;AAGjC,SAAK,cAAc;AAAA,MACjB,aAAa;AAAA,MACb,eAAe;AAAA,MACf,eAAe;AAAA,MACf,YAAY,GAAG,MAAM,GAAG,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAAA,EACA,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM;AAEpC,SAAK,aAAa,oBAAoB,SAAS,UAAU;AAAA,EAC3D;AACF,CAAC;;;AHpBH;AASA,IAAM,EAAE,iBAAiB,+BAA+B,QACtD,yDAA4B;AAAA,IAE9B,wBAAS,iCAAiC,YAAY,KAAK,eAAe;AAQ1E,YAAY;AAAA,IAEZ,iDAAyB;AAAA,EACvB,kBAAkB,CAAC,8BAA8B,CAAC;AAAA,EAClD,eAAe,mBAAQ,iBAAiB;AAAA,EACxC,gBAAgB,iBAAM,kBAAkB;AAC1C,CAAC;AAAA,CAEA,YAAY;AACX,QAAM,+BAA+B;AACvC,GAAG;","names":[]}
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,77 +0,0 @@
1
- // src/azure/functions/index.mts
2
- import { createAddHookMessageChannel } from "import-in-the-middle";
3
- import { register } from "module";
4
- import { metrics, trace } from "@opentelemetry/api";
5
- import { registerInstrumentations } from "@opentelemetry/instrumentation";
6
-
7
- // src/azure/monitor/start-from-env.ts
8
- import { useAzureMonitor } from "@azure/monitor-opentelemetry";
9
-
10
- // src/azure/monitor/env.ts
11
- import { createEnv } from "@t3-oss/env-core";
12
- import { z } from "zod";
13
- var loadEnv = () => createEnv({
14
- emptyStringAsUndefined: true,
15
- onValidationError: (errors) => {
16
- throw new Error(
17
- errors.map(
18
- (error) => `Environment variable ${error.path} - ${error.message}`
19
- ).join(", ")
20
- );
21
- },
22
- runtimeEnv: process.env,
23
- server: {
24
- APPINSIGHTS_SAMPLING_PERCENTAGE: z.optional(
25
- z.coerce.number().min(0).max(100).default(5).describe(
26
- "Application Insights sampling percentage between 0 and 100. If not set, defaults to 5."
27
- )
28
- ).transform((value) => {
29
- const percentage = Number(value);
30
- return isNaN(percentage) ? 5 : percentage;
31
- }).transform((value) => value / 100),
32
- APPLICATIONINSIGHTS_CONNECTION_STRING: z.string().describe("The connection string for Application Insights.")
33
- }
34
- });
35
-
36
- // src/azure/monitor/start-from-env.ts
37
- var initFromEnv = () => {
38
- const env = loadEnv();
39
- return useAzureMonitor({
40
- azureMonitorExporterOptions: {
41
- connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING
42
- },
43
- enableLiveMetrics: true,
44
- samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE
45
- });
46
- };
47
-
48
- // src/azure/opentelemetry/azure-undici-instrumentation.ts
49
- import { UndiciInstrumentation } from "@opentelemetry/instrumentation-undici";
50
- var registerUndiciInstrumentation = () => new UndiciInstrumentation({
51
- requestHook: (span, requestInfo) => {
52
- const { method, origin, path } = requestInfo;
53
- span.setAttributes({
54
- "http.host": origin,
55
- "http.method": method,
56
- "http.target": path,
57
- "http.url": `${origin}${path}`
58
- });
59
- },
60
- responseHook: (span, { response }) => {
61
- span.setAttribute("http.status_code", response.statusCode);
62
- }
63
- });
64
-
65
- // src/azure/functions/index.mts
66
- var { registerOptions, waitForAllMessagesAcknowledged } = createAddHookMessageChannel();
67
- register("import-in-the-middle/hook.mjs", import.meta.url, registerOptions);
68
- initFromEnv();
69
- registerInstrumentations({
70
- instrumentations: [registerUndiciInstrumentation()],
71
- meterProvider: metrics.getMeterProvider(),
72
- tracerProvider: trace.getTracerProvider()
73
- });
74
- (async () => {
75
- await waitForAllMessagesAcknowledged();
76
- })();
77
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/azure/functions/index.mts","../../src/azure/monitor/start-from-env.ts","../../src/azure/monitor/env.ts","../../src/azure/opentelemetry/azure-undici-instrumentation.ts"],"sourcesContent":["/*\nThis file is required to instrument ESM application to use OpenTelemetry.\nThis file must be pre-loaded through the `NODE_OPTIONS` environment variable to\nhave a fully instrumented application.\n */\n\nimport { createAddHookMessageChannel } from \"import-in-the-middle\";\nimport { register } from \"module\";\n\nconst { registerOptions, waitForAllMessagesAcknowledged } =\n createAddHookMessageChannel();\n\nregister(\"import-in-the-middle/hook.mjs\", import.meta.url, registerOptions);\n\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport { registerInstrumentations } from \"@opentelemetry/instrumentation\";\n\nimport { initFromEnv } from \"../monitor/start-from-env\";\nimport { registerUndiciInstrumentation } from \"../opentelemetry/azure-undici-instrumentation\";\n\ninitFromEnv();\n\nregisterInstrumentations({\n instrumentations: [registerUndiciInstrumentation()],\n meterProvider: metrics.getMeterProvider(),\n tracerProvider: trace.getTracerProvider(),\n});\n\n(async () => {\n await waitForAllMessagesAcknowledged();\n})();\n","import { useAzureMonitor } from \"@azure/monitor-opentelemetry\";\n\nimport { loadEnv } from \"./env\";\n\nexport const initFromEnv = () => {\n const env = loadEnv();\n\n return useAzureMonitor({\n azureMonitorExporterOptions: {\n connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING,\n },\n enableLiveMetrics: true,\n samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE,\n });\n};\n","// Load and type check environment variables on runtime\nimport { createEnv } from \"@t3-oss/env-core\";\nimport { z } from \"zod\";\n\nexport const loadEnv = () =>\n createEnv({\n emptyStringAsUndefined: true,\n onValidationError: (errors) => {\n throw new Error(\n errors\n .map(\n (error) => `Environment variable ${error.path} - ${error.message}`,\n )\n .join(\", \"),\n );\n },\n runtimeEnv: process.env,\n server: {\n APPINSIGHTS_SAMPLING_PERCENTAGE: z\n .optional(\n z.coerce\n .number()\n .min(0)\n .max(100)\n .default(5)\n .describe(\n \"Application Insights sampling percentage between 0 and 100. If not set, defaults to 5.\",\n ),\n )\n .transform((value) => {\n const percentage = Number(value);\n return isNaN(percentage) ? 5 : percentage;\n })\n .transform((value) => value / 100),\n APPLICATIONINSIGHTS_CONNECTION_STRING: z\n .string()\n .describe(\"The connection string for Application Insights.\"),\n },\n });\n","import { UndiciInstrumentation } from \"@opentelemetry/instrumentation-undici\";\n\n// instrument native node fetch\nexport const registerUndiciInstrumentation = () =>\n new UndiciInstrumentation({\n requestHook: (span, requestInfo) => {\n const { method, origin, path } = requestInfo;\n // Default instrumented attributes don't feed well into AppInsights,\n // so we set them manually.\n span.setAttributes({\n \"http.host\": origin,\n \"http.method\": method,\n \"http.target\": path,\n \"http.url\": `${origin}${path}`,\n });\n },\n responseHook: (span, { response }) => {\n // Same as above, set the status code manually.\n span.setAttribute(\"http.status_code\", response.statusCode);\n },\n });\n"],"mappings":";AAMA,SAAS,mCAAmC;AAC5C,SAAS,gBAAgB;AAOzB,SAAS,SAAS,aAAa;AAC/B,SAAS,gCAAgC;;;ACfzC,SAAS,uBAAuB;;;ACChC,SAAS,iBAAiB;AAC1B,SAAS,SAAS;AAEX,IAAM,UAAU,MACrB,UAAU;AAAA,EACR,wBAAwB;AAAA,EACxB,mBAAmB,CAAC,WAAW;AAC7B,UAAM,IAAI;AAAA,MACR,OACG;AAAA,QACC,CAAC,UAAU,wBAAwB,MAAM,IAAI,MAAM,MAAM,OAAO;AAAA,MAClE,EACC,KAAK,IAAI;AAAA,IACd;AAAA,EACF;AAAA,EACA,YAAY,QAAQ;AAAA,EACpB,QAAQ;AAAA,IACN,iCAAiC,EAC9B;AAAA,MACC,EAAE,OACC,OAAO,EACP,IAAI,CAAC,EACL,IAAI,GAAG,EACP,QAAQ,CAAC,EACT;AAAA,QACC;AAAA,MACF;AAAA,IACJ,EACC,UAAU,CAAC,UAAU;AACpB,YAAM,aAAa,OAAO,KAAK;AAC/B,aAAO,MAAM,UAAU,IAAI,IAAI;AAAA,IACjC,CAAC,EACA,UAAU,CAAC,UAAU,QAAQ,GAAG;AAAA,IACnC,uCAAuC,EACpC,OAAO,EACP,SAAS,iDAAiD;AAAA,EAC/D;AACF,CAAC;;;ADlCI,IAAM,cAAc,MAAM;AAC/B,QAAM,MAAM,QAAQ;AAEpB,SAAO,gBAAgB;AAAA,IACrB,6BAA6B;AAAA,MAC3B,kBAAkB,IAAI;AAAA,IACxB;AAAA,IACA,mBAAmB;AAAA,IACnB,eAAe,IAAI;AAAA,EACrB,CAAC;AACH;;;AEdA,SAAS,6BAA6B;AAG/B,IAAM,gCAAgC,MAC3C,IAAI,sBAAsB;AAAA,EACxB,aAAa,CAAC,MAAM,gBAAgB;AAClC,UAAM,EAAE,QAAQ,QAAQ,KAAK,IAAI;AAGjC,SAAK,cAAc;AAAA,MACjB,aAAa;AAAA,MACb,eAAe;AAAA,MACf,eAAe;AAAA,MACf,YAAY,GAAG,MAAM,GAAG,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAAA,EACA,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM;AAEpC,SAAK,aAAa,oBAAoB,SAAS,UAAU;AAAA,EAC3D;AACF,CAAC;;;AHXH,IAAM,EAAE,iBAAiB,+BAA+B,IACtD,4BAA4B;AAE9B,SAAS,iCAAiC,YAAY,KAAK,eAAe;AAQ1E,YAAY;AAEZ,yBAAyB;AAAA,EACvB,kBAAkB,CAAC,8BAA8B,CAAC;AAAA,EAClD,eAAe,QAAQ,iBAAiB;AAAA,EACxC,gBAAgB,MAAM,kBAAkB;AAC1C,CAAC;AAAA,CAEA,YAAY;AACX,QAAM,+BAA+B;AACvC,GAAG;","names":[]}
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/azure/functions/v3/index.ts
21
- var v3_exports = {};
22
- __export(v3_exports, {
23
- withOtelContextFunctionV3: () => withOtelContextFunctionV3
24
- });
25
- module.exports = __toCommonJS(v3_exports);
26
- var import_api = require("@opentelemetry/api");
27
- var withOtelContextFunctionV3 = (context) => (v3Function) => {
28
- const traceContext = context.traceContext ?? {};
29
- const headers = {
30
- traceparent: traceContext.traceparent,
31
- tracestate: traceContext.tracestate
32
- };
33
- const ctx = import_api.propagation.extract(import_api.context.active(), headers);
34
- return import_api.context.with(ctx, () => v3Function(context));
35
- };
36
- // Annotate the CommonJS export names for ESM import in node:
37
- 0 && (module.exports = {
38
- withOtelContextFunctionV3
39
- });
40
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/azure/functions/v3/index.ts"],"sourcesContent":["import { context as otelContext, propagation } from \"@opentelemetry/api\";\n\n/**\n * Interface representing the necessary parts of the Azure Functions v3 Context\n * for OpenTelemetry trace context propagation.\n */\ninterface FunctionContextV3 {\n traceContext?: {\n traceparent?: null | string;\n tracestate?: null | string;\n };\n}\n\n/**\n * Wraps an Azure Function v3 handler to propagate OpenTelemetry context.\n *\n * This function extracts trace context from a v3-like context object (simulated via `FunctionContextV3` interface)\n * and runs the provided `v3Function` within that context, ensuring OpenTelemetry trace propagation.\n *\n * @param context The Azure Function v3 context object (or an object conforming to `FunctionContextV3`).\n * @param v3Function The original Azure Function v3 handler function.\n * @returns A new function that, when called with the v3 context, executes the original handler with OpenTelemetry context propagation.\n */\nexport const withOtelContextFunctionV3 =\n <T extends FunctionContextV3>(context: T) =>\n (v3Function: (context: T) => void) => {\n const traceContext = context.traceContext ?? {};\n const headers = {\n traceparent: traceContext.traceparent,\n tracestate: traceContext.tracestate,\n };\n\n const ctx = propagation.extract(otelContext.active(), headers);\n return otelContext.with(ctx, () => v3Function(context));\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAoD;AAuB7C,IAAM,4BACX,CAA8B,YAC9B,CAAC,eAAqC;AACpC,QAAM,eAAe,QAAQ,gBAAgB,CAAC;AAC9C,QAAM,UAAU;AAAA,IACd,aAAa,aAAa;AAAA,IAC1B,YAAY,aAAa;AAAA,EAC3B;AAEA,QAAM,MAAM,uBAAY,QAAQ,WAAAA,QAAY,OAAO,GAAG,OAAO;AAC7D,SAAO,WAAAA,QAAY,KAAK,KAAK,MAAM,WAAW,OAAO,CAAC;AACxD;","names":["otelContext"]}
@@ -1,23 +0,0 @@
1
- /**
2
- * Interface representing the necessary parts of the Azure Functions v3 Context
3
- * for OpenTelemetry trace context propagation.
4
- */
5
- interface FunctionContextV3 {
6
- traceContext?: {
7
- traceparent?: null | string;
8
- tracestate?: null | string;
9
- };
10
- }
11
- /**
12
- * Wraps an Azure Function v3 handler to propagate OpenTelemetry context.
13
- *
14
- * This function extracts trace context from a v3-like context object (simulated via `FunctionContextV3` interface)
15
- * and runs the provided `v3Function` within that context, ensuring OpenTelemetry trace propagation.
16
- *
17
- * @param context The Azure Function v3 context object (or an object conforming to `FunctionContextV3`).
18
- * @param v3Function The original Azure Function v3 handler function.
19
- * @returns A new function that, when called with the v3 context, executes the original handler with OpenTelemetry context propagation.
20
- */
21
- declare const withOtelContextFunctionV3: <T extends FunctionContextV3>(context: T) => (v3Function: (context: T) => void) => void;
22
-
23
- export { withOtelContextFunctionV3 };
@@ -1,23 +0,0 @@
1
- /**
2
- * Interface representing the necessary parts of the Azure Functions v3 Context
3
- * for OpenTelemetry trace context propagation.
4
- */
5
- interface FunctionContextV3 {
6
- traceContext?: {
7
- traceparent?: null | string;
8
- tracestate?: null | string;
9
- };
10
- }
11
- /**
12
- * Wraps an Azure Function v3 handler to propagate OpenTelemetry context.
13
- *
14
- * This function extracts trace context from a v3-like context object (simulated via `FunctionContextV3` interface)
15
- * and runs the provided `v3Function` within that context, ensuring OpenTelemetry trace propagation.
16
- *
17
- * @param context The Azure Function v3 context object (or an object conforming to `FunctionContextV3`).
18
- * @param v3Function The original Azure Function v3 handler function.
19
- * @returns A new function that, when called with the v3 context, executes the original handler with OpenTelemetry context propagation.
20
- */
21
- declare const withOtelContextFunctionV3: <T extends FunctionContextV3>(context: T) => (v3Function: (context: T) => void) => void;
22
-
23
- export { withOtelContextFunctionV3 };
@@ -1,15 +0,0 @@
1
- // src/azure/functions/v3/index.ts
2
- import { context as otelContext, propagation } from "@opentelemetry/api";
3
- var withOtelContextFunctionV3 = (context) => (v3Function) => {
4
- const traceContext = context.traceContext ?? {};
5
- const headers = {
6
- traceparent: traceContext.traceparent,
7
- tracestate: traceContext.tracestate
8
- };
9
- const ctx = propagation.extract(otelContext.active(), headers);
10
- return otelContext.with(ctx, () => v3Function(context));
11
- };
12
- export {
13
- withOtelContextFunctionV3
14
- };
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/azure/functions/v3/index.ts"],"sourcesContent":["import { context as otelContext, propagation } from \"@opentelemetry/api\";\n\n/**\n * Interface representing the necessary parts of the Azure Functions v3 Context\n * for OpenTelemetry trace context propagation.\n */\ninterface FunctionContextV3 {\n traceContext?: {\n traceparent?: null | string;\n tracestate?: null | string;\n };\n}\n\n/**\n * Wraps an Azure Function v3 handler to propagate OpenTelemetry context.\n *\n * This function extracts trace context from a v3-like context object (simulated via `FunctionContextV3` interface)\n * and runs the provided `v3Function` within that context, ensuring OpenTelemetry trace propagation.\n *\n * @param context The Azure Function v3 context object (or an object conforming to `FunctionContextV3`).\n * @param v3Function The original Azure Function v3 handler function.\n * @returns A new function that, when called with the v3 context, executes the original handler with OpenTelemetry context propagation.\n */\nexport const withOtelContextFunctionV3 =\n <T extends FunctionContextV3>(context: T) =>\n (v3Function: (context: T) => void) => {\n const traceContext = context.traceContext ?? {};\n const headers = {\n traceparent: traceContext.traceparent,\n tracestate: traceContext.tracestate,\n };\n\n const ctx = propagation.extract(otelContext.active(), headers);\n return otelContext.with(ctx, () => v3Function(context));\n };\n"],"mappings":";AAAA,SAAS,WAAW,aAAa,mBAAmB;AAuB7C,IAAM,4BACX,CAA8B,YAC9B,CAAC,eAAqC;AACpC,QAAM,eAAe,QAAQ,gBAAgB,CAAC;AAC9C,QAAM,UAAU;AAAA,IACd,aAAa,aAAa;AAAA,IAC1B,YAAY,aAAa;AAAA,EAC3B;AAEA,QAAM,MAAM,YAAY,QAAQ,YAAY,OAAO,GAAG,OAAO;AAC7D,SAAO,YAAY,KAAK,KAAK,MAAM,WAAW,OAAO,CAAC;AACxD;","names":[]}
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/azure/monitor/index.ts
21
- var monitor_exports = {};
22
- __export(monitor_exports, {
23
- initAzureMonitor: () => initAzureMonitor
24
- });
25
- module.exports = __toCommonJS(monitor_exports);
26
- var import_monitor_opentelemetry2 = require("@azure/monitor-opentelemetry");
27
- var import_api = require("@opentelemetry/api");
28
- var import_instrumentation = require("@opentelemetry/instrumentation");
29
-
30
- // src/azure/opentelemetry/azure-undici-instrumentation.ts
31
- var import_instrumentation_undici = require("@opentelemetry/instrumentation-undici");
32
- var registerUndiciInstrumentation = () => new import_instrumentation_undici.UndiciInstrumentation({
33
- requestHook: (span, requestInfo) => {
34
- const { method, origin, path } = requestInfo;
35
- span.setAttributes({
36
- "http.host": origin,
37
- "http.method": method,
38
- "http.target": path,
39
- "http.url": `${origin}${path}`
40
- });
41
- },
42
- responseHook: (span, { response }) => {
43
- span.setAttribute("http.status_code", response.statusCode);
44
- }
45
- });
46
-
47
- // src/azure/monitor/start-from-env.ts
48
- var import_monitor_opentelemetry = require("@azure/monitor-opentelemetry");
49
-
50
- // src/azure/monitor/env.ts
51
- var import_env_core = require("@t3-oss/env-core");
52
- var import_zod = require("zod");
53
- var loadEnv = () => (0, import_env_core.createEnv)({
54
- emptyStringAsUndefined: true,
55
- onValidationError: (errors) => {
56
- throw new Error(
57
- errors.map(
58
- (error) => `Environment variable ${error.path} - ${error.message}`
59
- ).join(", ")
60
- );
61
- },
62
- runtimeEnv: process.env,
63
- server: {
64
- APPINSIGHTS_SAMPLING_PERCENTAGE: import_zod.z.optional(
65
- import_zod.z.coerce.number().min(0).max(100).default(5).describe(
66
- "Application Insights sampling percentage between 0 and 100. If not set, defaults to 5."
67
- )
68
- ).transform((value) => {
69
- const percentage = Number(value);
70
- return isNaN(percentage) ? 5 : percentage;
71
- }).transform((value) => value / 100),
72
- APPLICATIONINSIGHTS_CONNECTION_STRING: import_zod.z.string().describe("The connection string for Application Insights.")
73
- }
74
- });
75
-
76
- // src/azure/monitor/start-from-env.ts
77
- var initFromEnv = () => {
78
- const env = loadEnv();
79
- return (0, import_monitor_opentelemetry.useAzureMonitor)({
80
- azureMonitorExporterOptions: {
81
- connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING
82
- },
83
- enableLiveMetrics: true,
84
- samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE
85
- });
86
- };
87
-
88
- // src/azure/monitor/index.ts
89
- var initAzureMonitor = (instrumentations = [], azureMonitorOptions) => {
90
- if (azureMonitorOptions) {
91
- (0, import_monitor_opentelemetry2.useAzureMonitor)(azureMonitorOptions);
92
- } else {
93
- initFromEnv();
94
- }
95
- (0, import_instrumentation.registerInstrumentations)({
96
- instrumentations: [registerUndiciInstrumentation(), ...instrumentations],
97
- meterProvider: import_api.metrics.getMeterProvider(),
98
- tracerProvider: import_api.trace.getTracerProvider()
99
- });
100
- };
101
- // Annotate the CommonJS export names for ESM import in node:
102
- 0 && (module.exports = {
103
- initAzureMonitor
104
- });
105
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/azure/monitor/index.ts","../../src/azure/opentelemetry/azure-undici-instrumentation.ts","../../src/azure/monitor/start-from-env.ts","../../src/azure/monitor/env.ts"],"sourcesContent":["import {\n AzureMonitorOpenTelemetryOptions,\n useAzureMonitor,\n} from \"@azure/monitor-opentelemetry\";\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport {\n Instrumentation,\n registerInstrumentations,\n} from \"@opentelemetry/instrumentation\";\n\nimport { registerUndiciInstrumentation } from \"../opentelemetry/azure-undici-instrumentation\";\nimport { initFromEnv } from \"./start-from-env\";\n\n/**\n * Initialize the Azure Monitor with the given instrumentations and options.\n * This function sets up telemetry collection for your application by registering\n * the provided instrumentations and configuring Azure Monitor OpenTelemetry.\n *\n * By default, the Undici instrumentation is included. You can extend the functionality\n * by passing additional instrumentations as an array.\n *\n * @remarks\n * - This function should be called at the start of your application to ensure\n * telemetry is collected from the beginning.\n * - If `azureMonitorOptions` is not provided, the configuration will be initialized\n * using environment variables. @see README for more details.\n *\n * @example\n * // Basic usage with default settings\n * import { initAzureMonitor } from \"@pagopa/azure-tracing/azure-monitor\";\n * initAzureMonitor();\n *\n * @example\n * // Usage with custom instrumentations\n * import { initAzureMonitor } from \"@pagopa/azure-tracing/azure-monitor\";\n * import { MyCustomInstrumentation } from \"my-custom-instrumentation\";\n *\n * initAzureMonitor([new MyCustomInstrumentation()]);\n *\n * @example\n * // Usage with custom Azure Monitor options\n * import { initAzureMonitor } from \"@pagopa/azure-tracing/azure-monitor\";\n *\n * initAzureMonitor([], {\n * azureMonitorExporterOptions: {\n * connectionString: \"theConnectionString\",\n * },\n * // other options...\n * });\n *\n * @param instrumentations - The list of instrumentations to register with the Azure Monitor.\n * @param azureMonitorOptions - Custom configuration for Azure Monitor. If not provided,\n * it will be initialized using environment variables.\n */\nexport const initAzureMonitor = (\n instrumentations: readonly Instrumentation[] = [],\n azureMonitorOptions?: AzureMonitorOpenTelemetryOptions,\n) => {\n if (azureMonitorOptions) {\n useAzureMonitor(azureMonitorOptions);\n } else {\n initFromEnv();\n }\n\n registerInstrumentations({\n instrumentations: [registerUndiciInstrumentation(), ...instrumentations],\n meterProvider: metrics.getMeterProvider(),\n tracerProvider: trace.getTracerProvider(),\n });\n};\n","import { UndiciInstrumentation } from \"@opentelemetry/instrumentation-undici\";\n\n// instrument native node fetch\nexport const registerUndiciInstrumentation = () =>\n new UndiciInstrumentation({\n requestHook: (span, requestInfo) => {\n const { method, origin, path } = requestInfo;\n // Default instrumented attributes don't feed well into AppInsights,\n // so we set them manually.\n span.setAttributes({\n \"http.host\": origin,\n \"http.method\": method,\n \"http.target\": path,\n \"http.url\": `${origin}${path}`,\n });\n },\n responseHook: (span, { response }) => {\n // Same as above, set the status code manually.\n span.setAttribute(\"http.status_code\", response.statusCode);\n },\n });\n","import { useAzureMonitor } from \"@azure/monitor-opentelemetry\";\n\nimport { loadEnv } from \"./env\";\n\nexport const initFromEnv = () => {\n const env = loadEnv();\n\n return useAzureMonitor({\n azureMonitorExporterOptions: {\n connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING,\n },\n enableLiveMetrics: true,\n samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE,\n });\n};\n","// Load and type check environment variables on runtime\nimport { createEnv } from \"@t3-oss/env-core\";\nimport { z } from \"zod\";\n\nexport const loadEnv = () =>\n createEnv({\n emptyStringAsUndefined: true,\n onValidationError: (errors) => {\n throw new Error(\n errors\n .map(\n (error) => `Environment variable ${error.path} - ${error.message}`,\n )\n .join(\", \"),\n );\n },\n runtimeEnv: process.env,\n server: {\n APPINSIGHTS_SAMPLING_PERCENTAGE: z\n .optional(\n z.coerce\n .number()\n .min(0)\n .max(100)\n .default(5)\n .describe(\n \"Application Insights sampling percentage between 0 and 100. If not set, defaults to 5.\",\n ),\n )\n .transform((value) => {\n const percentage = Number(value);\n return isNaN(percentage) ? 5 : percentage;\n })\n .transform((value) => value / 100),\n APPLICATIONINSIGHTS_CONNECTION_STRING: z\n .string()\n .describe(\"The connection string for Application Insights.\"),\n },\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gCAGO;AACP,iBAA+B;AAC/B,6BAGO;;;ACRP,oCAAsC;AAG/B,IAAM,gCAAgC,MAC3C,IAAI,oDAAsB;AAAA,EACxB,aAAa,CAAC,MAAM,gBAAgB;AAClC,UAAM,EAAE,QAAQ,QAAQ,KAAK,IAAI;AAGjC,SAAK,cAAc;AAAA,MACjB,aAAa;AAAA,MACb,eAAe;AAAA,MACf,eAAe;AAAA,MACf,YAAY,GAAG,MAAM,GAAG,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAAA,EACA,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM;AAEpC,SAAK,aAAa,oBAAoB,SAAS,UAAU;AAAA,EAC3D;AACF,CAAC;;;ACpBH,mCAAgC;;;ACChC,sBAA0B;AAC1B,iBAAkB;AAEX,IAAM,UAAU,UACrB,2BAAU;AAAA,EACR,wBAAwB;AAAA,EACxB,mBAAmB,CAAC,WAAW;AAC7B,UAAM,IAAI;AAAA,MACR,OACG;AAAA,QACC,CAAC,UAAU,wBAAwB,MAAM,IAAI,MAAM,MAAM,OAAO;AAAA,MAClE,EACC,KAAK,IAAI;AAAA,IACd;AAAA,EACF;AAAA,EACA,YAAY,QAAQ;AAAA,EACpB,QAAQ;AAAA,IACN,iCAAiC,aAC9B;AAAA,MACC,aAAE,OACC,OAAO,EACP,IAAI,CAAC,EACL,IAAI,GAAG,EACP,QAAQ,CAAC,EACT;AAAA,QACC;AAAA,MACF;AAAA,IACJ,EACC,UAAU,CAAC,UAAU;AACpB,YAAM,aAAa,OAAO,KAAK;AAC/B,aAAO,MAAM,UAAU,IAAI,IAAI;AAAA,IACjC,CAAC,EACA,UAAU,CAAC,UAAU,QAAQ,GAAG;AAAA,IACnC,uCAAuC,aACpC,OAAO,EACP,SAAS,iDAAiD;AAAA,EAC/D;AACF,CAAC;;;ADlCI,IAAM,cAAc,MAAM;AAC/B,QAAM,MAAM,QAAQ;AAEpB,aAAO,8CAAgB;AAAA,IACrB,6BAA6B;AAAA,MAC3B,kBAAkB,IAAI;AAAA,IACxB;AAAA,IACA,mBAAmB;AAAA,IACnB,eAAe,IAAI;AAAA,EACrB,CAAC;AACH;;;AFwCO,IAAM,mBAAmB,CAC9B,mBAA+C,CAAC,GAChD,wBACG;AACH,MAAI,qBAAqB;AACvB,uDAAgB,mBAAmB;AAAA,EACrC,OAAO;AACL,gBAAY;AAAA,EACd;AAEA,uDAAyB;AAAA,IACvB,kBAAkB,CAAC,8BAA8B,GAAG,GAAG,gBAAgB;AAAA,IACvE,eAAe,mBAAQ,iBAAiB;AAAA,IACxC,gBAAgB,iBAAM,kBAAkB;AAAA,EAC1C,CAAC;AACH;","names":["import_monitor_opentelemetry"]}
@@ -1,47 +0,0 @@
1
- import { AzureMonitorOpenTelemetryOptions } from '@azure/monitor-opentelemetry';
2
- import { Instrumentation } from '@opentelemetry/instrumentation';
3
-
4
- /**
5
- * Initialize the Azure Monitor with the given instrumentations and options.
6
- * This function sets up telemetry collection for your application by registering
7
- * the provided instrumentations and configuring Azure Monitor OpenTelemetry.
8
- *
9
- * By default, the Undici instrumentation is included. You can extend the functionality
10
- * by passing additional instrumentations as an array.
11
- *
12
- * @remarks
13
- * - This function should be called at the start of your application to ensure
14
- * telemetry is collected from the beginning.
15
- * - If `azureMonitorOptions` is not provided, the configuration will be initialized
16
- * using environment variables. @see README for more details.
17
- *
18
- * @example
19
- * // Basic usage with default settings
20
- * import { initAzureMonitor } from "@pagopa/azure-tracing/azure-monitor";
21
- * initAzureMonitor();
22
- *
23
- * @example
24
- * // Usage with custom instrumentations
25
- * import { initAzureMonitor } from "@pagopa/azure-tracing/azure-monitor";
26
- * import { MyCustomInstrumentation } from "my-custom-instrumentation";
27
- *
28
- * initAzureMonitor([new MyCustomInstrumentation()]);
29
- *
30
- * @example
31
- * // Usage with custom Azure Monitor options
32
- * import { initAzureMonitor } from "@pagopa/azure-tracing/azure-monitor";
33
- *
34
- * initAzureMonitor([], {
35
- * azureMonitorExporterOptions: {
36
- * connectionString: "theConnectionString",
37
- * },
38
- * // other options...
39
- * });
40
- *
41
- * @param instrumentations - The list of instrumentations to register with the Azure Monitor.
42
- * @param azureMonitorOptions - Custom configuration for Azure Monitor. If not provided,
43
- * it will be initialized using environment variables.
44
- */
45
- declare const initAzureMonitor: (instrumentations?: readonly Instrumentation[], azureMonitorOptions?: AzureMonitorOpenTelemetryOptions) => void;
46
-
47
- export { initAzureMonitor };
@@ -1,47 +0,0 @@
1
- import { AzureMonitorOpenTelemetryOptions } from '@azure/monitor-opentelemetry';
2
- import { Instrumentation } from '@opentelemetry/instrumentation';
3
-
4
- /**
5
- * Initialize the Azure Monitor with the given instrumentations and options.
6
- * This function sets up telemetry collection for your application by registering
7
- * the provided instrumentations and configuring Azure Monitor OpenTelemetry.
8
- *
9
- * By default, the Undici instrumentation is included. You can extend the functionality
10
- * by passing additional instrumentations as an array.
11
- *
12
- * @remarks
13
- * - This function should be called at the start of your application to ensure
14
- * telemetry is collected from the beginning.
15
- * - If `azureMonitorOptions` is not provided, the configuration will be initialized
16
- * using environment variables. @see README for more details.
17
- *
18
- * @example
19
- * // Basic usage with default settings
20
- * import { initAzureMonitor } from "@pagopa/azure-tracing/azure-monitor";
21
- * initAzureMonitor();
22
- *
23
- * @example
24
- * // Usage with custom instrumentations
25
- * import { initAzureMonitor } from "@pagopa/azure-tracing/azure-monitor";
26
- * import { MyCustomInstrumentation } from "my-custom-instrumentation";
27
- *
28
- * initAzureMonitor([new MyCustomInstrumentation()]);
29
- *
30
- * @example
31
- * // Usage with custom Azure Monitor options
32
- * import { initAzureMonitor } from "@pagopa/azure-tracing/azure-monitor";
33
- *
34
- * initAzureMonitor([], {
35
- * azureMonitorExporterOptions: {
36
- * connectionString: "theConnectionString",
37
- * },
38
- * // other options...
39
- * });
40
- *
41
- * @param instrumentations - The list of instrumentations to register with the Azure Monitor.
42
- * @param azureMonitorOptions - Custom configuration for Azure Monitor. If not provided,
43
- * it will be initialized using environment variables.
44
- */
45
- declare const initAzureMonitor: (instrumentations?: readonly Instrumentation[], azureMonitorOptions?: AzureMonitorOpenTelemetryOptions) => void;
46
-
47
- export { initAzureMonitor };
@@ -1,84 +0,0 @@
1
- // src/azure/monitor/index.ts
2
- import {
3
- useAzureMonitor as useAzureMonitor2
4
- } from "@azure/monitor-opentelemetry";
5
- import { metrics, trace } from "@opentelemetry/api";
6
- import {
7
- registerInstrumentations
8
- } from "@opentelemetry/instrumentation";
9
-
10
- // src/azure/opentelemetry/azure-undici-instrumentation.ts
11
- import { UndiciInstrumentation } from "@opentelemetry/instrumentation-undici";
12
- var registerUndiciInstrumentation = () => new UndiciInstrumentation({
13
- requestHook: (span, requestInfo) => {
14
- const { method, origin, path } = requestInfo;
15
- span.setAttributes({
16
- "http.host": origin,
17
- "http.method": method,
18
- "http.target": path,
19
- "http.url": `${origin}${path}`
20
- });
21
- },
22
- responseHook: (span, { response }) => {
23
- span.setAttribute("http.status_code", response.statusCode);
24
- }
25
- });
26
-
27
- // src/azure/monitor/start-from-env.ts
28
- import { useAzureMonitor } from "@azure/monitor-opentelemetry";
29
-
30
- // src/azure/monitor/env.ts
31
- import { createEnv } from "@t3-oss/env-core";
32
- import { z } from "zod";
33
- var loadEnv = () => createEnv({
34
- emptyStringAsUndefined: true,
35
- onValidationError: (errors) => {
36
- throw new Error(
37
- errors.map(
38
- (error) => `Environment variable ${error.path} - ${error.message}`
39
- ).join(", ")
40
- );
41
- },
42
- runtimeEnv: process.env,
43
- server: {
44
- APPINSIGHTS_SAMPLING_PERCENTAGE: z.optional(
45
- z.coerce.number().min(0).max(100).default(5).describe(
46
- "Application Insights sampling percentage between 0 and 100. If not set, defaults to 5."
47
- )
48
- ).transform((value) => {
49
- const percentage = Number(value);
50
- return isNaN(percentage) ? 5 : percentage;
51
- }).transform((value) => value / 100),
52
- APPLICATIONINSIGHTS_CONNECTION_STRING: z.string().describe("The connection string for Application Insights.")
53
- }
54
- });
55
-
56
- // src/azure/monitor/start-from-env.ts
57
- var initFromEnv = () => {
58
- const env = loadEnv();
59
- return useAzureMonitor({
60
- azureMonitorExporterOptions: {
61
- connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING
62
- },
63
- enableLiveMetrics: true,
64
- samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE
65
- });
66
- };
67
-
68
- // src/azure/monitor/index.ts
69
- var initAzureMonitor = (instrumentations = [], azureMonitorOptions) => {
70
- if (azureMonitorOptions) {
71
- useAzureMonitor2(azureMonitorOptions);
72
- } else {
73
- initFromEnv();
74
- }
75
- registerInstrumentations({
76
- instrumentations: [registerUndiciInstrumentation(), ...instrumentations],
77
- meterProvider: metrics.getMeterProvider(),
78
- tracerProvider: trace.getTracerProvider()
79
- });
80
- };
81
- export {
82
- initAzureMonitor
83
- };
84
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/azure/monitor/index.ts","../../src/azure/opentelemetry/azure-undici-instrumentation.ts","../../src/azure/monitor/start-from-env.ts","../../src/azure/monitor/env.ts"],"sourcesContent":["import {\n AzureMonitorOpenTelemetryOptions,\n useAzureMonitor,\n} from \"@azure/monitor-opentelemetry\";\nimport { metrics, trace } from \"@opentelemetry/api\";\nimport {\n Instrumentation,\n registerInstrumentations,\n} from \"@opentelemetry/instrumentation\";\n\nimport { registerUndiciInstrumentation } from \"../opentelemetry/azure-undici-instrumentation\";\nimport { initFromEnv } from \"./start-from-env\";\n\n/**\n * Initialize the Azure Monitor with the given instrumentations and options.\n * This function sets up telemetry collection for your application by registering\n * the provided instrumentations and configuring Azure Monitor OpenTelemetry.\n *\n * By default, the Undici instrumentation is included. You can extend the functionality\n * by passing additional instrumentations as an array.\n *\n * @remarks\n * - This function should be called at the start of your application to ensure\n * telemetry is collected from the beginning.\n * - If `azureMonitorOptions` is not provided, the configuration will be initialized\n * using environment variables. @see README for more details.\n *\n * @example\n * // Basic usage with default settings\n * import { initAzureMonitor } from \"@pagopa/azure-tracing/azure-monitor\";\n * initAzureMonitor();\n *\n * @example\n * // Usage with custom instrumentations\n * import { initAzureMonitor } from \"@pagopa/azure-tracing/azure-monitor\";\n * import { MyCustomInstrumentation } from \"my-custom-instrumentation\";\n *\n * initAzureMonitor([new MyCustomInstrumentation()]);\n *\n * @example\n * // Usage with custom Azure Monitor options\n * import { initAzureMonitor } from \"@pagopa/azure-tracing/azure-monitor\";\n *\n * initAzureMonitor([], {\n * azureMonitorExporterOptions: {\n * connectionString: \"theConnectionString\",\n * },\n * // other options...\n * });\n *\n * @param instrumentations - The list of instrumentations to register with the Azure Monitor.\n * @param azureMonitorOptions - Custom configuration for Azure Monitor. If not provided,\n * it will be initialized using environment variables.\n */\nexport const initAzureMonitor = (\n instrumentations: readonly Instrumentation[] = [],\n azureMonitorOptions?: AzureMonitorOpenTelemetryOptions,\n) => {\n if (azureMonitorOptions) {\n useAzureMonitor(azureMonitorOptions);\n } else {\n initFromEnv();\n }\n\n registerInstrumentations({\n instrumentations: [registerUndiciInstrumentation(), ...instrumentations],\n meterProvider: metrics.getMeterProvider(),\n tracerProvider: trace.getTracerProvider(),\n });\n};\n","import { UndiciInstrumentation } from \"@opentelemetry/instrumentation-undici\";\n\n// instrument native node fetch\nexport const registerUndiciInstrumentation = () =>\n new UndiciInstrumentation({\n requestHook: (span, requestInfo) => {\n const { method, origin, path } = requestInfo;\n // Default instrumented attributes don't feed well into AppInsights,\n // so we set them manually.\n span.setAttributes({\n \"http.host\": origin,\n \"http.method\": method,\n \"http.target\": path,\n \"http.url\": `${origin}${path}`,\n });\n },\n responseHook: (span, { response }) => {\n // Same as above, set the status code manually.\n span.setAttribute(\"http.status_code\", response.statusCode);\n },\n });\n","import { useAzureMonitor } from \"@azure/monitor-opentelemetry\";\n\nimport { loadEnv } from \"./env\";\n\nexport const initFromEnv = () => {\n const env = loadEnv();\n\n return useAzureMonitor({\n azureMonitorExporterOptions: {\n connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING,\n },\n enableLiveMetrics: true,\n samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE,\n });\n};\n","// Load and type check environment variables on runtime\nimport { createEnv } from \"@t3-oss/env-core\";\nimport { z } from \"zod\";\n\nexport const loadEnv = () =>\n createEnv({\n emptyStringAsUndefined: true,\n onValidationError: (errors) => {\n throw new Error(\n errors\n .map(\n (error) => `Environment variable ${error.path} - ${error.message}`,\n )\n .join(\", \"),\n );\n },\n runtimeEnv: process.env,\n server: {\n APPINSIGHTS_SAMPLING_PERCENTAGE: z\n .optional(\n z.coerce\n .number()\n .min(0)\n .max(100)\n .default(5)\n .describe(\n \"Application Insights sampling percentage between 0 and 100. If not set, defaults to 5.\",\n ),\n )\n .transform((value) => {\n const percentage = Number(value);\n return isNaN(percentage) ? 5 : percentage;\n })\n .transform((value) => value / 100),\n APPLICATIONINSIGHTS_CONNECTION_STRING: z\n .string()\n .describe(\"The connection string for Application Insights.\"),\n },\n });\n"],"mappings":";AAAA;AAAA,EAEE,mBAAAA;AAAA,OACK;AACP,SAAS,SAAS,aAAa;AAC/B;AAAA,EAEE;AAAA,OACK;;;ACRP,SAAS,6BAA6B;AAG/B,IAAM,gCAAgC,MAC3C,IAAI,sBAAsB;AAAA,EACxB,aAAa,CAAC,MAAM,gBAAgB;AAClC,UAAM,EAAE,QAAQ,QAAQ,KAAK,IAAI;AAGjC,SAAK,cAAc;AAAA,MACjB,aAAa;AAAA,MACb,eAAe;AAAA,MACf,eAAe;AAAA,MACf,YAAY,GAAG,MAAM,GAAG,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAAA,EACA,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM;AAEpC,SAAK,aAAa,oBAAoB,SAAS,UAAU;AAAA,EAC3D;AACF,CAAC;;;ACpBH,SAAS,uBAAuB;;;ACChC,SAAS,iBAAiB;AAC1B,SAAS,SAAS;AAEX,IAAM,UAAU,MACrB,UAAU;AAAA,EACR,wBAAwB;AAAA,EACxB,mBAAmB,CAAC,WAAW;AAC7B,UAAM,IAAI;AAAA,MACR,OACG;AAAA,QACC,CAAC,UAAU,wBAAwB,MAAM,IAAI,MAAM,MAAM,OAAO;AAAA,MAClE,EACC,KAAK,IAAI;AAAA,IACd;AAAA,EACF;AAAA,EACA,YAAY,QAAQ;AAAA,EACpB,QAAQ;AAAA,IACN,iCAAiC,EAC9B;AAAA,MACC,EAAE,OACC,OAAO,EACP,IAAI,CAAC,EACL,IAAI,GAAG,EACP,QAAQ,CAAC,EACT;AAAA,QACC;AAAA,MACF;AAAA,IACJ,EACC,UAAU,CAAC,UAAU;AACpB,YAAM,aAAa,OAAO,KAAK;AAC/B,aAAO,MAAM,UAAU,IAAI,IAAI;AAAA,IACjC,CAAC,EACA,UAAU,CAAC,UAAU,QAAQ,GAAG;AAAA,IACnC,uCAAuC,EACpC,OAAO,EACP,SAAS,iDAAiD;AAAA,EAC/D;AACF,CAAC;;;ADlCI,IAAM,cAAc,MAAM;AAC/B,QAAM,MAAM,QAAQ;AAEpB,SAAO,gBAAgB;AAAA,IACrB,6BAA6B;AAAA,MAC3B,kBAAkB,IAAI;AAAA,IACxB;AAAA,IACA,mBAAmB;AAAA,IACnB,eAAe,IAAI;AAAA,EACrB,CAAC;AACH;;;AFwCO,IAAM,mBAAmB,CAC9B,mBAA+C,CAAC,GAChD,wBACG;AACH,MAAI,qBAAqB;AACvB,IAAAC,iBAAgB,mBAAmB;AAAA,EACrC,OAAO;AACL,gBAAY;AAAA,EACd;AAEA,2BAAyB;AAAA,IACvB,kBAAkB,CAAC,8BAA8B,GAAG,GAAG,gBAAgB;AAAA,IACvE,eAAe,QAAQ,iBAAiB;AAAA,IACxC,gBAAgB,MAAM,kBAAkB;AAAA,EAC1C,CAAC;AACH;","names":["useAzureMonitor","useAzureMonitor"]}
@@ -1,39 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/azure/opentelemetry/logger.ts
21
- var logger_exports = {};
22
- __export(logger_exports, {
23
- emitCustomEvent: () => emitCustomEvent
24
- });
25
- module.exports = __toCommonJS(logger_exports);
26
- var import_api_logs = require("@opentelemetry/api-logs");
27
- var emitCustomEvent = (eventName, attributes = {}) => (loggerName = "ApplicationInsightsLogger") => {
28
- import_api_logs.logs.getLogger(loggerName).emit({
29
- attributes: {
30
- "microsoft.custom_event.name": eventName,
31
- ...attributes
32
- }
33
- });
34
- };
35
- // Annotate the CommonJS export names for ESM import in node:
36
- 0 && (module.exports = {
37
- emitCustomEvent
38
- });
39
- //# sourceMappingURL=logger.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/azure/opentelemetry/logger.ts"],"sourcesContent":["import { logs } from \"@opentelemetry/api-logs\";\n\n/**\n * Emit a custom event to the Azure Monitor.\n * This function is used to emit custom events to the Azure Monitor.\n *\n * @param eventName the name of the event to emit\n * @param attributes the attributes to include with the event\n */\nexport const emitCustomEvent =\n (eventName: string, attributes: Record<string, string> = {}) =>\n (loggerName = \"ApplicationInsightsLogger\") => {\n logs.getLogger(loggerName).emit({\n attributes: {\n \"microsoft.custom_event.name\": eventName,\n ...attributes,\n },\n });\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAqB;AASd,IAAM,kBACX,CAAC,WAAmB,aAAqC,CAAC,MAC1D,CAAC,aAAa,gCAAgC;AAC5C,uBAAK,UAAU,UAAU,EAAE,KAAK;AAAA,IAC9B,YAAY;AAAA,MACV,+BAA+B;AAAA,MAC/B,GAAG;AAAA,IACL;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,10 +0,0 @@
1
- /**
2
- * Emit a custom event to the Azure Monitor.
3
- * This function is used to emit custom events to the Azure Monitor.
4
- *
5
- * @param eventName the name of the event to emit
6
- * @param attributes the attributes to include with the event
7
- */
8
- declare const emitCustomEvent: (eventName: string, attributes?: Record<string, string>) => (loggerName?: string) => void;
9
-
10
- export { emitCustomEvent };
@@ -1,10 +0,0 @@
1
- /**
2
- * Emit a custom event to the Azure Monitor.
3
- * This function is used to emit custom events to the Azure Monitor.
4
- *
5
- * @param eventName the name of the event to emit
6
- * @param attributes the attributes to include with the event
7
- */
8
- declare const emitCustomEvent: (eventName: string, attributes?: Record<string, string>) => (loggerName?: string) => void;
9
-
10
- export { emitCustomEvent };
@@ -1,14 +0,0 @@
1
- // src/azure/opentelemetry/logger.ts
2
- import { logs } from "@opentelemetry/api-logs";
3
- var emitCustomEvent = (eventName, attributes = {}) => (loggerName = "ApplicationInsightsLogger") => {
4
- logs.getLogger(loggerName).emit({
5
- attributes: {
6
- "microsoft.custom_event.name": eventName,
7
- ...attributes
8
- }
9
- });
10
- };
11
- export {
12
- emitCustomEvent
13
- };
14
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/azure/opentelemetry/logger.ts"],"sourcesContent":["import { logs } from \"@opentelemetry/api-logs\";\n\n/**\n * Emit a custom event to the Azure Monitor.\n * This function is used to emit custom events to the Azure Monitor.\n *\n * @param eventName the name of the event to emit\n * @param attributes the attributes to include with the event\n */\nexport const emitCustomEvent =\n (eventName: string, attributes: Record<string, string> = {}) =>\n (loggerName = \"ApplicationInsightsLogger\") => {\n logs.getLogger(loggerName).emit({\n attributes: {\n \"microsoft.custom_event.name\": eventName,\n ...attributes,\n },\n });\n };\n"],"mappings":";AAAA,SAAS,YAAY;AASd,IAAM,kBACX,CAAC,WAAmB,aAAqC,CAAC,MAC1D,CAAC,aAAa,gCAAgC;AAC5C,OAAK,UAAU,UAAU,EAAE,KAAK;AAAA,IAC9B,YAAY;AAAA,MACV,+BAA+B;AAAA,MAC/B,GAAG;AAAA,IACL;AAAA,EACF,CAAC;AACH;","names":[]}