@pagopa/azure-tracing 0.4.12 → 0.4.14

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.
@@ -1 +1 @@
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
+ {"version":3,"sources":["../../src/azure/functions/hooks.ts"],"sourcesContent":["import { context as otelContext, propagation } from \"@opentelemetry/api\";\n\n/**\n * Minimal structural interface for the Azure Functions v4 `app` object.\n * Using a structural type instead of `typeof app` from `@azure/functions`\n * makes this function compatible with any minor version of `@azure/functions@^4`\n * installed by the consumer, without type conflicts between versions.\n */\ninterface AzureFunctionsApp {\n hook: {\n preInvocation: (\n handler: (context: {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type -- Function is intentionally used here to remain compatible with any minor version of @azure/functions without importing its types\n functionHandler: Function;\n invocationContext: {\n traceContext?: {\n traceParent?: null | string;\n traceState?: null | string;\n };\n };\n }) => void,\n ) => unknown;\n };\n}\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 }: AzureFunctionsApp) => {\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;AAAA,iBAAoD;AA0C7C,IAAM,6BAA6B,CAAC,EAAE,KAAK,MAAyB;AACzE,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,5 +1,22 @@
1
- import { app } from '@azure/functions';
2
-
1
+ /**
2
+ * Minimal structural interface for the Azure Functions v4 `app` object.
3
+ * Using a structural type instead of `typeof app` from `@azure/functions`
4
+ * makes this function compatible with any minor version of `@azure/functions@^4`
5
+ * installed by the consumer, without type conflicts between versions.
6
+ */
7
+ interface AzureFunctionsApp {
8
+ hook: {
9
+ preInvocation: (handler: (context: {
10
+ functionHandler: Function;
11
+ invocationContext: {
12
+ traceContext?: {
13
+ traceParent?: null | string;
14
+ traceState?: null | string;
15
+ };
16
+ };
17
+ }) => void) => unknown;
18
+ };
19
+ }
3
20
  /**
4
21
  * Registers Azure Function hooks to enable OpenTelemetry tracing.
5
22
  * These hooks extract trace context from the Azure Function context
@@ -11,12 +28,12 @@ import { app } from '@azure/functions';
11
28
  * to the instrumentation package and remove this workaround.
12
29
  *
13
30
  * @example
14
- * In your application, where you add the Azure Functions hooks (like `app.http() and so on), you
31
+ * In your application, where you add the Azure Functions hooks (like `app.http()` and so on), you
15
32
  * can add the following code:
16
33
  *
17
34
  * registerAzureFunctionHooks(app);
18
35
  *
19
36
  */
20
- declare const registerAzureFunctionHooks: ({ hook }: typeof app) => void;
37
+ declare const registerAzureFunctionHooks: ({ hook }: AzureFunctionsApp) => void;
21
38
 
22
39
  export { registerAzureFunctionHooks };
@@ -1,5 +1,22 @@
1
- import { app } from '@azure/functions';
2
-
1
+ /**
2
+ * Minimal structural interface for the Azure Functions v4 `app` object.
3
+ * Using a structural type instead of `typeof app` from `@azure/functions`
4
+ * makes this function compatible with any minor version of `@azure/functions@^4`
5
+ * installed by the consumer, without type conflicts between versions.
6
+ */
7
+ interface AzureFunctionsApp {
8
+ hook: {
9
+ preInvocation: (handler: (context: {
10
+ functionHandler: Function;
11
+ invocationContext: {
12
+ traceContext?: {
13
+ traceParent?: null | string;
14
+ traceState?: null | string;
15
+ };
16
+ };
17
+ }) => void) => unknown;
18
+ };
19
+ }
3
20
  /**
4
21
  * Registers Azure Function hooks to enable OpenTelemetry tracing.
5
22
  * These hooks extract trace context from the Azure Function context
@@ -11,12 +28,12 @@ import { app } from '@azure/functions';
11
28
  * to the instrumentation package and remove this workaround.
12
29
  *
13
30
  * @example
14
- * In your application, where you add the Azure Functions hooks (like `app.http() and so on), you
31
+ * In your application, where you add the Azure Functions hooks (like `app.http()` and so on), you
15
32
  * can add the following code:
16
33
  *
17
34
  * registerAzureFunctionHooks(app);
18
35
  *
19
36
  */
20
- declare const registerAzureFunctionHooks: ({ hook }: typeof app) => void;
37
+ declare const registerAzureFunctionHooks: ({ hook }: AzureFunctionsApp) => void;
21
38
 
22
39
  export { registerAzureFunctionHooks };
@@ -1 +1 @@
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
+ {"version":3,"sources":["../../src/azure/functions/hooks.ts"],"sourcesContent":["import { context as otelContext, propagation } from \"@opentelemetry/api\";\n\n/**\n * Minimal structural interface for the Azure Functions v4 `app` object.\n * Using a structural type instead of `typeof app` from `@azure/functions`\n * makes this function compatible with any minor version of `@azure/functions@^4`\n * installed by the consumer, without type conflicts between versions.\n */\ninterface AzureFunctionsApp {\n hook: {\n preInvocation: (\n handler: (context: {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type -- Function is intentionally used here to remain compatible with any minor version of @azure/functions without importing its types\n functionHandler: Function;\n invocationContext: {\n traceContext?: {\n traceParent?: null | string;\n traceState?: null | string;\n };\n };\n }) => void,\n ) => unknown;\n };\n}\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 }: AzureFunctionsApp) => {\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,SAAS,WAAW,aAAa,mBAAmB;AA0C7C,IAAM,6BAA6B,CAAC,EAAE,KAAK,MAAyB;AACzE,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":[]}
@@ -43,7 +43,10 @@ var initFromEnv = () => {
43
43
  connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING
44
44
  },
45
45
  enableLiveMetrics: true,
46
- samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE
46
+ samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE,
47
+ // Disable the RateLimitedSampler (new default in 1.16.0) so that
48
+ // samplingRatio is respected via the ApplicationInsightsSampler.
49
+ tracesPerSecond: 0
47
50
  });
48
51
  };
