Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions apps/io-lollipop/api/external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ components:
format: int32
description: >-
The HTTP status code generated by the origin server for this
occurrence

of the problem.
occurrence of the problem.
minimum: 100
maximum: 600
exclusiveMaximum: true
Expand Down
4 changes: 1 addition & 3 deletions apps/io-lollipop/api/internal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ components:
format: int32
description: >-
The HTTP status code generated by the origin server for this
occurrence

of the problem.
occurrence of the problem.
minimum: 100
maximum: 600
exclusiveMaximum: true
Expand Down
8 changes: 4 additions & 4 deletions apps/io-lollipop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
"vitest": "~1.5.0"
},
"dependencies": {
"@azure/cosmos": "^3.17.2",
"@azure/cosmos": "^4.0.0",
"@mattrglobal/http-signatures": "^4.0.1",
"@pagopa/express-azure-functions": "^2.0.0",
"@pagopa/io-functions-commons": "28.1.0",
"@pagopa/io-functions-commons": "^29.3.0",
"@pagopa/openapi-codegen-ts": "^12.2.0",
"@pagopa/ts-commons": "^11.0.0",
"@pagopa/ts-commons": "^13.1.2",
"@pagopa/winston-ts": "^2.2.0",
"@xmldom/xmldom": "^0.8.10",
"applicationinsights": "1.8.10",
"applicationinsights": "^2.9.5",
"azure-storage": "^2.10.3",
"date-fns": "^2.29.3",
"express": "^4.15.3",
Expand Down
4 changes: 1 addition & 3 deletions apps/io-lollipop/src/ActivatePubKey/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ const assertionBlobService = createBlobService(
config.LOLLIPOP_ASSERTION_STORAGE_CONNECTION_STRING
);

const telemetryClient = initTelemetryClient(
config.APPINSIGHTS_INSTRUMENTATIONKEY
);
const telemetryClient = initTelemetryClient(config);

// eslint-disable-next-line functional/no-let
let logger: Context["log"];
Expand Down
4 changes: 1 addition & 3 deletions apps/io-lollipop/src/GenerateLCParams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ import { GenerateLCParams } from "./handler";

const config = getConfigOrThrow();

const telemetryClient = initTelemetryClient(
config.APPINSIGHTS_INSTRUMENTATIONKEY
);
const telemetryClient = initTelemetryClient(config);

// eslint-disable-next-line functional/no-let
let logger: Context["log"];
Expand Down
4 changes: 1 addition & 3 deletions apps/io-lollipop/src/GetAssertion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ import { GetAssertion } from "./handler";

const config = getConfigOrThrow();

const telemetryClient = initTelemetryClient(
config.APPINSIGHTS_INSTRUMENTATIONKEY
);
const telemetryClient = initTelemetryClient(config);

const lollipopKeysModel = new LolliPOPKeysModel(
cosmosdbInstance.container(LOLLIPOPKEYS_COLLECTION_NAME)
Expand Down
4 changes: 1 addition & 3 deletions apps/io-lollipop/src/HandlePubKeyRevoke/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const lollipopKeysModel = new LolliPOPKeysModel(
cosmosdbInstance.container(LOLLIPOPKEYS_COLLECTION_NAME)
);

const telemetryClient = initTelemetryClient(
config.APPINSIGHTS_INSTRUMENTATIONKEY
);
const telemetryClient = initTelemetryClient(config);

export const index: AzureFunction = (
context: Context,
Expand Down
4 changes: 1 addition & 3 deletions apps/io-lollipop/src/ReservePubKey/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ const lollipopPubkeysModel = new LolliPOPKeysModel(
cosmosdbInstance.container(LOLLIPOPKEYS_COLLECTION_NAME)
);

const telemetryClient = initTelemetryClient(
config.APPINSIGHTS_INSTRUMENTATIONKEY
);
const telemetryClient = initTelemetryClient(config);

// eslint-disable-next-line functional/no-let
let logger: Context["log"];
Expand Down
39 changes: 23 additions & 16 deletions apps/io-lollipop/src/utils/appinsights.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
import * as ai from "applicationinsights";
import { initAppInsights } from "@pagopa/ts-commons/lib/appinsights";
import { IntegerFromString } from "@pagopa/ts-commons/lib/numbers";
import { NonEmptyString } from "@pagopa/ts-commons/lib/strings";
import * as E from "fp-ts/lib/Either";
import * as O from "fp-ts/lib/Option";
import { pipe } from "fp-ts/lib/function";
import {
EventTelemetry,
ExceptionTelemetry
} from "applicationinsights/out/Declarations/Contracts";
import { AppInsightsConfig } from "./config";

// the internal function runtime has MaxTelemetryItem per second set to 20 by default
// @see https://github.com/Azure/azure-functions-host/blob/master/src/WebJobs.Script/Config/ApplicationInsightsLoggerOptionsSetup.cs#L29
const DEFAULT_SAMPLING_PERCENTAGE = 5;

// Avoid to initialize Application Insights more than once
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const initTelemetryClient = (
intrumentationKey: NonEmptyString,
env = process.env
) =>
ai.defaultClient
? ai.defaultClient
: initAppInsights(intrumentationKey, {
disableAppInsights: env.APPINSIGHTS_DISABLE === "true",
samplingPercentage: pipe(
IntegerFromString.decode(env.APPINSIGHTS_SAMPLING_PERCENTAGE),
E.getOrElse(() => DEFAULT_SAMPLING_PERCENTAGE)
)
});
export const initTelemetryClient = (config: AppInsightsConfig) =>
pipe(
ai.defaultClient,
O.fromNullable,
O.getOrElse(() => {
const client = initAppInsights(
config.APPLICATIONINSIGHTS_CONNECTION_STRING,
{
disableAppInsights: config.APPINSIGHTS_DISABLE === "true",
samplingPercentage: pipe(
config.APPINSIGHTS_SAMPLING_PERCENTAGE,
O.fromNullable,
O.getOrElse(() => DEFAULT_SAMPLING_PERCENTAGE)
)
}
);
// eslint-disable-next-line functional/immutable-data
client.config.correlationHeaderExcludedDomains =
config.APPINSIGHTS_EXCLUDED_DOMAINS || [];
return client;
})
);

export type TelemetryClient = ReturnType<typeof initTelemetryClient>;

Expand Down
23 changes: 20 additions & 3 deletions apps/io-lollipop/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import { pipe } from "fp-ts/lib/function";

import * as reporters from "@pagopa/ts-commons/lib/reporters";
import { NonEmptyString } from "@pagopa/ts-commons/lib/strings";
import { CommaSeparatedListOf } from "@pagopa/ts-commons/lib/comma-separated-list";
import {
IntegerFromString,
NonNegativeInteger,
NonNegativeIntegerFromString
} from "@pagopa/ts-commons/lib/numbers";
Expand Down Expand Up @@ -68,12 +70,26 @@ export const JWTConfig = t.intersection([
// ----------------------------
// Global app configuration
// ----------------------------
export type AppInsightsConfig = t.TypeOf<typeof AppInsightsConfig>;
export const AppInsightsConfig = t.intersection([
t.type({
// required for both appinsights sdk and azure function runtime
// changing the name of this variable would cause data loss on app insights
// source-> https://learn.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2#enable-application-insights-integration
APPLICATIONINSIGHTS_CONNECTION_STRING: NonEmptyString
}),
t.partial({
APPINSIGHTS_DISABLE: NonEmptyString,
APPINSIGHTS_EXCLUDED_DOMAINS: CommaSeparatedListOf(t.string).pipe(
t.array(NonEmptyString)
),
APPINSIGHTS_SAMPLING_PERCENTAGE: IntegerFromString
})
]);

export type IConfig = t.TypeOf<typeof IConfig>;
// eslint-disable-next-line @typescript-eslint/ban-types
export const IConfig = t.intersection([
t.interface({
APPINSIGHTS_INSTRUMENTATIONKEY: NonEmptyString,

COSMOSDB_KEY: NonEmptyString,
COSMOSDB_NAME: NonEmptyString,
COSMOSDB_URI: NonEmptyString,
Expand All @@ -89,6 +105,7 @@ export const IConfig = t.intersection([

isProduction: t.boolean
}),
AppInsightsConfig,
JWTConfig,
FirstLcAssertionClientConfig
]);
Expand Down
5 changes: 4 additions & 1 deletion docker/.env.common
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ API_GATEWAY_PORT=80
FUNCTION_LOLLIPOP_PORT=7071
FUNCTION_WEB_PROFILE_PORT=7072
FUNCTION_PUBLIC_PORT=7073
APPINSIGHTS_INSTRUMENTATIONKEY=foo
APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=foo;IngestionEndpoint=https://localhost;LiveEndpoint=https://localhost;ApplicationId=Bar"
APPINSIGHTS_DISABLE=false
APPINSIGHTS_SAMPLING_PERCENTAGE=100
APPINSIGHTS_EXCLUDED_DOMAINS="127.0.0.1,localhost,storage-account,azurite"

# --------
# Cosmos
Expand Down
9 changes: 6 additions & 3 deletions docker/io-lollipop/env-dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DOTNET_EnableWriteXorExecute=0
FUNCTION_LOLLIPOP_PORT=${FUNCTION_LOLLIPOP_PORT}

# -------------------
Expand All @@ -8,13 +9,15 @@ FUNCTIONS_WORKER_RUNTIME=node
WEBSITE_NODE_DEFAULT_VERSION=20.12.0

AZURE_ENABLE_STRICT_SSL=false
NODE_TLS_REJECT_UNAUTHORIZED=0
NODE_TLS_REJECT_UNAUTHORIZED=0

# -------------------
# appinsight infos
# -------------------
APPINSIGHTS_INSTRUMENTATIONKEY=${APPINSIGHTS_INSTRUMENTATIONKEY}
APPINSIGHTS_DISABLE=${APPINSIGHTS_DISABLE}
APPLICATIONINSIGHTS_CONNECTION_STRING=${APPLICATIONINSIGHTS_CONNECTION_STRING}
APPINSIGHTS_SAMPLING_PERCENTAGE=${APPINSIGHTS_SAMPLING_PERCENTAGE}
APPINSIGHTS_EXCLUDED_DOMAINS=${APPINSIGHTS_EXCLUDED_DOMAINS}

# --------
# Storage
Expand Down Expand Up @@ -56,4 +59,4 @@ DOTNET_EnableWriteXorExecute=0
# Test Data
# ----------
BEARER_AUTH_HEADER=x-pagopa-lollipop-auth
A_WRONG_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAkz9DugFKbN3mLZbKmVB+Ltf+0AHhUQgVh0nBF8bDbLOxOpR0\nxchiWrw4/GnlLAhorszTRAjn9//AHsn2HiZIFVrD9AnPJkgh0koilBOrh6WAmYI2\neXRCvdrTeA6zcz+0Cam3qN5VH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