49
52
 
@@ -1 +1 @@
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
+ {"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 // Disable the RateLimitedSampler (new default in 1.16.0) so that\n // samplingRatio is respected via the ApplicationInsightsSampler.\n tracesPerSecond: 0,\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;AAAA;AAAA,IAGnB,iBAAiB;AAAA,EACnB,CAAC;AACH;;;AEjBA,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":[]}
@@ -41,7 +41,10 @@ var initFromEnv = () => {
41
41
  connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING
42
42
  },
43
43
  enableLiveMetrics: true,
44
- samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE
44
+ samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE,
45
+ // Disable the RateLimitedSampler (new default in 1.16.0) so that
46
+ // samplingRatio is respected via the ApplicationInsightsSampler.
47
+ tracesPerSecond: 0
45
48
  });
46
49
  };
47
50
 
@@ -1 +1 @@
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
+ {"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 // Disable the RateLimitedSampler (new default in 1.16.0) so that\n // samplingRatio is respected via the ApplicationInsightsSampler.\n tracesPerSecond: 0,\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;AAAA;AAAA,IAGnB,iBAAiB;AAAA,EACnB,CAAC;AACH;;;AEjBA,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":[]}
@@ -81,7 +81,10 @@ var initFromEnv = () => {
81
81
  connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING
82
82
  },
83
83
  enableLiveMetrics: true,
84
- samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE
84
+ samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE,
85
+ // Disable the RateLimitedSampler (new default in 1.16.0) so that
86
+ // samplingRatio is respected via the ApplicationInsightsSampler.
87
+ tracesPerSecond: 0
85
88
  });
86
89
  };
87
90
 
@@ -1 +1 @@
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
+ {"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 // Disable the RateLimitedSampler (new default in 1.16.0) so that\n // samplingRatio is respected via the ApplicationInsightsSampler.\n tracesPerSecond: 0,\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;AAAA;AAAA,IAGnB,iBAAiB;AAAA,EACnB,CAAC;AACH;;;AFqCO,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"]}
@@ -61,7 +61,10 @@ var initFromEnv = () => {
61
61
  connectionString: env.APPLICATIONINSIGHTS_CONNECTION_STRING
62
62
  },
63
63
  enableLiveMetrics: true,
64
- samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE
64
+ samplingRatio: env.APPINSIGHTS_SAMPLING_PERCENTAGE,
65
+ // Disable the RateLimitedSampler (new default in 1.16.0) so that
66
+ // samplingRatio is respected via the ApplicationInsightsSampler.
67
+ tracesPerSecond: 0
65
68
  });
66
69
  };
67
70
 
@@ -1 +1 @@
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
+ {"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 // Disable the RateLimitedSampler (new default in 1.16.0) so that\n // samplingRatio is respected via the ApplicationInsightsSampler.\n tracesPerSecond: 0,\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;AAAA;AAAA,IAGnB,iBAAiB;AAAA,EACnB,CAAC;AACH;;;AFqCO,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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/azure-tracing",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "type": "module",
5
5
  "description": "A package that contains some utilities to enable Azure tracing on Node.js applications.",
6
6
  "repository": {
@@ -65,27 +65,30 @@
65
65
  }
66
66
  },
67
67
  "dependencies": {
68
- "@azure/functions": "^4.7.2",
69
- "@azure/monitor-opentelemetry": "1.13.1",
68
+ "@azure/monitor-opentelemetry": "1.16.0",
70
69
  "@azure/monitor-opentelemetry-exporter": "^1.0.0-beta.32",
71
70
  "@opentelemetry/api": "^1.9.0",
72
- "@opentelemetry/api-logs": "^0.205.0",
73
- "@opentelemetry/instrumentation": "^0.205.0",
74
- "@opentelemetry/instrumentation-undici": "^0.16.2",
75
- "@t3-oss/env-core": "^0.13.8",
76
- "import-in-the-middle": "^1.15.0",
71
+ "@opentelemetry/api-logs": "^0.213.0",
72
+ "@opentelemetry/instrumentation": "^0.213.0",
73
+ "@opentelemetry/instrumentation-undici": "^0.23.0",
74
+ "@t3-oss/env-core": "^0.13.11",
75
+ "import-in-the-middle": "^3.0.0",
77
76
  "zod": "^3.25.76"
78
77
  },
79
78
  "devDependencies": {
80
- "@tsconfig/node24": "24.0.0",
81
- "@types/node": "^22.19.1",
82
- "eslint": "^9.39.2",
79
+ "@azure/functions": "^4.11.2",
80
+ "@tsconfig/node24": "24.0.4",
81
+ "@types/node": "^22.19.15",
82
+ "@vitest/coverage-v8": "^3.2.4",
83
+ "eslint": "^10.1.0",
83
84
  "tsup": "^8.5.1",
84
- "typescript": "~5.8.3",
85
- "@pagopa/eslint-config": "^5.1.2"
85
+ "typescript": "~5.9.3",
86
+ "vitest": "^3.2.4",
87
+ "@pagopa/eslint-config": "^6.0.1"
86
88
  },
87
89
  "scripts": {
88
90
  "build": "tsup",
91
+ "test": "vitest",
89
92
  "typecheck": "tsc --noEmit"
90
93
  }
91
94
  }