@geekmidas/telescope 10.0.0-alpha.99 → 10.0.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/CHANGELOG.md +79 -0
- package/README.md +18 -28
- package/dist/InMemoryMetricsStorage-BbKCL3YL.d.mts +47 -0
- package/dist/InMemoryMetricsStorage-BbKCL3YL.d.mts.map +1 -0
- package/dist/InMemoryMetricsStorage-C4drxT7G.mjs +247 -0
- package/dist/InMemoryMetricsStorage-C4drxT7G.mjs.map +1 -0
- package/dist/InMemoryMetricsStorage-D0njWUSi.cjs +252 -0
- package/dist/InMemoryMetricsStorage-D0njWUSi.cjs.map +1 -0
- package/dist/InMemoryMetricsStorage-TvPdZjL0.d.cts +47 -0
- package/dist/InMemoryMetricsStorage-TvPdZjL0.d.cts.map +1 -0
- package/dist/{MetricsAggregator-BJdIvfEv.d.mts → MetricsAggregator-4SqelGcG.d.cts} +6 -3
- package/dist/MetricsAggregator-4SqelGcG.d.cts.map +1 -0
- package/dist/MetricsAggregator-B7lUICdH.cjs +363 -0
- package/dist/MetricsAggregator-B7lUICdH.cjs.map +1 -0
- package/dist/{MetricsAggregator-CnC3oT5q.d.cts → MetricsAggregator-DZrW8ls6.d.mts} +6 -3
- package/dist/MetricsAggregator-DZrW8ls6.d.mts.map +1 -0
- package/dist/MetricsAggregator-S3DQWNas.mjs +357 -0
- package/dist/MetricsAggregator-S3DQWNas.mjs.map +1 -0
- package/dist/MetricsStorage-B86e4131.d.cts +60 -0
- package/dist/MetricsStorage-B86e4131.d.cts.map +1 -0
- package/dist/MetricsStorage-BWyP2_12.d.mts +60 -0
- package/dist/MetricsStorage-BWyP2_12.d.mts.map +1 -0
- package/dist/MetricsStorage-BypQXWiv.mjs +0 -0
- package/dist/MetricsStorage-Or8pVCe4.cjs +0 -0
- package/dist/Telescope-Cs3fv8jt.cjs +395 -0
- package/dist/Telescope-Cs3fv8jt.cjs.map +1 -0
- package/dist/{Telescope-BVfDvVvY.d.mts → Telescope-D4nmwDRA.d.cts} +7 -4
- package/dist/Telescope-D4nmwDRA.d.cts.map +1 -0
- package/dist/Telescope-Dh5av3FC.mjs +389 -0
- package/dist/Telescope-Dh5av3FC.mjs.map +1 -0
- package/dist/{Telescope-DeqSHfuB.d.cts → Telescope-Dl6VSfxd.d.mts} +7 -4
- package/dist/Telescope-Dl6VSfxd.d.mts.map +1 -0
- package/dist/Telescope.cjs +4 -385
- package/dist/Telescope.d.cts +3 -1
- package/dist/Telescope.d.mts +3 -1
- package/dist/Telescope.mjs +4 -384
- package/dist/adapters/index.d.cts +2 -2
- package/dist/adapters/index.d.mts +2 -2
- package/dist/adapters/index.mjs +0 -1
- package/dist/adapters/lambda.cjs +10 -9
- package/dist/adapters/lambda.cjs.map +1 -1
- package/dist/adapters/lambda.d.cts +13 -9
- package/dist/adapters/lambda.d.cts.map +1 -1
- package/dist/adapters/lambda.d.mts +13 -9
- package/dist/adapters/lambda.d.mts.map +1 -1
- package/dist/adapters/lambda.mjs +4 -3
- package/dist/adapters/lambda.mjs.map +1 -1
- package/dist/adapters/middy.cjs +4 -236
- package/dist/adapters/middy.d.cts +5 -60
- package/dist/adapters/middy.d.mts +5 -60
- package/dist/adapters/middy.mjs +3 -234
- package/dist/adapters/types.d.cts +2 -162
- package/dist/adapters/types.d.mts +2 -162
- package/dist/adapters/types.mjs +0 -1
- package/dist/{rolldown-runtime-VH7oDXx4.cjs → chunk-CUT6urMc.cjs} +10 -8
- package/dist/core--quSp5Qr.d.mts +78 -0
- package/dist/core--quSp5Qr.d.mts.map +1 -0
- package/dist/core-B4Jpia5H.d.cts +78 -0
- package/dist/core-B4Jpia5H.d.cts.map +1 -0
- package/dist/core-CtVHRJGv.cjs +199 -0
- package/dist/core-CtVHRJGv.cjs.map +1 -0
- package/dist/core-D6hJ6exL.mjs +139 -0
- package/dist/core-D6hJ6exL.mjs.map +1 -0
- package/dist/core.cjs +22 -22
- package/dist/core.d.cts +4 -4
- package/dist/core.d.mts +4 -4
- package/dist/core.mjs +4 -3
- package/dist/hono--uKQ7Jgi.d.mts +71 -0
- package/dist/hono--uKQ7Jgi.d.mts.map +1 -0
- package/dist/hono-C4EgpbKQ.cjs +160 -0
- package/dist/hono-C4EgpbKQ.cjs.map +1 -0
- package/dist/hono-CemCKU87.d.cts +71 -0
- package/dist/hono-CemCKU87.d.cts.map +1 -0
- package/dist/hono-DxhvnVbF.mjs +136 -0
- package/dist/hono-DxhvnVbF.mjs.map +1 -0
- package/dist/http-BiNtg85L.d.mts +107 -0
- package/dist/http-BiNtg85L.d.mts.map +1 -0
- package/dist/http-DQzgLczm.mjs +159 -0
- package/dist/http-DQzgLczm.mjs.map +1 -0
- package/dist/http-D_Z8sYXZ.cjs +219 -0
- package/dist/http-D_Z8sYXZ.cjs.map +1 -0
- package/dist/http-Dvca6fC3.d.cts +107 -0
- package/dist/http-Dvca6fC3.d.cts.map +1 -0
- package/dist/index-BL32-cvv.d.cts +1 -0
- package/dist/index-CsuikFeJ.d.mts +1 -0
- package/dist/index.cjs +9 -8
- package/dist/index.d.cts +6 -5
- package/dist/index.d.mts +6 -5
- package/dist/index.mjs +7 -5
- package/dist/instrumentation/core.cjs +11 -147
- package/dist/instrumentation/core.d.cts +3 -74
- package/dist/instrumentation/core.d.mts +3 -74
- package/dist/instrumentation/core.mjs +2 -137
- package/dist/instrumentation/hono.cjs +6 -174
- package/dist/instrumentation/hono.d.cts +2 -86
- package/dist/instrumentation/hono.d.mts +2 -86
- package/dist/instrumentation/hono.mjs +3 -170
- package/dist/instrumentation/http.cjs +11 -189
- package/dist/instrumentation/http.d.cts +2 -119
- package/dist/instrumentation/http.d.mts +2 -119
- package/dist/instrumentation/http.mjs +2 -178
- package/dist/instrumentation/index.cjs +47 -56
- package/dist/instrumentation/index.d.cts +9 -11
- package/dist/instrumentation/index.d.mts +9 -11
- package/dist/instrumentation/index.mjs +9 -10
- package/dist/instrumentation/middleware.cjs +6 -164
- package/dist/instrumentation/middleware.d.cts +2 -83
- package/dist/instrumentation/middleware.d.mts +2 -83
- package/dist/instrumentation/middleware.mjs +3 -160
- package/dist/instrumentation/otel.cjs +3 -137
- package/dist/instrumentation/otel.d.cts +2 -97
- package/dist/instrumentation/otel.d.mts +2 -97
- package/dist/instrumentation/otel.mjs +3 -136
- package/dist/instrumentation/setup.cjs +4 -142
- package/dist/instrumentation/setup.d.cts +3 -139
- package/dist/instrumentation/setup.d.mts +3 -139
- package/dist/instrumentation/setup.mjs +3 -139
- package/dist/instrumentation/tracing.cjs +10 -114
- package/dist/instrumentation/tracing.d.cts +2 -49
- package/dist/instrumentation/tracing.d.mts +2 -49
- package/dist/instrumentation/tracing.mjs +2 -105
- package/dist/logger/console.cjs +12 -18
- package/dist/logger/console.cjs.map +1 -1
- package/dist/logger/console.d.cts +10 -7
- package/dist/logger/console.d.cts.map +1 -1
- package/dist/logger/console.d.mts +10 -7
- package/dist/logger/console.d.mts.map +1 -1
- package/dist/logger/console.mjs +11 -17
- package/dist/logger/console.mjs.map +1 -1
- package/dist/logger/pino.cjs +5 -6
- package/dist/logger/pino.cjs.map +1 -1
- package/dist/logger/pino.d.cts +10 -6
- package/dist/logger/pino.d.cts.map +1 -1
- package/dist/logger/pino.d.mts +10 -6
- package/dist/logger/pino.d.mts.map +1 -1
- package/dist/logger/pino.mjs +3 -2
- package/dist/logger/pino.mjs.map +1 -1
- package/dist/memory--BK4iWiv.d.cts +40 -0
- package/dist/memory--BK4iWiv.d.cts.map +1 -0
- package/dist/memory-6S9H-IF5.mjs +123 -0
- package/dist/memory-6S9H-IF5.mjs.map +1 -0
- package/dist/memory-B0d_n1g5.cjs +129 -0
- package/dist/memory-B0d_n1g5.cjs.map +1 -0
- package/dist/memory-DCirEVFW.d.mts +40 -0
- package/dist/memory-DCirEVFW.d.mts.map +1 -0
- package/dist/metrics/MetricsAggregator.cjs +2 -354
- package/dist/metrics/MetricsAggregator.d.cts +2 -1
- package/dist/metrics/MetricsAggregator.d.mts +2 -1
- package/dist/metrics/MetricsAggregator.mjs +2 -353
- package/dist/metrics/index.cjs +4 -3
- package/dist/metrics/index.d.cts +4 -2
- package/dist/metrics/index.d.mts +4 -2
- package/dist/metrics/index.mjs +4 -2
- package/dist/metrics/storage/InMemoryMetricsStorage.cjs +3 -240
- package/dist/metrics/storage/InMemoryMetricsStorage.d.cts +4 -43
- package/dist/metrics/storage/InMemoryMetricsStorage.d.mts +4 -43
- package/dist/metrics/storage/InMemoryMetricsStorage.mjs +3 -239
- package/dist/metrics/storage/MetricsStorage.cjs +1 -0
- package/dist/metrics/storage/MetricsStorage.d.cts +3 -56
- package/dist/metrics/storage/MetricsStorage.d.mts +3 -56
- package/dist/metrics/storage/MetricsStorage.mjs +1 -1
- package/dist/metrics/storage/index.cjs +6 -6
- package/dist/metrics/storage/index.d.cts +3 -3
- package/dist/metrics/storage/index.d.mts +3 -3
- package/dist/metrics/storage/index.mjs +5 -4
- package/dist/metrics/storage/types.cjs +2 -34
- package/dist/metrics/storage/types.d.cts +2 -207
- package/dist/metrics/storage/types.d.mts +2 -207
- package/dist/metrics/storage/types.mjs +2 -33
- package/dist/metrics-D5YT-Rnq.mjs +0 -0
- package/dist/metrics-fhD3l3C3.cjs +0 -0
- package/dist/middleware-B2jFUukM.cjs +184 -0
- package/dist/middleware-B2jFUukM.cjs.map +1 -0
- package/dist/middleware-BTDncHwm.mjs +160 -0
- package/dist/middleware-BTDncHwm.mjs.map +1 -0
- package/dist/middleware-CA84nsNN.d.cts +74 -0
- package/dist/middleware-CA84nsNN.d.cts.map +1 -0
- package/dist/middleware-DAceVpfw.d.mts +74 -0
- package/dist/middleware-DAceVpfw.d.mts.map +1 -0
- package/dist/middy-B6Btl8XE.d.mts +64 -0
- package/dist/middy-B6Btl8XE.d.mts.map +1 -0
- package/dist/middy-BTR3cyvk.mjs +236 -0
- package/dist/middy-BTR3cyvk.mjs.map +1 -0
- package/dist/middy-Bq0defVg.d.cts +64 -0
- package/dist/middy-Bq0defVg.d.cts.map +1 -0
- package/dist/middy-y5Zp27eG.cjs +247 -0
- package/dist/middy-y5Zp27eG.cjs.map +1 -0
- package/dist/otel-1bJPb2Z7.d.mts +101 -0
- package/dist/otel-1bJPb2Z7.d.mts.map +1 -0
- package/dist/otel-C1HqHA2O.cjs +136 -0
- package/dist/otel-C1HqHA2O.cjs.map +1 -0
- package/dist/otel-SBVoVEHr.d.cts +101 -0
- package/dist/otel-SBVoVEHr.d.cts.map +1 -0
- package/dist/otel-wulj5B-X.mjs +130 -0
- package/dist/otel-wulj5B-X.mjs.map +1 -0
- package/dist/otlp/hono.cjs +15 -9
- package/dist/otlp/hono.cjs.map +1 -1
- package/dist/otlp/hono.d.cts +13 -3
- package/dist/otlp/hono.d.cts.map +1 -1
- package/dist/otlp/hono.d.mts +13 -3
- package/dist/otlp/hono.d.mts.map +1 -1
- package/dist/otlp/hono.mjs +11 -5
- package/dist/otlp/hono.mjs.map +1 -1
- package/dist/otlp/index.cjs +11 -11
- package/dist/otlp/index.d.cts +7 -4
- package/dist/otlp/index.d.mts +7 -4
- package/dist/otlp/index.mjs +5 -4
- package/dist/otlp/receiver.cjs +4 -88
- package/dist/otlp/receiver.d.cts +7 -59
- package/dist/otlp/receiver.d.mts +7 -59
- package/dist/otlp/receiver.mjs +4 -87
- package/dist/otlp/transformer.cjs +5 -214
- package/dist/otlp/transformer.d.cts +3 -1
- package/dist/otlp/transformer.d.mts +3 -1
- package/dist/otlp/transformer.mjs +3 -211
- package/dist/otlp/types.cjs +5 -57
- package/dist/otlp/types.d.cts +1 -1
- package/dist/otlp/types.d.mts +1 -1
- package/dist/otlp/types.mjs +2 -53
- package/dist/receiver-Cj1lbAOO.cjs +94 -0
- package/dist/receiver-Cj1lbAOO.cjs.map +1 -0
- package/dist/receiver-CxVd_9CB.mjs +89 -0
- package/dist/receiver-CxVd_9CB.mjs.map +1 -0
- package/dist/receiver-DLICx5uU.d.cts +63 -0
- package/dist/receiver-DLICx5uU.d.cts.map +1 -0
- package/dist/receiver-UeZT-H8u.d.mts +63 -0
- package/dist/receiver-UeZT-H8u.d.mts.map +1 -0
- package/dist/redact-BzkITCNW.mjs +83 -0
- package/dist/redact-BzkITCNW.mjs.map +1 -0
- package/dist/redact-DVaSSPZT.cjs +95 -0
- package/dist/redact-DVaSSPZT.cjs.map +1 -0
- package/dist/redact.cjs +3 -84
- package/dist/redact.d.cts +8 -4
- package/dist/redact.d.cts.map +1 -1
- package/dist/redact.d.mts +8 -4
- package/dist/redact.d.mts.map +1 -1
- package/dist/redact.mjs +2 -80
- package/dist/server/hono.cjs +54 -33
- package/dist/server/hono.cjs.map +1 -1
- package/dist/server/hono.d.cts +14 -19
- package/dist/server/hono.d.cts.map +1 -1
- package/dist/server/hono.d.mts +14 -19
- package/dist/server/hono.d.mts.map +1 -1
- package/dist/server/hono.mjs +52 -31
- package/dist/server/hono.mjs.map +1 -1
- package/dist/setup-B9jM77Qk.mjs +98 -0
- package/dist/setup-B9jM77Qk.mjs.map +1 -0
- package/dist/setup-Bkxm4g6b.d.mts +87 -0
- package/dist/setup-Bkxm4g6b.d.mts.map +1 -0
- package/dist/setup-CYpff5B9.cjs +110 -0
- package/dist/setup-CYpff5B9.cjs.map +1 -0
- package/dist/setup-D58N1f9O.d.cts +87 -0
- package/dist/setup-D58N1f9O.d.cts.map +1 -0
- package/dist/storage/kysely.cjs +70 -82
- package/dist/storage/kysely.cjs.map +1 -1
- package/dist/storage/kysely.d.cts +20 -36
- package/dist/storage/kysely.d.cts.map +1 -1
- package/dist/storage/kysely.d.mts +20 -36
- package/dist/storage/kysely.d.mts.map +1 -1
- package/dist/storage/kysely.mjs +69 -81
- package/dist/storage/kysely.mjs.map +1 -1
- package/dist/storage/memory.cjs +2 -122
- package/dist/storage/memory.d.cts +3 -36
- package/dist/storage/memory.d.mts +3 -36
- package/dist/storage/memory.mjs +2 -121
- package/dist/tracing-BX8uY2nR.d.cts +53 -0
- package/dist/tracing-BX8uY2nR.d.cts.map +1 -0
- package/dist/tracing-Bt1zWRlb.cjs +167 -0
- package/dist/tracing-Bt1zWRlb.cjs.map +1 -0
- package/dist/tracing-Cijm_5NI.mjs +113 -0
- package/dist/tracing-Cijm_5NI.mjs.map +1 -0
- package/dist/tracing-PnECEbEu.d.mts +53 -0
- package/dist/tracing-PnECEbEu.d.mts.map +1 -0
- package/dist/transformer-BXQPhzql.mjs +215 -0
- package/dist/transformer-BXQPhzql.mjs.map +1 -0
- package/dist/transformer-CLGZ0EQc.cjs +232 -0
- package/dist/transformer-CLGZ0EQc.cjs.map +1 -0
- package/dist/{transformer-BtqjAs0b.d.cts → transformer-CTGsaVfV.d.mts} +8 -4
- package/dist/transformer-CTGsaVfV.d.mts.map +1 -0
- package/dist/{transformer-DI6t8-YA.d.mts → transformer-ICEbxpFf.d.cts} +8 -4
- package/dist/transformer-ICEbxpFf.d.cts.map +1 -0
- package/dist/{types-BVujq4zd.d.mts → types-B1EIa_cQ.d.mts} +4 -3
- package/dist/types-B1EIa_cQ.d.mts.map +1 -0
- package/dist/types-BRzW1NM8.d.cts +166 -0
- package/dist/types-BRzW1NM8.d.cts.map +1 -0
- package/dist/types-BS3Rx8Sk.d.cts +209 -0
- package/dist/types-BS3Rx8Sk.d.cts.map +1 -0
- package/dist/types-Bwm_jNU7.mjs +54 -0
- package/dist/types-Bwm_jNU7.mjs.map +1 -0
- package/dist/types-BzQ78Efw.d.mts +166 -0
- package/dist/types-BzQ78Efw.d.mts.map +1 -0
- package/dist/types-CbNGXnJE.d.mts +209 -0
- package/dist/types-CbNGXnJE.d.mts.map +1 -0
- package/dist/{types-DVETVdpa.d.cts → types-CmOB7CLO.d.cts} +7 -6
- package/dist/types-CmOB7CLO.d.cts.map +1 -0
- package/dist/{types-DVETVdpa.d.mts → types-DBc0q5KD.d.mts} +7 -6
- package/dist/types-DBc0q5KD.d.mts.map +1 -0
- package/dist/types-Dsh-DIO_.cjs +78 -0
- package/dist/types-Dsh-DIO_.cjs.map +1 -0
- package/dist/types-ZW-nfWf6.cjs +40 -0
- package/dist/types-ZW-nfWf6.cjs.map +1 -0
- package/dist/{types-BVujq4zd.d.cts → types-l7Rlb5Mg.d.cts} +4 -3
- package/dist/types-l7Rlb5Mg.d.cts.map +1 -0
- package/dist/types-ojhnLdwz.mjs +34 -0
- package/dist/types-ojhnLdwz.mjs.map +1 -0
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.mjs +0 -1
- package/dist/ui-assets-BEXqOQLe.cjs +48 -0
- package/dist/ui-assets-BEXqOQLe.cjs.map +1 -0
- package/dist/ui-assets-BhTDUsrM.mjs +30 -0
- package/dist/ui-assets-BhTDUsrM.mjs.map +1 -0
- package/dist/ui-assets.cjs +5 -0
- package/dist/ui-assets.d.cts +13 -0
- package/dist/ui-assets.d.cts.map +1 -0
- package/dist/ui-assets.d.mts +13 -0
- package/dist/ui-assets.d.mts.map +1 -0
- package/dist/ui-assets.mjs +3 -0
- package/package.json +46 -46
- package/src/Telescope.ts +561 -0
- package/src/__tests__/Telescope.spec.ts +438 -0
- package/src/__tests__/pino-transport.spec.ts +115 -0
- package/src/__tests__/redact.spec.ts +336 -0
- package/src/adapters/__tests__/lambda.spec.ts +318 -0
- package/src/adapters/__tests__/middy.spec.ts +741 -0
- package/src/adapters/index.ts +22 -0
- package/src/adapters/lambda.ts +432 -0
- package/src/adapters/middy.ts +402 -0
- package/src/adapters/types.ts +181 -0
- package/src/core.ts +51 -0
- package/src/index.ts +34 -0
- package/src/instrumentation/__tests__/core.spec.ts +248 -0
- package/src/instrumentation/__tests__/hono.spec.ts +348 -0
- package/src/instrumentation/__tests__/middleware.spec.ts +528 -0
- package/src/instrumentation/__tests__/otel.spec.ts +291 -0
- package/src/instrumentation/__tests__/tracing.spec.ts +208 -0
- package/src/instrumentation/core.ts +228 -0
- package/src/instrumentation/hono.ts +270 -0
- package/src/instrumentation/http.ts +306 -0
- package/src/instrumentation/index.ts +90 -0
- package/src/instrumentation/middleware.ts +297 -0
- package/src/instrumentation/otel.ts +271 -0
- package/src/instrumentation/setup.ts +246 -0
- package/src/instrumentation/tracing.ts +145 -0
- package/src/logger/__tests__/console.spec.ts +366 -0
- package/src/logger/__tests__/pino.spec.ts +217 -0
- package/src/logger/console.ts +230 -0
- package/src/logger/pino.ts +201 -0
- package/src/metrics/MetricsAggregator.ts +555 -0
- package/src/metrics/__tests__/MetricsAggregator.spec.ts +298 -0
- package/src/metrics/index.ts +2 -0
- package/src/metrics/storage/InMemoryMetricsStorage.ts +380 -0
- package/src/metrics/storage/MetricsStorage.ts +74 -0
- package/src/metrics/storage/index.ts +3 -0
- package/src/metrics/storage/types.ts +243 -0
- package/src/otlp/__tests__/receiver.spec.ts +367 -0
- package/src/otlp/__tests__/transformer.spec.ts +455 -0
- package/src/otlp/hono.ts +120 -0
- package/src/otlp/index.ts +22 -0
- package/src/otlp/receiver.ts +162 -0
- package/src/otlp/transformer.ts +367 -0
- package/src/otlp/types.ts +364 -0
- package/src/redact.ts +116 -0
- package/src/server/__tests__/hono.spec.ts +814 -0
- package/src/server/hono.ts +442 -0
- package/src/storage/__tests__/kysely.spec.ts +715 -0
- package/src/storage/__tests__/memory.spec.ts +694 -0
- package/src/storage/kysely.ts +599 -0
- package/src/storage/memory.ts +204 -0
- package/src/types.ts +447 -0
- package/src/ui-assets.ts +40 -0
- package/tsconfig.json +9 -0
- package/ui/CHANGELOG.md +7 -0
- package/ui/index.html +12 -0
- package/ui/node_modules/.bin/tsc +21 -0
- package/ui/node_modules/.bin/tsserver +21 -0
- package/ui/node_modules/.bin/vite +21 -0
- package/ui/package.json +24 -0
- package/ui/src/App.tsx +595 -0
- package/ui/src/api.ts +88 -0
- package/ui/src/components/ExceptionDetail.tsx +100 -0
- package/ui/src/components/FilterBar.tsx +162 -0
- package/ui/src/components/LogDetail.tsx +91 -0
- package/ui/src/components/RequestDetail.tsx +143 -0
- package/ui/src/main.tsx +10 -0
- package/ui/src/styles.css +11 -0
- package/ui/src/types.ts +63 -0
- package/ui/src/vite-env.d.ts +1 -0
- package/ui/src/vite-plugin-gkm-config.ts +54 -0
- package/ui/tsconfig.json +20 -0
- package/ui/tsconfig.tsbuildinfo +1 -0
- package/ui/vite.config.ts +13 -0
- package/dist/MetricsAggregator-BJdIvfEv.d.mts.map +0 -1
- package/dist/MetricsAggregator-CnC3oT5q.d.cts.map +0 -1
- package/dist/Telescope-BVfDvVvY.d.mts.map +0 -1
- package/dist/Telescope-DeqSHfuB.d.cts.map +0 -1
- package/dist/Telescope.cjs.map +0 -1
- package/dist/Telescope.mjs.map +0 -1
- package/dist/adapters/middy.cjs.map +0 -1
- package/dist/adapters/middy.d.cts.map +0 -1
- package/dist/adapters/middy.d.mts.map +0 -1
- package/dist/adapters/middy.mjs.map +0 -1
- package/dist/adapters/types.d.cts.map +0 -1
- package/dist/adapters/types.d.mts.map +0 -1
- package/dist/instrumentation/core.cjs.map +0 -1
- package/dist/instrumentation/core.d.cts.map +0 -1
- package/dist/instrumentation/core.d.mts.map +0 -1
- package/dist/instrumentation/core.mjs.map +0 -1
- package/dist/instrumentation/hono.cjs.map +0 -1
- package/dist/instrumentation/hono.d.cts.map +0 -1
- package/dist/instrumentation/hono.d.mts.map +0 -1
- package/dist/instrumentation/hono.mjs.map +0 -1
- package/dist/instrumentation/http.cjs.map +0 -1
- package/dist/instrumentation/http.d.cts.map +0 -1
- package/dist/instrumentation/http.d.mts.map +0 -1
- package/dist/instrumentation/http.mjs.map +0 -1
- package/dist/instrumentation/middleware.cjs.map +0 -1
- package/dist/instrumentation/middleware.d.cts.map +0 -1
- package/dist/instrumentation/middleware.d.mts.map +0 -1
- package/dist/instrumentation/middleware.mjs.map +0 -1
- package/dist/instrumentation/otel.cjs.map +0 -1
- package/dist/instrumentation/otel.d.cts.map +0 -1
- package/dist/instrumentation/otel.d.mts.map +0 -1
- package/dist/instrumentation/otel.mjs.map +0 -1
- package/dist/instrumentation/sampler.cjs +0 -54
- package/dist/instrumentation/sampler.cjs.map +0 -1
- package/dist/instrumentation/sampler.d.cts +0 -38
- package/dist/instrumentation/sampler.d.cts.map +0 -1
- package/dist/instrumentation/sampler.d.mts +0 -38
- package/dist/instrumentation/sampler.d.mts.map +0 -1
- package/dist/instrumentation/sampler.mjs +0 -52
- package/dist/instrumentation/sampler.mjs.map +0 -1
- package/dist/instrumentation/setup.cjs.map +0 -1
- package/dist/instrumentation/setup.d.cts.map +0 -1
- package/dist/instrumentation/setup.d.mts.map +0 -1
- package/dist/instrumentation/setup.mjs.map +0 -1
- package/dist/instrumentation/tracing.cjs.map +0 -1
- package/dist/instrumentation/tracing.d.cts.map +0 -1
- package/dist/instrumentation/tracing.d.mts.map +0 -1
- package/dist/instrumentation/tracing.mjs.map +0 -1
- package/dist/instrumentation/trust.cjs +0 -107
- package/dist/instrumentation/trust.cjs.map +0 -1
- package/dist/instrumentation/trust.d.cts +0 -57
- package/dist/instrumentation/trust.d.cts.map +0 -1
- package/dist/instrumentation/trust.d.mts +0 -57
- package/dist/instrumentation/trust.d.mts.map +0 -1
- package/dist/instrumentation/trust.mjs +0 -104
- package/dist/instrumentation/trust.mjs.map +0 -1
- package/dist/metrics/MetricsAggregator.cjs.map +0 -1
- package/dist/metrics/MetricsAggregator.mjs.map +0 -1
- package/dist/metrics/storage/InMemoryMetricsStorage.cjs.map +0 -1
- package/dist/metrics/storage/InMemoryMetricsStorage.d.cts.map +0 -1
- package/dist/metrics/storage/InMemoryMetricsStorage.d.mts.map +0 -1
- package/dist/metrics/storage/InMemoryMetricsStorage.mjs.map +0 -1
- package/dist/metrics/storage/MetricsStorage.d.cts.map +0 -1
- package/dist/metrics/storage/MetricsStorage.d.mts.map +0 -1
- package/dist/metrics/storage/types.cjs.map +0 -1
- package/dist/metrics/storage/types.d.cts.map +0 -1
- package/dist/metrics/storage/types.d.mts.map +0 -1
- package/dist/metrics/storage/types.mjs.map +0 -1
- package/dist/otlp/receiver.cjs.map +0 -1
- package/dist/otlp/receiver.d.cts.map +0 -1
- package/dist/otlp/receiver.d.mts.map +0 -1
- package/dist/otlp/receiver.mjs.map +0 -1
- package/dist/otlp/transformer.cjs.map +0 -1
- package/dist/otlp/transformer.mjs.map +0 -1
- package/dist/otlp/types.cjs.map +0 -1
- package/dist/otlp/types.mjs.map +0 -1
- package/dist/redact.cjs.map +0 -1
- package/dist/redact.mjs.map +0 -1
- package/dist/storage/memory.cjs.map +0 -1
- package/dist/storage/memory.d.cts.map +0 -1
- package/dist/storage/memory.d.mts.map +0 -1
- package/dist/storage/memory.mjs.map +0 -1
- package/dist/transformer-BtqjAs0b.d.cts.map +0 -1
- package/dist/transformer-DI6t8-YA.d.mts.map +0 -1
- package/dist/types-BVujq4zd.d.cts.map +0 -1
- package/dist/types-BVujq4zd.d.mts.map +0 -1
- package/dist/types-DVETVdpa.d.cts.map +0 -1
- package/dist/types-DVETVdpa.d.mts.map +0 -1
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
let _opentelemetry_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
3
|
-
//#region src/instrumentation/sampler.ts
|
|
4
|
-
/**
|
|
5
|
-
* The sampler a service uses at `ratio`: parent-based, with the ratio as a cap
|
|
6
|
-
* on what a remote caller asks for.
|
|
7
|
-
*
|
|
8
|
-
* `parentbased_traceidratio` follows a remote parent's sampled flag as it is.
|
|
9
|
-
* Between services that is how a trace stays whole — but the flag on a
|
|
10
|
-
* request from a browser is the caller's to set, and following it would let
|
|
11
|
-
* any page force 100% tracing on a stage that keeps 10%. So:
|
|
12
|
-
*
|
|
13
|
-
* | parent | decision |
|
|
14
|
-
* |---------------------------|---------------------------------------|
|
|
15
|
-
* | none (a new trace) | the ratio, from the trace id |
|
|
16
|
-
* | remote, sampled | the ratio again: the flag is a request |
|
|
17
|
-
* | remote, not sampled | not sampled: a caller may only ask for less |
|
|
18
|
-
* | local (this process) | the parent's decision |
|
|
19
|
-
*
|
|
20
|
-
* The cap costs a whole trace nothing. `TraceIdRatioBasedSampler` decides from
|
|
21
|
-
* the trace id alone, so every service at the same rate — and the generated
|
|
22
|
-
* API client, which applies the same rule to the page view's trace id — makes
|
|
23
|
-
* the same decision for the same trace: a trace sampled where it started is
|
|
24
|
-
* sampled at every hop.
|
|
25
|
-
*/
|
|
26
|
-
function traceSampler(ratio) {
|
|
27
|
-
const capped = new _opentelemetry_sdk_trace_base.TraceIdRatioBasedSampler(ratio);
|
|
28
|
-
return new _opentelemetry_sdk_trace_base.ParentBasedSampler({
|
|
29
|
-
root: capped,
|
|
30
|
-
remoteParentSampled: capped
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* {@link traceSampler} at the rate the standard variables name, when they ask
|
|
35
|
-
* for `parentbased_traceidratio` — which is what a deploy sets for a stage's
|
|
36
|
-
* sample rate. `OTEL_TRACES_SAMPLER_ARG` is the rate, 1 when absent.
|
|
37
|
-
*
|
|
38
|
-
* Undefined otherwise, and for an argument that is not a rate from 0 to 1:
|
|
39
|
-
* the SDK then reads the variables itself, as it would without this, and
|
|
40
|
-
* reports a bad argument the way it always has — a sampling setting is not a
|
|
41
|
-
* reason for a server not to start.
|
|
42
|
-
*/
|
|
43
|
-
function traceSamplerFromEnv(env = process.env) {
|
|
44
|
-
if (env.OTEL_TRACES_SAMPLER?.trim() !== "parentbased_traceidratio") return;
|
|
45
|
-
const arg = env.OTEL_TRACES_SAMPLER_ARG?.trim();
|
|
46
|
-
const ratio = arg ? Number(arg) : 1;
|
|
47
|
-
if (!Number.isFinite(ratio) || ratio < 0 || ratio > 1) return void 0;
|
|
48
|
-
return traceSampler(ratio);
|
|
49
|
-
}
|
|
50
|
-
//#endregion
|
|
51
|
-
exports.traceSampler = traceSampler;
|
|
52
|
-
exports.traceSamplerFromEnv = traceSamplerFromEnv;
|
|
53
|
-
|
|
54
|
-
//# sourceMappingURL=sampler.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sampler.cjs","names":["TraceIdRatioBasedSampler","ParentBasedSampler"],"sources":["../../src/instrumentation/sampler.ts"],"sourcesContent":["import {\n\tParentBasedSampler,\n\ttype Sampler,\n\tTraceIdRatioBasedSampler,\n} from '@opentelemetry/sdk-trace-base';\n\n/**\n * The sampler a service uses at `ratio`: parent-based, with the ratio as a cap\n * on what a remote caller asks for.\n *\n * `parentbased_traceidratio` follows a remote parent's sampled flag as it is.\n * Between services that is how a trace stays whole — but the flag on a\n * request from a browser is the caller's to set, and following it would let\n * any page force 100% tracing on a stage that keeps 10%. So:\n *\n * | parent | decision |\n * |---------------------------|---------------------------------------|\n * | none (a new trace) | the ratio, from the trace id |\n * | remote, sampled | the ratio again: the flag is a request |\n * | remote, not sampled | not sampled: a caller may only ask for less |\n * | local (this process) | the parent's decision |\n *\n * The cap costs a whole trace nothing. `TraceIdRatioBasedSampler` decides from\n * the trace id alone, so every service at the same rate — and the generated\n * API client, which applies the same rule to the page view's trace id — makes\n * the same decision for the same trace: a trace sampled where it started is\n * sampled at every hop.\n */\nexport function traceSampler(ratio: number): Sampler {\n\tconst capped = new TraceIdRatioBasedSampler(ratio);\n\treturn new ParentBasedSampler({\n\t\troot: capped,\n\t\tremoteParentSampled: capped,\n\t});\n}\n\n/**\n * {@link traceSampler} at the rate the standard variables name, when they ask\n * for `parentbased_traceidratio` — which is what a deploy sets for a stage's\n * sample rate. `OTEL_TRACES_SAMPLER_ARG` is the rate, 1 when absent.\n *\n * Undefined otherwise, and for an argument that is not a rate from 0 to 1:\n * the SDK then reads the variables itself, as it would without this, and\n * reports a bad argument the way it always has — a sampling setting is not a\n * reason for a server not to start.\n */\nexport function traceSamplerFromEnv(\n\tenv: Record<string, string | undefined> = process.env,\n): Sampler | undefined {\n\tif (env.OTEL_TRACES_SAMPLER?.trim() !== 'parentbased_traceidratio') {\n\t\treturn undefined;\n\t}\n\tconst arg = env.OTEL_TRACES_SAMPLER_ARG?.trim();\n\tconst ratio = arg ? Number(arg) : 1;\n\tif (!Number.isFinite(ratio) || ratio < 0 || ratio > 1) return undefined;\n\treturn traceSampler(ratio);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,aAAa,OAAwB;CACpD,MAAM,SAAS,IAAIA,8BAAAA,yBAAyB,KAAK;CACjD,OAAO,IAAIC,8BAAAA,mBAAmB;EAC7B,MAAM;EACN,qBAAqB;CACtB,CAAC;AACF;;;;;;;;;;;AAYA,SAAgB,oBACf,MAA0C,QAAQ,KAC5B;CACtB,IAAI,IAAI,qBAAqB,KAAK,MAAM,4BACvC;CAED,MAAM,MAAM,IAAI,yBAAyB,KAAK;CAC9C,MAAM,QAAQ,MAAM,OAAO,GAAG,IAAI;CAClC,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,QAAQ,KAAK,QAAQ,GAAG,OAAO,KAAA;CAC9D,OAAO,aAAa,KAAK;AAC1B"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Sampler } from "@opentelemetry/sdk-trace-base";
|
|
2
|
-
//#region src/instrumentation/sampler.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* The sampler a service uses at `ratio`: parent-based, with the ratio as a cap
|
|
5
|
-
* on what a remote caller asks for.
|
|
6
|
-
*
|
|
7
|
-
* `parentbased_traceidratio` follows a remote parent's sampled flag as it is.
|
|
8
|
-
* Between services that is how a trace stays whole — but the flag on a
|
|
9
|
-
* request from a browser is the caller's to set, and following it would let
|
|
10
|
-
* any page force 100% tracing on a stage that keeps 10%. So:
|
|
11
|
-
*
|
|
12
|
-
* | parent | decision |
|
|
13
|
-
* |---------------------------|---------------------------------------|
|
|
14
|
-
* | none (a new trace) | the ratio, from the trace id |
|
|
15
|
-
* | remote, sampled | the ratio again: the flag is a request |
|
|
16
|
-
* | remote, not sampled | not sampled: a caller may only ask for less |
|
|
17
|
-
* | local (this process) | the parent's decision |
|
|
18
|
-
*
|
|
19
|
-
* The cap costs a whole trace nothing. `TraceIdRatioBasedSampler` decides from
|
|
20
|
-
* the trace id alone, so every service at the same rate — and the generated
|
|
21
|
-
* API client, which applies the same rule to the page view's trace id — makes
|
|
22
|
-
* the same decision for the same trace: a trace sampled where it started is
|
|
23
|
-
* sampled at every hop.
|
|
24
|
-
*/
|
|
25
|
-
export declare function traceSampler(ratio: number): Sampler;
|
|
26
|
-
/**
|
|
27
|
-
* {@link traceSampler} at the rate the standard variables name, when they ask
|
|
28
|
-
* for `parentbased_traceidratio` — which is what a deploy sets for a stage's
|
|
29
|
-
* sample rate. `OTEL_TRACES_SAMPLER_ARG` is the rate, 1 when absent.
|
|
30
|
-
*
|
|
31
|
-
* Undefined otherwise, and for an argument that is not a rate from 0 to 1:
|
|
32
|
-
* the SDK then reads the variables itself, as it would without this, and
|
|
33
|
-
* reports a bad argument the way it always has — a sampling setting is not a
|
|
34
|
-
* reason for a server not to start.
|
|
35
|
-
*/
|
|
36
|
-
export declare function traceSamplerFromEnv(env?: Record<string, string | undefined>): Sampler | undefined;
|
|
37
|
-
//#endregion
|
|
38
|
-
//# sourceMappingURL=sampler.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sampler.d.cts","names":[],"sources":["../../src/instrumentation/sampler.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;wBA4BgB,aAAa,gBAAgB;;;;;;;;;;;wBAkB7B,oBACf,MAAK,qCACH"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Sampler } from "@opentelemetry/sdk-trace-base";
|
|
2
|
-
//#region src/instrumentation/sampler.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* The sampler a service uses at `ratio`: parent-based, with the ratio as a cap
|
|
5
|
-
* on what a remote caller asks for.
|
|
6
|
-
*
|
|
7
|
-
* `parentbased_traceidratio` follows a remote parent's sampled flag as it is.
|
|
8
|
-
* Between services that is how a trace stays whole — but the flag on a
|
|
9
|
-
* request from a browser is the caller's to set, and following it would let
|
|
10
|
-
* any page force 100% tracing on a stage that keeps 10%. So:
|
|
11
|
-
*
|
|
12
|
-
* | parent | decision |
|
|
13
|
-
* |---------------------------|---------------------------------------|
|
|
14
|
-
* | none (a new trace) | the ratio, from the trace id |
|
|
15
|
-
* | remote, sampled | the ratio again: the flag is a request |
|
|
16
|
-
* | remote, not sampled | not sampled: a caller may only ask for less |
|
|
17
|
-
* | local (this process) | the parent's decision |
|
|
18
|
-
*
|
|
19
|
-
* The cap costs a whole trace nothing. `TraceIdRatioBasedSampler` decides from
|
|
20
|
-
* the trace id alone, so every service at the same rate — and the generated
|
|
21
|
-
* API client, which applies the same rule to the page view's trace id — makes
|
|
22
|
-
* the same decision for the same trace: a trace sampled where it started is
|
|
23
|
-
* sampled at every hop.
|
|
24
|
-
*/
|
|
25
|
-
export declare function traceSampler(ratio: number): Sampler;
|
|
26
|
-
/**
|
|
27
|
-
* {@link traceSampler} at the rate the standard variables name, when they ask
|
|
28
|
-
* for `parentbased_traceidratio` — which is what a deploy sets for a stage's
|
|
29
|
-
* sample rate. `OTEL_TRACES_SAMPLER_ARG` is the rate, 1 when absent.
|
|
30
|
-
*
|
|
31
|
-
* Undefined otherwise, and for an argument that is not a rate from 0 to 1:
|
|
32
|
-
* the SDK then reads the variables itself, as it would without this, and
|
|
33
|
-
* reports a bad argument the way it always has — a sampling setting is not a
|
|
34
|
-
* reason for a server not to start.
|
|
35
|
-
*/
|
|
36
|
-
export declare function traceSamplerFromEnv(env?: Record<string, string | undefined>): Sampler | undefined;
|
|
37
|
-
//#endregion
|
|
38
|
-
//# sourceMappingURL=sampler.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sampler.d.mts","names":[],"sources":["../../src/instrumentation/sampler.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;wBA4BgB,aAAa,gBAAgB;;;;;;;;;;;wBAkB7B,oBACf,MAAK,qCACH"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ParentBasedSampler, TraceIdRatioBasedSampler } from "@opentelemetry/sdk-trace-base";
|
|
2
|
-
//#region src/instrumentation/sampler.ts
|
|
3
|
-
/**
|
|
4
|
-
* The sampler a service uses at `ratio`: parent-based, with the ratio as a cap
|
|
5
|
-
* on what a remote caller asks for.
|
|
6
|
-
*
|
|
7
|
-
* `parentbased_traceidratio` follows a remote parent's sampled flag as it is.
|
|
8
|
-
* Between services that is how a trace stays whole — but the flag on a
|
|
9
|
-
* request from a browser is the caller's to set, and following it would let
|
|
10
|
-
* any page force 100% tracing on a stage that keeps 10%. So:
|
|
11
|
-
*
|
|
12
|
-
* | parent | decision |
|
|
13
|
-
* |---------------------------|---------------------------------------|
|
|
14
|
-
* | none (a new trace) | the ratio, from the trace id |
|
|
15
|
-
* | remote, sampled | the ratio again: the flag is a request |
|
|
16
|
-
* | remote, not sampled | not sampled: a caller may only ask for less |
|
|
17
|
-
* | local (this process) | the parent's decision |
|
|
18
|
-
*
|
|
19
|
-
* The cap costs a whole trace nothing. `TraceIdRatioBasedSampler` decides from
|
|
20
|
-
* the trace id alone, so every service at the same rate — and the generated
|
|
21
|
-
* API client, which applies the same rule to the page view's trace id — makes
|
|
22
|
-
* the same decision for the same trace: a trace sampled where it started is
|
|
23
|
-
* sampled at every hop.
|
|
24
|
-
*/
|
|
25
|
-
function traceSampler(ratio) {
|
|
26
|
-
const capped = new TraceIdRatioBasedSampler(ratio);
|
|
27
|
-
return new ParentBasedSampler({
|
|
28
|
-
root: capped,
|
|
29
|
-
remoteParentSampled: capped
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* {@link traceSampler} at the rate the standard variables name, when they ask
|
|
34
|
-
* for `parentbased_traceidratio` — which is what a deploy sets for a stage's
|
|
35
|
-
* sample rate. `OTEL_TRACES_SAMPLER_ARG` is the rate, 1 when absent.
|
|
36
|
-
*
|
|
37
|
-
* Undefined otherwise, and for an argument that is not a rate from 0 to 1:
|
|
38
|
-
* the SDK then reads the variables itself, as it would without this, and
|
|
39
|
-
* reports a bad argument the way it always has — a sampling setting is not a
|
|
40
|
-
* reason for a server not to start.
|
|
41
|
-
*/
|
|
42
|
-
function traceSamplerFromEnv(env = process.env) {
|
|
43
|
-
if (env.OTEL_TRACES_SAMPLER?.trim() !== "parentbased_traceidratio") return;
|
|
44
|
-
const arg = env.OTEL_TRACES_SAMPLER_ARG?.trim();
|
|
45
|
-
const ratio = arg ? Number(arg) : 1;
|
|
46
|
-
if (!Number.isFinite(ratio) || ratio < 0 || ratio > 1) return void 0;
|
|
47
|
-
return traceSampler(ratio);
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
50
|
-
export { traceSampler, traceSamplerFromEnv };
|
|
51
|
-
|
|
52
|
-
//# sourceMappingURL=sampler.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sampler.mjs","names":[],"sources":["../../src/instrumentation/sampler.ts"],"sourcesContent":["import {\n\tParentBasedSampler,\n\ttype Sampler,\n\tTraceIdRatioBasedSampler,\n} from '@opentelemetry/sdk-trace-base';\n\n/**\n * The sampler a service uses at `ratio`: parent-based, with the ratio as a cap\n * on what a remote caller asks for.\n *\n * `parentbased_traceidratio` follows a remote parent's sampled flag as it is.\n * Between services that is how a trace stays whole — but the flag on a\n * request from a browser is the caller's to set, and following it would let\n * any page force 100% tracing on a stage that keeps 10%. So:\n *\n * | parent | decision |\n * |---------------------------|---------------------------------------|\n * | none (a new trace) | the ratio, from the trace id |\n * | remote, sampled | the ratio again: the flag is a request |\n * | remote, not sampled | not sampled: a caller may only ask for less |\n * | local (this process) | the parent's decision |\n *\n * The cap costs a whole trace nothing. `TraceIdRatioBasedSampler` decides from\n * the trace id alone, so every service at the same rate — and the generated\n * API client, which applies the same rule to the page view's trace id — makes\n * the same decision for the same trace: a trace sampled where it started is\n * sampled at every hop.\n */\nexport function traceSampler(ratio: number): Sampler {\n\tconst capped = new TraceIdRatioBasedSampler(ratio);\n\treturn new ParentBasedSampler({\n\t\troot: capped,\n\t\tremoteParentSampled: capped,\n\t});\n}\n\n/**\n * {@link traceSampler} at the rate the standard variables name, when they ask\n * for `parentbased_traceidratio` — which is what a deploy sets for a stage's\n * sample rate. `OTEL_TRACES_SAMPLER_ARG` is the rate, 1 when absent.\n *\n * Undefined otherwise, and for an argument that is not a rate from 0 to 1:\n * the SDK then reads the variables itself, as it would without this, and\n * reports a bad argument the way it always has — a sampling setting is not a\n * reason for a server not to start.\n */\nexport function traceSamplerFromEnv(\n\tenv: Record<string, string | undefined> = process.env,\n): Sampler | undefined {\n\tif (env.OTEL_TRACES_SAMPLER?.trim() !== 'parentbased_traceidratio') {\n\t\treturn undefined;\n\t}\n\tconst arg = env.OTEL_TRACES_SAMPLER_ARG?.trim();\n\tconst ratio = arg ? Number(arg) : 1;\n\tif (!Number.isFinite(ratio) || ratio < 0 || ratio > 1) return undefined;\n\treturn traceSampler(ratio);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,aAAa,OAAwB;CACpD,MAAM,SAAS,IAAI,yBAAyB,KAAK;CACjD,OAAO,IAAI,mBAAmB;EAC7B,MAAM;EACN,qBAAqB;CACtB,CAAC;AACF;;;;;;;;;;;AAYA,SAAgB,oBACf,MAA0C,QAAQ,KAC5B;CACtB,IAAI,IAAI,qBAAqB,KAAK,MAAM,4BACvC;CAED,MAAM,MAAM,IAAI,yBAAyB,KAAK;CAC9C,MAAM,QAAQ,MAAM,OAAO,GAAG,IAAI;CAClC,IAAI,CAAC,OAAO,SAAS,KAAK,KAAK,QAAQ,KAAK,QAAQ,GAAG,OAAO,KAAA;CAC9D,OAAO,aAAa,KAAK;AAC1B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.cjs","names":["traceSamplerFromEnv","traceSampler","DiagConsoleLogger","DiagLogLevel","resourceFromAttributes","ATTR_SERVICE_NAME","ATTR_SERVICE_VERSION","PinoInstrumentation","getNodeAutoInstrumentations","OTLPTraceExporter","ConsoleSpanExporter","getRecommendedStrategy","createSpanProcessor","OTLPLogExporter","BatchLogRecordProcessor","NodeSDK"],"sources":["../../src/instrumentation/setup.ts"],"sourcesContent":["import { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';\nimport { resourceFromAttributes } from '@opentelemetry/resources';\nimport { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport {\n\tConsoleSpanExporter,\n\ttype Sampler,\n\ttype SpanExporter,\n} from '@opentelemetry/sdk-trace-node';\nimport {\n\tATTR_SERVICE_NAME,\n\tATTR_SERVICE_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport type { SpanProcessorStrategy } from '../adapters/types';\nimport {\n\tcreateSpanProcessor,\n\tgetRecommendedStrategy,\n\tsetGlobalLogProcessor,\n\tsetGlobalSpanProcessor,\n} from './core';\nimport { traceSampler, traceSamplerFromEnv } from './sampler';\n\n/**\n * Options for configuring telemetry\n */\nexport interface TelemetryOptions {\n\t/**\n\t * Service name for resource identification\n\t */\n\tserviceName: string;\n\n\t/**\n\t * Service version\n\t */\n\tserviceVersion?: string;\n\n\t/**\n\t * The `service.namespace` resource attribute — the product an app is part\n\t * of, so several services from one workspace group together.\n\t */\n\tserviceNamespace?: string;\n\n\t/**\n\t * The stage this process runs as (`production`, `staging`, …). Sent as\n\t * `deployment.environment.name`, and as the older `deployment.environment`\n\t * many backends still filter on.\n\t */\n\tdeploymentEnvironment?: string;\n\n\t/**\n\t * OTLP endpoint URL (e.g., 'http://localhost:3000/__telescope/v1').\n\t * Traces go to `<endpoint>/traces` and logs to `<endpoint>/logs`.\n\t *\n\t * If not provided, the standard `OTEL_EXPORTER_OTLP_ENDPOINT` (and its\n\t * per-signal `_TRACES_`/`_LOGS_` variants and `OTEL_EXPORTER_OTLP_HEADERS`)\n\t * configure the exporters, with the spec's `/v1/traces` and `/v1/logs`\n\t * paths. With neither, traces are written to the console.\n\t */\n\tendpoint?: string;\n\n\t/**\n\t * The fraction of new traces to sample, from 0 to 1. A span whose parent\n\t * in this process was sampled (or not) follows its parent, so a trace is\n\t * never cut in half; a caller's sampled flag is capped at this rate, so a\n\t * request cannot force a trace the stage would not keep (`traceSampler`).\n\t *\n\t * When left out, the standard `OTEL_TRACES_SAMPLER` and\n\t * `OTEL_TRACES_SAMPLER_ARG` decide — `parentbased_traceidratio` with `0.1`\n\t * is the same capped sampler at 0.1; with neither, every trace is sampled.\n\t */\n\tsampleRatio?: number;\n\n\t/**\n\t * Shut the SDK down and exit on `SIGTERM`.\n\t *\n\t * Turn it off when the process has its own graceful shutdown — exiting as\n\t * soon as telemetry is flushed would cut in-flight requests short.\n\t * @default true\n\t */\n\thandleSignals?: boolean;\n\n\t/**\n\t * Whether to instrument Pino for log correlation.\n\t *\n\t * It hooks module loading, so it sees nothing inside a bundle. A logger\n\t * from `@geekmidas/logger`'s `createLogger` sends its records through the\n\t * logs API itself; turn this off for one, or each record is sent twice\n\t * where pino can be hooked.\n\t * @default true\n\t */\n\tinstrumentPino?: boolean;\n\n\t/**\n\t * Whether the http auto-instrumentation opens a span for each incoming\n\t * request.\n\t *\n\t * Turn it off when the server opens its own — `honoTelemetryMiddleware`,\n\t * as a `gkm build` server does — or each request is traced twice where\n\t * `node:http` can be hooked, and not at all in a bundle, where it cannot.\n\t * Outgoing requests are traced either way.\n\t * @default true\n\t */\n\tincomingHttpSpans?: boolean;\n\n\t/**\n\t * Whether to enable auto-instrumentation for common libraries\n\t * (http, fetch, express, etc.)\n\t * @default true\n\t */\n\tautoInstrument?: boolean;\n\n\t/**\n\t * Enable debug logging for OTel SDK\n\t * @default false\n\t */\n\tdebug?: boolean;\n\n\t/**\n\t * Additional resource attributes\n\t */\n\tresourceAttributes?: Record<string, string>;\n\n\t/**\n\t * Headers to send with OTLP requests\n\t */\n\theaders?: Record<string, string>;\n\n\t/**\n\t * Span processor strategy.\n\t * - 'batch': Efficient batching for long-running servers (default)\n\t * - 'simple': Immediate export for serverless environments (Lambda, Edge)\n\t *\n\t * If not specified, automatically selected based on environment detection.\n\t */\n\tspanProcessorStrategy?: SpanProcessorStrategy;\n\n\t/**\n\t * Environment type for automatic configuration\n\t * @default 'server'\n\t */\n\tenvironment?: 'server' | 'lambda' | 'edge' | 'custom';\n}\n\nlet sdk: NodeSDK | null = null;\nlet onSigterm: (() => void) | null = null;\n\n/** A `sampleRatio` outside 0–1, which no sampler can honour. */\nexport class InvalidSampleRatio extends Error {\n\tconstructor(readonly sampleRatio: number) {\n\t\tsuper(\n\t\t\t`sampleRatio must be a number from 0 (no traces) to 1 (every trace), got ${sampleRatio}. Pass a fraction such as 0.1 to keep one trace in ten.`,\n\t\t);\n\t\tthis.name = 'InvalidSampleRatio';\n\t}\n}\n\n/** Whether the standard OTLP environment variables name a collector. */\nfunction otlpEndpointFromEnv(signal: 'TRACES' | 'LOGS'): boolean {\n\treturn Boolean(\n\t\tprocess.env[`OTEL_EXPORTER_OTLP_${signal}_ENDPOINT`] ||\n\t\t\tprocess.env.OTEL_EXPORTER_OTLP_ENDPOINT,\n\t);\n}\n\n/**\n * The sampler for an explicit ratio, or for the stage's rate in\n * `OTEL_TRACES_SAMPLER_ARG` — or undefined to let the SDK read any other\n * `OTEL_TRACES_SAMPLER` itself.\n */\nfunction samplerFor(sampleRatio: number | undefined): Sampler | undefined {\n\tif (sampleRatio === undefined) return traceSamplerFromEnv();\n\tif (!Number.isFinite(sampleRatio) || sampleRatio < 0 || sampleRatio > 1) {\n\t\tthrow new InvalidSampleRatio(sampleRatio);\n\t}\n\treturn traceSampler(sampleRatio);\n}\n\n/**\n * Set up OpenTelemetry instrumentation.\n * Call this BEFORE importing your application code.\n *\n * @example\n * ```typescript\n * // instrumentation.ts (create this file)\n * import { setupTelemetry } from '@geekmidas/telescope/instrumentation';\n *\n * setupTelemetry({\n * serviceName: 'my-api',\n * endpoint: 'http://localhost:3000/__telescope/v1',\n * });\n *\n * // Then in your entry point:\n * // import './instrumentation';\n * // import { app } from './app';\n * ```\n */\nexport function setupTelemetry(options: TelemetryOptions): void {\n\tif (sdk) {\n\t\treturn;\n\t}\n\n\tconst {\n\t\tserviceName,\n\t\tserviceVersion = '1.0.0',\n\t\tserviceNamespace,\n\t\tdeploymentEnvironment,\n\t\tendpoint,\n\t\tsampleRatio,\n\t\thandleSignals = true,\n\t\tinstrumentPino = true,\n\t\tincomingHttpSpans = true,\n\t\tautoInstrument = true,\n\t\tdebug = false,\n\t\tresourceAttributes = {},\n\t\theaders,\n\t\tspanProcessorStrategy,\n\t\tenvironment = 'server',\n\t} = options;\n\n\t// Before anything starts, so a bad ratio leaves nothing half set up.\n\tconst sampler = samplerFor(sampleRatio);\n\n\t// Enable debug logging if requested\n\tif (debug) {\n\t\tdiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);\n\t}\n\n\t// Create resource\n\t// `new Resource(...)` went in resources 2.x — a resource is now made from\n\t// attributes by a function, so a detector and a literal produce the same\n\t// thing rather than two shapes that had to be merged.\n\t//\n\t// The SDK merges what `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME`\n\t// say over this, so an operator can still rename or relabel a service.\n\tconst resource = resourceFromAttributes({\n\t\t[ATTR_SERVICE_NAME]: serviceName,\n\t\t[ATTR_SERVICE_VERSION]: serviceVersion,\n\t\t...(serviceNamespace && { 'service.namespace': serviceNamespace }),\n\t\t...(deploymentEnvironment && {\n\t\t\t'deployment.environment.name': deploymentEnvironment,\n\t\t\t'deployment.environment': deploymentEnvironment,\n\t\t}),\n\t\t...resourceAttributes,\n\t});\n\n\t// Build instrumentations list\n\tconst instrumentations = [];\n\n\t// Add Pino instrumentation for log correlation\n\tif (instrumentPino) {\n\t\tinstrumentations.push(\n\t\t\tnew PinoInstrumentation({\n\t\t\t\t// Inject trace context into log records\n\t\t\t\tlogHook: (span, record) => {\n\t\t\t\t\trecord.trace_id = span.spanContext().traceId;\n\t\t\t\t\trecord.span_id = span.spanContext().spanId;\n\t\t\t\t\trecord.trace_flags = span.spanContext().traceFlags;\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Add auto-instrumentations for common libraries\n\tif (autoInstrument) {\n\t\tinstrumentations.push(\n\t\t\tgetNodeAutoInstrumentations({\n\t\t\t\t// Disable file system instrumentation (too noisy)\n\t\t\t\t'@opentelemetry/instrumentation-fs': { enabled: false },\n\t\t\t\t// Configure HTTP instrumentation\n\t\t\t\t'@opentelemetry/instrumentation-http': {\n\t\t\t\t\tdisableIncomingRequestInstrumentation: !incomingHttpSpans,\n\t\t\t\t\tignoreIncomingRequestHook: (request) => {\n\t\t\t\t\t\t// Ignore health checks and internal routes\n\t\t\t\t\t\tconst path = request.url || '';\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tpath.includes('/__health') ||\n\t\t\t\t\t\t\tpath.includes('/__telescope') ||\n\t\t\t\t\t\t\tpath.includes('/favicon')\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Create exporters\n\tlet traceExporter: SpanExporter;\n\tif (endpoint) {\n\t\ttraceExporter = new OTLPTraceExporter({\n\t\t\turl: `${endpoint}/traces`,\n\t\t\theaders: headers ?? {},\n\t\t});\n\t} else if (otlpEndpointFromEnv('TRACES')) {\n\t\t// No URL: the exporter reads the OTLP variables itself, the way any\n\t\t// other OpenTelemetry SDK would.\n\t\ttraceExporter = new OTLPTraceExporter(headers ? { headers } : {});\n\t} else {\n\t\t// Fall back to console exporter for debugging\n\t\ttraceExporter = new ConsoleSpanExporter();\n\t}\n\n\t// Determine span processor strategy\n\tconst strategy = spanProcessorStrategy ?? getRecommendedStrategy(environment);\n\tconst spanProcessor = createSpanProcessor(traceExporter, { strategy });\n\n\t// Register globally for flush operations\n\tsetGlobalSpanProcessor(spanProcessor);\n\n\t// Set up log exporter if a collector is named\n\tlet logProcessor: BatchLogRecordProcessor | undefined;\n\tif (endpoint || otlpEndpointFromEnv('LOGS')) {\n\t\tconst logExporter = endpoint\n\t\t\t? new OTLPLogExporter({\n\t\t\t\t\turl: `${endpoint}/logs`,\n\t\t\t\t\theaders: headers ?? {},\n\t\t\t\t})\n\t\t\t: new OTLPLogExporter(headers ? { headers } : {});\n\n\t\t// sdk-logs 2.x: processors are constructor-only and the exporter is\n\t\t// named rather than positional.\n\t\tlogProcessor = new BatchLogRecordProcessor({ exporter: logExporter });\n\n\t\t// Register for flush operations\n\t\tsetGlobalLogProcessor(logProcessor);\n\t}\n\n\t// Create and configure SDK. The SDK owns the logger provider, so the log\n\t// processor is handed to it rather than to a provider of our own — one\n\t// nothing registered would never receive a record.\n\tsdk = new NodeSDK({\n\t\tresource,\n\t\ttraceExporter,\n\t\tspanProcessors: [spanProcessor],\n\t\t...(logProcessor && { logRecordProcessors: [logProcessor] }),\n\t\t...(sampler && { sampler }),\n\t\tinstrumentations,\n\t});\n\n\t// Start the SDK\n\tsdk.start();\n\n\tif (handleSignals) {\n\t\t// Graceful shutdown\n\t\tonSigterm = () => {\n\t\t\tsdk\n\t\t\t\t?.shutdown()\n\t\t\t\t.then(() => {})\n\t\t\t\t.catch((_error) => {})\n\t\t\t\t.finally(() => process.exit(0));\n\t\t};\n\t\tprocess.on('SIGTERM', onSigterm);\n\t}\n}\n\n/**\n * Shut down telemetry (for testing or graceful shutdown)\n */\nexport async function shutdownTelemetry(): Promise<void> {\n\tif (onSigterm) {\n\t\tprocess.off('SIGTERM', onSigterm);\n\t\tonSigterm = null;\n\t}\n\tif (sdk) {\n\t\tawait sdk.shutdown();\n\t\tsdk = null;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AAmJA,IAAI,MAAsB;AAC1B,IAAI,YAAiC;;AAGrC,IAAa,qBAAb,cAAwC,MAAM;CACxB;CAArB,YAAY,aAA8B;EACzC,MACC,2EAA2E,YAAY,wDACxF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;GACjB,KACG,SAAS,CAAC,CACX,WAAW,CAAC,CAAC,CAAC,CACd,OAAO,WAAW,CAAC,CAAC,CAAC,CACrB,cAAc,QAAQ,KAAK,CAAC,CAAC;EAChC;EACA,QAAQ,GAAG,WAAW,SAAS;CAChC;AACD;;;;AAKA,eAAsB,oBAAmC;CACxD,IAAI,WAAW;EACd,QAAQ,IAAI,WAAW,SAAS;EAChC,YAAY;CACb;CACA,IAAI,KAAK;EACR,MAAM,IAAI,SAAS;EACnB,MAAM;CACP;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.cts","names":[],"sources":["../../src/instrumentation/setup.ts"],"mappings":";;;;;iBA6BiB;;;;EAIhB;;;;EAKA;;;;;EAMA;;;;;;EAOA;;;;;;;;;;EAWA;;;;;;;;;;;EAYA;;;;;;;;EASA;;;;;;;;;;EAWA;;;;;;;;;;;EAYA;;;;;;EAOA;;;;;EAMA;;;;EAKA,qBAAqB;;;;EAKrB,UAAU;;;;;;;;EASV,wBAAwB;;;;;EAMxB;;;qBAOY,2BAA2B;WAClB;EAArB,YAAqB;;;;;;;;;;;;;;;;;;;;;wBAgDN,eAAe,SAAS;;;;wBAiKlB,qBAAqB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.mts","names":[],"sources":["../../src/instrumentation/setup.ts"],"mappings":";;;;;iBA6BiB;;;;EAIhB;;;;EAKA;;;;;EAMA;;;;;;EAOA;;;;;;;;;;EAWA;;;;;;;;;;;EAYA;;;;;;;;EASA;;;;;;;;;;EAWA;;;;;;;;;;;EAYA;;;;;;EAOA;;;;;EAMA;;;;EAKA,qBAAqB;;;;EAKrB,UAAU;;;;;;;;EASV,wBAAwB;;;;;EAMxB;;;qBAOY,2BAA2B;WAClB;EAArB,YAAqB;;;;;;;;;;;;;;;;;;;;;wBAgDN,eAAe,SAAS;;;;wBAiKlB,qBAAqB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.mjs","names":[],"sources":["../../src/instrumentation/setup.ts"],"sourcesContent":["import { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api';\nimport { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';\nimport { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';\nimport { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\nimport { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';\nimport { resourceFromAttributes } from '@opentelemetry/resources';\nimport { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { NodeSDK } from '@opentelemetry/sdk-node';\nimport {\n\tConsoleSpanExporter,\n\ttype Sampler,\n\ttype SpanExporter,\n} from '@opentelemetry/sdk-trace-node';\nimport {\n\tATTR_SERVICE_NAME,\n\tATTR_SERVICE_VERSION,\n} from '@opentelemetry/semantic-conventions';\nimport type { SpanProcessorStrategy } from '../adapters/types';\nimport {\n\tcreateSpanProcessor,\n\tgetRecommendedStrategy,\n\tsetGlobalLogProcessor,\n\tsetGlobalSpanProcessor,\n} from './core';\nimport { traceSampler, traceSamplerFromEnv } from './sampler';\n\n/**\n * Options for configuring telemetry\n */\nexport interface TelemetryOptions {\n\t/**\n\t * Service name for resource identification\n\t */\n\tserviceName: string;\n\n\t/**\n\t * Service version\n\t */\n\tserviceVersion?: string;\n\n\t/**\n\t * The `service.namespace` resource attribute — the product an app is part\n\t * of, so several services from one workspace group together.\n\t */\n\tserviceNamespace?: string;\n\n\t/**\n\t * The stage this process runs as (`production`, `staging`, …). Sent as\n\t * `deployment.environment.name`, and as the older `deployment.environment`\n\t * many backends still filter on.\n\t */\n\tdeploymentEnvironment?: string;\n\n\t/**\n\t * OTLP endpoint URL (e.g., 'http://localhost:3000/__telescope/v1').\n\t * Traces go to `<endpoint>/traces` and logs to `<endpoint>/logs`.\n\t *\n\t * If not provided, the standard `OTEL_EXPORTER_OTLP_ENDPOINT` (and its\n\t * per-signal `_TRACES_`/`_LOGS_` variants and `OTEL_EXPORTER_OTLP_HEADERS`)\n\t * configure the exporters, with the spec's `/v1/traces` and `/v1/logs`\n\t * paths. With neither, traces are written to the console.\n\t */\n\tendpoint?: string;\n\n\t/**\n\t * The fraction of new traces to sample, from 0 to 1. A span whose parent\n\t * in this process was sampled (or not) follows its parent, so a trace is\n\t * never cut in half; a caller's sampled flag is capped at this rate, so a\n\t * request cannot force a trace the stage would not keep (`traceSampler`).\n\t *\n\t * When left out, the standard `OTEL_TRACES_SAMPLER` and\n\t * `OTEL_TRACES_SAMPLER_ARG` decide — `parentbased_traceidratio` with `0.1`\n\t * is the same capped sampler at 0.1; with neither, every trace is sampled.\n\t */\n\tsampleRatio?: number;\n\n\t/**\n\t * Shut the SDK down and exit on `SIGTERM`.\n\t *\n\t * Turn it off when the process has its own graceful shutdown — exiting as\n\t * soon as telemetry is flushed would cut in-flight requests short.\n\t * @default true\n\t */\n\thandleSignals?: boolean;\n\n\t/**\n\t * Whether to instrument Pino for log correlation.\n\t *\n\t * It hooks module loading, so it sees nothing inside a bundle. A logger\n\t * from `@geekmidas/logger`'s `createLogger` sends its records through the\n\t * logs API itself; turn this off for one, or each record is sent twice\n\t * where pino can be hooked.\n\t * @default true\n\t */\n\tinstrumentPino?: boolean;\n\n\t/**\n\t * Whether the http auto-instrumentation opens a span for each incoming\n\t * request.\n\t *\n\t * Turn it off when the server opens its own — `honoTelemetryMiddleware`,\n\t * as a `gkm build` server does — or each request is traced twice where\n\t * `node:http` can be hooked, and not at all in a bundle, where it cannot.\n\t * Outgoing requests are traced either way.\n\t * @default true\n\t */\n\tincomingHttpSpans?: boolean;\n\n\t/**\n\t * Whether to enable auto-instrumentation for common libraries\n\t * (http, fetch, express, etc.)\n\t * @default true\n\t */\n\tautoInstrument?: boolean;\n\n\t/**\n\t * Enable debug logging for OTel SDK\n\t * @default false\n\t */\n\tdebug?: boolean;\n\n\t/**\n\t * Additional resource attributes\n\t */\n\tresourceAttributes?: Record<string, string>;\n\n\t/**\n\t * Headers to send with OTLP requests\n\t */\n\theaders?: Record<string, string>;\n\n\t/**\n\t * Span processor strategy.\n\t * - 'batch': Efficient batching for long-running servers (default)\n\t * - 'simple': Immediate export for serverless environments (Lambda, Edge)\n\t *\n\t * If not specified, automatically selected based on environment detection.\n\t */\n\tspanProcessorStrategy?: SpanProcessorStrategy;\n\n\t/**\n\t * Environment type for automatic configuration\n\t * @default 'server'\n\t */\n\tenvironment?: 'server' | 'lambda' | 'edge' | 'custom';\n}\n\nlet sdk: NodeSDK | null = null;\nlet onSigterm: (() => void) | null = null;\n\n/** A `sampleRatio` outside 0–1, which no sampler can honour. */\nexport class InvalidSampleRatio extends Error {\n\tconstructor(readonly sampleRatio: number) {\n\t\tsuper(\n\t\t\t`sampleRatio must be a number from 0 (no traces) to 1 (every trace), got ${sampleRatio}. Pass a fraction such as 0.1 to keep one trace in ten.`,\n\t\t);\n\t\tthis.name = 'InvalidSampleRatio';\n\t}\n}\n\n/** Whether the standard OTLP environment variables name a collector. */\nfunction otlpEndpointFromEnv(signal: 'TRACES' | 'LOGS'): boolean {\n\treturn Boolean(\n\t\tprocess.env[`OTEL_EXPORTER_OTLP_${signal}_ENDPOINT`] ||\n\t\t\tprocess.env.OTEL_EXPORTER_OTLP_ENDPOINT,\n\t);\n}\n\n/**\n * The sampler for an explicit ratio, or for the stage's rate in\n * `OTEL_TRACES_SAMPLER_ARG` — or undefined to let the SDK read any other\n * `OTEL_TRACES_SAMPLER` itself.\n */\nfunction samplerFor(sampleRatio: number | undefined): Sampler | undefined {\n\tif (sampleRatio === undefined) return traceSamplerFromEnv();\n\tif (!Number.isFinite(sampleRatio) || sampleRatio < 0 || sampleRatio > 1) {\n\t\tthrow new InvalidSampleRatio(sampleRatio);\n\t}\n\treturn traceSampler(sampleRatio);\n}\n\n/**\n * Set up OpenTelemetry instrumentation.\n * Call this BEFORE importing your application code.\n *\n * @example\n * ```typescript\n * // instrumentation.ts (create this file)\n * import { setupTelemetry } from '@geekmidas/telescope/instrumentation';\n *\n * setupTelemetry({\n * serviceName: 'my-api',\n * endpoint: 'http://localhost:3000/__telescope/v1',\n * });\n *\n * // Then in your entry point:\n * // import './instrumentation';\n * // import { app } from './app';\n * ```\n */\nexport function setupTelemetry(options: TelemetryOptions): void {\n\tif (sdk) {\n\t\treturn;\n\t}\n\n\tconst {\n\t\tserviceName,\n\t\tserviceVersion = '1.0.0',\n\t\tserviceNamespace,\n\t\tdeploymentEnvironment,\n\t\tendpoint,\n\t\tsampleRatio,\n\t\thandleSignals = true,\n\t\tinstrumentPino = true,\n\t\tincomingHttpSpans = true,\n\t\tautoInstrument = true,\n\t\tdebug = false,\n\t\tresourceAttributes = {},\n\t\theaders,\n\t\tspanProcessorStrategy,\n\t\tenvironment = 'server',\n\t} = options;\n\n\t// Before anything starts, so a bad ratio leaves nothing half set up.\n\tconst sampler = samplerFor(sampleRatio);\n\n\t// Enable debug logging if requested\n\tif (debug) {\n\t\tdiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);\n\t}\n\n\t// Create resource\n\t// `new Resource(...)` went in resources 2.x — a resource is now made from\n\t// attributes by a function, so a detector and a literal produce the same\n\t// thing rather than two shapes that had to be merged.\n\t//\n\t// The SDK merges what `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME`\n\t// say over this, so an operator can still rename or relabel a service.\n\tconst resource = resourceFromAttributes({\n\t\t[ATTR_SERVICE_NAME]: serviceName,\n\t\t[ATTR_SERVICE_VERSION]: serviceVersion,\n\t\t...(serviceNamespace && { 'service.namespace': serviceNamespace }),\n\t\t...(deploymentEnvironment && {\n\t\t\t'deployment.environment.name': deploymentEnvironment,\n\t\t\t'deployment.environment': deploymentEnvironment,\n\t\t}),\n\t\t...resourceAttributes,\n\t});\n\n\t// Build instrumentations list\n\tconst instrumentations = [];\n\n\t// Add Pino instrumentation for log correlation\n\tif (instrumentPino) {\n\t\tinstrumentations.push(\n\t\t\tnew PinoInstrumentation({\n\t\t\t\t// Inject trace context into log records\n\t\t\t\tlogHook: (span, record) => {\n\t\t\t\t\trecord.trace_id = span.spanContext().traceId;\n\t\t\t\t\trecord.span_id = span.spanContext().spanId;\n\t\t\t\t\trecord.trace_flags = span.spanContext().traceFlags;\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Add auto-instrumentations for common libraries\n\tif (autoInstrument) {\n\t\tinstrumentations.push(\n\t\t\tgetNodeAutoInstrumentations({\n\t\t\t\t// Disable file system instrumentation (too noisy)\n\t\t\t\t'@opentelemetry/instrumentation-fs': { enabled: false },\n\t\t\t\t// Configure HTTP instrumentation\n\t\t\t\t'@opentelemetry/instrumentation-http': {\n\t\t\t\t\tdisableIncomingRequestInstrumentation: !incomingHttpSpans,\n\t\t\t\t\tignoreIncomingRequestHook: (request) => {\n\t\t\t\t\t\t// Ignore health checks and internal routes\n\t\t\t\t\t\tconst path = request.url || '';\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tpath.includes('/__health') ||\n\t\t\t\t\t\t\tpath.includes('/__telescope') ||\n\t\t\t\t\t\t\tpath.includes('/favicon')\n\t\t\t\t\t\t);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n\t}\n\n\t// Create exporters\n\tlet traceExporter: SpanExporter;\n\tif (endpoint) {\n\t\ttraceExporter = new OTLPTraceExporter({\n\t\t\turl: `${endpoint}/traces`,\n\t\t\theaders: headers ?? {},\n\t\t});\n\t} else if (otlpEndpointFromEnv('TRACES')) {\n\t\t// No URL: the exporter reads the OTLP variables itself, the way any\n\t\t// other OpenTelemetry SDK would.\n\t\ttraceExporter = new OTLPTraceExporter(headers ? { headers } : {});\n\t} else {\n\t\t// Fall back to console exporter for debugging\n\t\ttraceExporter = new ConsoleSpanExporter();\n\t}\n\n\t// Determine span processor strategy\n\tconst strategy = spanProcessorStrategy ?? getRecommendedStrategy(environment);\n\tconst spanProcessor = createSpanProcessor(traceExporter, { strategy });\n\n\t// Register globally for flush operations\n\tsetGlobalSpanProcessor(spanProcessor);\n\n\t// Set up log exporter if a collector is named\n\tlet logProcessor: BatchLogRecordProcessor | undefined;\n\tif (endpoint || otlpEndpointFromEnv('LOGS')) {\n\t\tconst logExporter = endpoint\n\t\t\t? new OTLPLogExporter({\n\t\t\t\t\turl: `${endpoint}/logs`,\n\t\t\t\t\theaders: headers ?? {},\n\t\t\t\t})\n\t\t\t: new OTLPLogExporter(headers ? { headers } : {});\n\n\t\t// sdk-logs 2.x: processors are constructor-only and the exporter is\n\t\t// named rather than positional.\n\t\tlogProcessor = new BatchLogRecordProcessor({ exporter: logExporter });\n\n\t\t// Register for flush operations\n\t\tsetGlobalLogProcessor(logProcessor);\n\t}\n\n\t// Create and configure SDK. The SDK owns the logger provider, so the log\n\t// processor is handed to it rather than to a provider of our own — one\n\t// nothing registered would never receive a record.\n\tsdk = new NodeSDK({\n\t\tresource,\n\t\ttraceExporter,\n\t\tspanProcessors: [spanProcessor],\n\t\t...(logProcessor && { logRecordProcessors: [logProcessor] }),\n\t\t...(sampler && { sampler }),\n\t\tinstrumentations,\n\t});\n\n\t// Start the SDK\n\tsdk.start();\n\n\tif (handleSignals) {\n\t\t// Graceful shutdown\n\t\tonSigterm = () => {\n\t\t\tsdk\n\t\t\t\t?.shutdown()\n\t\t\t\t.then(() => {})\n\t\t\t\t.catch((_error) => {})\n\t\t\t\t.finally(() => process.exit(0));\n\t\t};\n\t\tprocess.on('SIGTERM', onSigterm);\n\t}\n}\n\n/**\n * Shut down telemetry (for testing or graceful shutdown)\n */\nexport async function shutdownTelemetry(): Promise<void> {\n\tif (onSigterm) {\n\t\tprocess.off('SIGTERM', onSigterm);\n\t\tonSigterm = null;\n\t}\n\tif (sdk) {\n\t\tawait sdk.shutdown();\n\t\tsdk = null;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AAmJA,IAAI,MAAsB;AAC1B,IAAI,YAAiC;;AAGrC,IAAa,qBAAb,cAAwC,MAAM;CACxB;CAArB,YAAY,aAA8B;EACzC,MAC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ACxD,IAAI,WAAW;EACd,QAAQ,IAAI,WAAW,SAAS;EAChC,YAAY;CACb;CACA,IAAI,KAAK;EACR,MAAM,IAAI,SAAS;EACnB,MAAM;CACP;AACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.cjs","names":["trace","context","SpanStatusCode"],"sources":["../../src/instrumentation/tracing.ts"],"sourcesContent":["import {\n\ttype Attributes,\n\tcontext,\n\ttype Span,\n\tSpanStatusCode,\n\ttrace,\n} from '@opentelemetry/api';\n\n/**\n * Get the currently active span\n */\nexport function getActiveSpan(): Span | undefined {\n\treturn trace.getActiveSpan();\n}\n\n/**\n * Set attributes on the active span\n */\nexport function setSpanAttributes(attributes: Attributes): void {\n\tconst span = getActiveSpan();\n\tif (span) {\n\t\tspan.setAttributes(attributes);\n\t}\n}\n\n/**\n * Create a new span as a child of the current span\n */\nexport function createSpan(name: string, attributes?: Attributes): Span {\n\tconst tracer = trace.getTracer('@geekmidas/telescope');\n\tconst span = tracer.startSpan(name, { attributes });\n\treturn span;\n}\n\n/**\n * Execute a function within a new span context\n *\n * @example\n * ```typescript\n * const result = await withSpan('processOrder', async (span) => {\n * span.setAttribute('order.id', orderId);\n * const order = await processOrder(orderId);\n * return order;\n * });\n * ```\n */\nexport async function withSpan<T>(\n\tname: string,\n\tfn: (span: Span) => Promise<T>,\n\tattributes?: Attributes,\n): Promise<T> {\n\tconst tracer = trace.getTracer('@geekmidas/telescope');\n\tconst span = tracer.startSpan(name, { attributes });\n\n\ttry {\n\t\tconst result = await context.with(\n\t\t\ttrace.setSpan(context.active(), span),\n\t\t\t() => fn(span),\n\t\t);\n\t\tspan.setStatus({ code: SpanStatusCode.OK });\n\t\treturn result;\n\t} catch (error) {\n\t\tspan.setStatus({\n\t\t\tcode: SpanStatusCode.ERROR,\n\t\t\tmessage: error instanceof Error ? error.message : 'Unknown error',\n\t\t});\n\t\tspan.recordException(\n\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t);\n\t\tthrow error;\n\t} finally {\n\t\tspan.end();\n\t}\n}\n\n/**\n * Synchronous version of withSpan\n */\nexport function withSpanSync<T>(\n\tname: string,\n\tfn: (span: Span) => T,\n\tattributes?: Attributes,\n): T {\n\tconst tracer = trace.getTracer('@geekmidas/telescope');\n\tconst span = tracer.startSpan(name, { attributes });\n\n\ttry {\n\t\tconst result = context.with(trace.setSpan(context.active(), span), () =>\n\t\t\tfn(span),\n\t\t);\n\t\tspan.setStatus({ code: SpanStatusCode.OK });\n\t\treturn result;\n\t} catch (error) {\n\t\tspan.setStatus({\n\t\t\tcode: SpanStatusCode.ERROR,\n\t\t\tmessage: error instanceof Error ? error.message : 'Unknown error',\n\t\t});\n\t\tspan.recordException(\n\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t);\n\t\tthrow error;\n\t} finally {\n\t\tspan.end();\n\t}\n}\n\n/**\n * Get the current trace ID (useful for log correlation)\n */\nexport function getTraceId(): string | undefined {\n\tconst span = getActiveSpan();\n\treturn span?.spanContext().traceId;\n}\n\n/**\n * Get the current span ID\n */\nexport function getSpanId(): string | undefined {\n\tconst span = getActiveSpan();\n\treturn span?.spanContext().spanId;\n}\n\n/**\n * Record an exception on the current span\n */\nexport function recordException(error: Error): void {\n\tconst span = getActiveSpan();\n\tif (span) {\n\t\tspan.recordException(error);\n\t\tspan.setStatus({\n\t\t\tcode: SpanStatusCode.ERROR,\n\t\t\tmessage: error.message,\n\t\t});\n\t}\n}\n\n/**\n * Add an event to the current span\n */\nexport function addSpanEvent(name: string, attributes?: Attributes): void {\n\tconst span = getActiveSpan();\n\tif (span) {\n\t\tspan.addEvent(name, attributes);\n\t}\n}\n"],"mappings":";;;;;;AAWA,SAAgB,gBAAkC;CACjD,OAAOA,mBAAAA,MAAM,cAAc;AAC5B;;;;AAKA,SAAgB,kBAAkB,YAA8B;CAC/D,MAAM,OAAO,cAAc;CAC3B,IAAI,MACH,KAAK,cAAc,UAAU;AAE/B;;;;AAKA,SAAgB,WAAW,MA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CACV;AACD;;;;AAKA,SAAgB,aAAiC;CAEhD,OADa,cACH,CAAC,EAAE,YAAY,CAAC,CAAC;AAC5B;;;;AAKA,SAAgB,YAAgC;CAE/C,OADa,cACH,CAAC,EAAE,YAAY,CAAC,CAAC;AAC5B;;;;AAKA,SAAgB,gBAAgB,OAAoB;CACnD,MAAM,OAAO,cAAc;CAC3B,IAAI,MAAM;EACT,KAAK,gBAAgB,KAAK;EAC1B,KAAK,UAAU;GACd,MAAMA,mBAAAA,eAAe;GACrB,SAAS,MAAM;EAChB,CAAC;CACF;AACD;;;;AAKA,SAAgB,aAAa,MAAc,YAA+B;CACzE,MAAM,OAAO,cAAc;CAC3B,IAAI,MACH,KAAK,SAAS,MAAM,UAAU;AAEhC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.d.cts","names":[],"sources":["../../src/instrumentation/tracing.ts"],"mappings":";;;;;wBAWgB,iBAAiB;;;;wBAOjB,kBAAkB,YAAY;;;;wBAU9B,WAAW,cAAc,aAAa,aAAa;;;;;;;;;;;;;wBAkB7C,SAAS,GAC9B,cACA,KAAK,MAAM,SAAS,QAAQ,IAC5B,aAAa,aACX,QAAQ;;;;wBA4BK,aAAa,GAC5B,cACA,KAAK,MAAM,SAAS,GACpB,aAAa,aACX;;;;wBA2Ba;;;;wBAQA;;;;wBAQA,gBAAgB,OAAO;;;;wBAcvB,aAAa,cAAc,aAAa"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.d.mts","names":[],"sources":["../../src/instrumentation/tracing.ts"],"mappings":";;;;;wBAWgB,iBAAiB;;;;wBAOjB,kBAAkB,YAAY;;;;wBAU9B,WAAW,cAAc,aAAa,aAAa;;;;;;;;;;;;;wBAkB7C,SAAS,GAC9B,cACA,KAAK,MAAM,SAAS,QAAQ,IAC5B,aAAa,aACX,QAAQ;;;;wBA4BK,aAAa,GAC5B,cACA,KAAK,MAAM,SAAS,GACpB,aAAa,aACX;;;;wBA2Ba;;;;wBAQA;;;;wBAQA,gBAAgB,OAAO;;;;wBAcvB,aAAa,cAAc,aAAa"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.mjs","names":[],"sources":["../../src/instrumentation/tracing.ts"],"sourcesContent":["import {\n\ttype Attributes,\n\tcontext,\n\ttype Span,\n\tSpanStatusCode,\n\ttrace,\n} from '@opentelemetry/api';\n\n/**\n * Get the currently active span\n */\nexport function getActiveSpan(): Span | undefined {\n\treturn trace.getActiveSpan();\n}\n\n/**\n * Set attributes on the active span\n */\nexport function setSpanAttributes(attributes: Attributes): void {\n\tconst span = getActiveSpan();\n\tif (span) {\n\t\tspan.setAttributes(attributes);\n\t}\n}\n\n/**\n * Create a new span as a child of the current span\n */\nexport function createSpan(name: string, attributes?: Attributes): Span {\n\tconst tracer = trace.getTracer('@geekmidas/telescope');\n\tconst span = tracer.startSpan(name, { attributes });\n\treturn span;\n}\n\n/**\n * Execute a function within a new span context\n *\n * @example\n * ```typescript\n * const result = await withSpan('processOrder', async (span) => {\n * span.setAttribute('order.id', orderId);\n * const order = await processOrder(orderId);\n * return order;\n * });\n * ```\n */\nexport async function withSpan<T>(\n\tname: string,\n\tfn: (span: Span) => Promise<T>,\n\tattributes?: Attributes,\n): Promise<T> {\n\tconst tracer = trace.getTracer('@geekmidas/telescope');\n\tconst span = tracer.startSpan(name, { attributes });\n\n\ttry {\n\t\tconst result = await context.with(\n\t\t\ttrace.setSpan(context.active(), span),\n\t\t\t() => fn(span),\n\t\t);\n\t\tspan.setStatus({ code: SpanStatusCode.OK });\n\t\treturn result;\n\t} catch (error) {\n\t\tspan.setStatus({\n\t\t\tcode: SpanStatusCode.ERROR,\n\t\t\tmessage: error instanceof Error ? error.message : 'Unknown error',\n\t\t});\n\t\tspan.recordException(\n\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t);\n\t\tthrow error;\n\t} finally {\n\t\tspan.end();\n\t}\n}\n\n/**\n * Synchronous version of withSpan\n */\nexport function withSpanSync<T>(\n\tname: string,\n\tfn: (span: Span) => T,\n\tattributes?: Attributes,\n): T {\n\tconst tracer = trace.getTracer('@geekmidas/telescope');\n\tconst span = tracer.startSpan(name, { attributes });\n\n\ttry {\n\t\tconst result = context.with(trace.setSpan(context.active(), span), () =>\n\t\t\tfn(span),\n\t\t);\n\t\tspan.setStatus({ code: SpanStatusCode.OK });\n\t\treturn result;\n\t} catch (error) {\n\t\tspan.setStatus({\n\t\t\tcode: SpanStatusCode.ERROR,\n\t\t\tmessage: error instanceof Error ? error.message : 'Unknown error',\n\t\t});\n\t\tspan.recordException(\n\t\t\terror instanceof Error ? error : new Error(String(error)),\n\t\t);\n\t\tthrow error;\n\t} finally {\n\t\tspan.end();\n\t}\n}\n\n/**\n * Get the current trace ID (useful for log correlation)\n */\nexport function getTraceId(): string | undefined {\n\tconst span = getActiveSpan();\n\treturn span?.spanContext().traceId;\n}\n\n/**\n * Get the current span ID\n */\nexport function getSpanId(): string | undefined {\n\tconst span = getActiveSpan();\n\treturn span?.spanContext().spanId;\n}\n\n/**\n * Record an exception on the current span\n */\nexport function recordException(error: Error): void {\n\tconst span = getActiveSpan();\n\tif (span) {\n\t\tspan.recordException(error);\n\t\tspan.setStatus({\n\t\t\tcode: SpanStatusCode.ERROR,\n\t\t\tmessage: error.message,\n\t\t});\n\t}\n}\n\n/**\n * Add an event to the current span\n */\nexport function addSpanEvent(name: string, attributes?: Attributes): void {\n\tconst span = getActiveSpan();\n\tif (span) {\n\t\tspan.addEvent(name, attributes);\n\t}\n}\n"],"mappings":";;;;;AAWA,SAAgB,gBAAkC;CACjD,OAAO,MAAM,cAAc;AAC5B;;;;AAKA,SAAgB,kBAAkB,YAA8B;CAC/D,MAAM,OAAO,cAAc;CAC3B,IAAI,MACH,KAAK,cAAc,UAAU;AAE/B;;;;AAKA,SAAgB,WAAW,MAAc,YAA+B;CAGvE,OAFe,MAAM,UAAU,sBACb,CAAC,CAAC,UAAU,MAAM,EAAE,WAAW,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ACnD,MAAM,OAAO,cAAc;CAC3B,IAAI,MAAM;EACT,KAAK,gBAAgB,KAAK;EAC1B,KAAK,UAAU;GACd,MAAM,eAAe;GACrB,SAAS,MAAM;EAChB,CAAC;CACF;AACD;;;;AAKA,SAAgB,aAAa,MAAc,YAA+B;CACzE,MAAM,OAAO,cAAc;CAC3B,IAAI,MACH,KAAK,SAAS,MAAM,UAAU;AAEhC"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/instrumentation/trust.ts
|
|
3
|
-
/**
|
|
4
|
-
* Whose `traceparent` an API continues.
|
|
5
|
-
*
|
|
6
|
-
* An incoming trace context is a claim made by the caller. Continued, it puts
|
|
7
|
-
* this request's span inside whatever trace the caller named, and its sampled
|
|
8
|
-
* flag asks this API to record it. From the API's own sites and from its own
|
|
9
|
-
* services that is the point; from anyone else it lets a stranger graft spans
|
|
10
|
-
* onto another user's trace, or force traces the stage's rate would not keep.
|
|
11
|
-
*
|
|
12
|
-
* So a request's context is continued only when it comes from a trusted source:
|
|
13
|
-
*
|
|
14
|
-
* - **its own sites** — an `Origin` header naming one of the API's allowed CORS
|
|
15
|
-
* origins (the sites with an edge to it). A browser sets `Origin` itself on
|
|
16
|
-
* every cross-origin request and a page cannot forge it;
|
|
17
|
-
* - **an internal caller** — no `Origin` at all, no header any reverse proxy
|
|
18
|
-
* adds (`X-Forwarded-For`, `Forwarded`, `X-Real-IP`, …), and a TCP peer on a
|
|
19
|
-
* loopback or private address. That is another service calling this one
|
|
20
|
-
* over the private network by its internal URL: a request from the internet
|
|
21
|
-
* reaches the API through the stack's proxy, which always adds a forwarding
|
|
22
|
-
* header, or from a public address.
|
|
23
|
-
*
|
|
24
|
-
* Anything else — an unknown origin, a request through the public proxy with
|
|
25
|
-
* no origin (curl, a server elsewhere) — starts a new trace, linked to the
|
|
26
|
-
* context it claimed so the hop can still be followed.
|
|
27
|
-
*
|
|
28
|
-
* Whether a trusted context is *sampled* is still this API's decision: see
|
|
29
|
-
* `traceSampler`, which caps an incoming sampled flag at the stage's rate.
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* Headers a reverse proxy or CDN adds on the way in.
|
|
33
|
-
*
|
|
34
|
-
* Not `x-gkm-client-ip`: that is gkm's own, sent by a service calling another
|
|
35
|
-
* on a client's behalf (an API's session check), and stripped by the stack's
|
|
36
|
-
* edge from everything that arrives from outside.
|
|
37
|
-
*/
|
|
38
|
-
const FORWARDING_HEADERS = [
|
|
39
|
-
"forwarded",
|
|
40
|
-
"x-forwarded-for",
|
|
41
|
-
"x-forwarded-host",
|
|
42
|
-
"x-real-ip",
|
|
43
|
-
"cf-connecting-ip",
|
|
44
|
-
"true-client-ip",
|
|
45
|
-
"fastly-client-ip",
|
|
46
|
-
"x-client-ip"
|
|
47
|
-
];
|
|
48
|
-
/** `origin` normalized the way a browser sends it, or undefined. */
|
|
49
|
-
function normalizeOrigin(origin) {
|
|
50
|
-
try {
|
|
51
|
-
const url = new URL(origin);
|
|
52
|
-
return url.origin === "null" ? void 0 : url.origin;
|
|
53
|
-
} catch {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Whether `origin` is one of `trustedOrigins` — exactly, scheme, host and
|
|
59
|
-
* port. A wildcard trusts nothing: an API that answers any origin's CORS has
|
|
60
|
-
* not said which sites are its own.
|
|
61
|
-
*/
|
|
62
|
-
function isTrustedOrigin(origin, trustedOrigins) {
|
|
63
|
-
if (!origin || !trustedOrigins?.length) return false;
|
|
64
|
-
const normalized = normalizeOrigin(origin);
|
|
65
|
-
if (!normalized) return false;
|
|
66
|
-
return trustedOrigins.some((trusted) => trusted !== "*" && normalizeOrigin(trusted) === normalized);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Whether `address` is loopback or private: 127/8, 10/8, 172.16/12,
|
|
70
|
-
* 192.168/16, 169.254/16, `::1`, `fc00::/7`, `fe80::/10`, and an IPv4 one
|
|
71
|
-
* mapped into IPv6.
|
|
72
|
-
*/
|
|
73
|
-
function isPrivateAddress(address) {
|
|
74
|
-
if (!address) return false;
|
|
75
|
-
const ip = address.toLowerCase().replace(/^::ffff:/, "");
|
|
76
|
-
const v4 = ip.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
77
|
-
if (v4) {
|
|
78
|
-
const [a, b] = [Number(v4[1]), Number(v4[2])];
|
|
79
|
-
return a === 127 || a === 10 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 169 && b === 254;
|
|
80
|
-
}
|
|
81
|
-
if (ip === "::1") return true;
|
|
82
|
-
return /^f[cd][0-9a-f]{2}:/.test(ip) || /^fe[89ab][0-9a-f]:/.test(ip);
|
|
83
|
-
}
|
|
84
|
-
function header(headers, name) {
|
|
85
|
-
if (headers instanceof Headers) return headers.get(name) ?? void 0;
|
|
86
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
87
|
-
if (key.toLowerCase() !== name) continue;
|
|
88
|
-
return Array.isArray(value) ? value[0] : value;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Whether a request is an internal caller's: no `Origin`, no forwarding
|
|
93
|
-
* header, and a loopback or private peer. Without a peer address — a request
|
|
94
|
-
* handed to the app in-process, a runtime that does not expose the socket —
|
|
95
|
-
* it is not.
|
|
96
|
-
*/
|
|
97
|
-
function isInternalCaller(request) {
|
|
98
|
-
if (header(request.headers, "origin")) return false;
|
|
99
|
-
if (FORWARDING_HEADERS.some((name) => header(request.headers, name))) return false;
|
|
100
|
-
return isPrivateAddress(request.remoteAddress);
|
|
101
|
-
}
|
|
102
|
-
//#endregion
|
|
103
|
-
exports.isInternalCaller = isInternalCaller;
|
|
104
|
-
exports.isPrivateAddress = isPrivateAddress;
|
|
105
|
-
exports.isTrustedOrigin = isTrustedOrigin;
|
|
106
|
-
|
|
107
|
-
//# sourceMappingURL=trust.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trust.cjs","names":[],"sources":["../../src/instrumentation/trust.ts"],"sourcesContent":["/**\n * Whose `traceparent` an API continues.\n *\n * An incoming trace context is a claim made by the caller. Continued, it puts\n * this request's span inside whatever trace the caller named, and its sampled\n * flag asks this API to record it. From the API's own sites and from its own\n * services that is the point; from anyone else it lets a stranger graft spans\n * onto another user's trace, or force traces the stage's rate would not keep.\n *\n * So a request's context is continued only when it comes from a trusted source:\n *\n * - **its own sites** — an `Origin` header naming one of the API's allowed CORS\n * origins (the sites with an edge to it). A browser sets `Origin` itself on\n * every cross-origin request and a page cannot forge it;\n * - **an internal caller** — no `Origin` at all, no header any reverse proxy\n * adds (`X-Forwarded-For`, `Forwarded`, `X-Real-IP`, …), and a TCP peer on a\n * loopback or private address. That is another service calling this one\n * over the private network by its internal URL: a request from the internet\n * reaches the API through the stack's proxy, which always adds a forwarding\n * header, or from a public address.\n *\n * Anything else — an unknown origin, a request through the public proxy with\n * no origin (curl, a server elsewhere) — starts a new trace, linked to the\n * context it claimed so the hop can still be followed.\n *\n * Whether a trusted context is *sampled* is still this API's decision: see\n * `traceSampler`, which caps an incoming sampled flag at the stage's rate.\n */\n\n/**\n * Headers a reverse proxy or CDN adds on the way in.\n *\n * Not `x-gkm-client-ip`: that is gkm's own, sent by a service calling another\n * on a client's behalf (an API's session check), and stripped by the stack's\n * edge from everything that arrives from outside.\n */\nconst FORWARDING_HEADERS = [\n\t'forwarded',\n\t'x-forwarded-for',\n\t'x-forwarded-host',\n\t'x-real-ip',\n\t'cf-connecting-ip',\n\t'true-client-ip',\n\t'fastly-client-ip',\n\t'x-client-ip',\n];\n\n/** `origin` normalized the way a browser sends it, or undefined. */\nfunction normalizeOrigin(origin: string): string | undefined {\n\ttry {\n\t\tconst url = new URL(origin);\n\t\treturn url.origin === 'null' ? undefined : url.origin;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Whether `origin` is one of `trustedOrigins` — exactly, scheme, host and\n * port. A wildcard trusts nothing: an API that answers any origin's CORS has\n * not said which sites are its own.\n */\nexport function isTrustedOrigin(\n\torigin: string | undefined,\n\ttrustedOrigins: readonly string[] | undefined,\n): boolean {\n\tif (!origin || !trustedOrigins?.length) return false;\n\tconst normalized = normalizeOrigin(origin);\n\tif (!normalized) return false;\n\treturn trustedOrigins.some(\n\t\t(trusted) => trusted !== '*' && normalizeOrigin(trusted) === normalized,\n\t);\n}\n\n/**\n * Whether `address` is loopback or private: 127/8, 10/8, 172.16/12,\n * 192.168/16, 169.254/16, `::1`, `fc00::/7`, `fe80::/10`, and an IPv4 one\n * mapped into IPv6.\n */\nexport function isPrivateAddress(address: string | undefined): boolean {\n\tif (!address) return false;\n\tconst ip = address.toLowerCase().replace(/^::ffff:/, '');\n\n\tconst v4 = ip.match(/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/);\n\tif (v4) {\n\t\tconst [a, b] = [Number(v4[1]), Number(v4[2])];\n\t\treturn (\n\t\t\ta === 127 ||\n\t\t\ta === 10 ||\n\t\t\t(a === 172 && b >= 16 && b <= 31) ||\n\t\t\t(a === 192 && b === 168) ||\n\t\t\t(a === 169 && b === 254)\n\t\t);\n\t}\n\n\tif (ip === '::1') return true;\n\treturn /^f[cd][0-9a-f]{2}:/.test(ip) || /^fe[89ab][0-9a-f]:/.test(ip);\n}\n\n/** What the internal-caller rule looks at. */\nexport interface IncomingRequestFacts {\n\t/** Every request header. */\n\theaders: Headers | Record<string, string | string[] | undefined>;\n\t/** The TCP peer's address, when the server knows it. */\n\tremoteAddress?: string;\n}\n\nfunction header(\n\theaders: IncomingRequestFacts['headers'],\n\tname: string,\n): string | undefined {\n\tif (headers instanceof Headers) return headers.get(name) ?? undefined;\n\tfor (const [key, value] of Object.entries(headers)) {\n\t\tif (key.toLowerCase() !== name) continue;\n\t\treturn Array.isArray(value) ? value[0] : value;\n\t}\n\treturn undefined;\n}\n\n/**\n * Whether a request is an internal caller's: no `Origin`, no forwarding\n * header, and a loopback or private peer. Without a peer address — a request\n * handed to the app in-process, a runtime that does not expose the socket —\n * it is not.\n */\nexport function isInternalCaller(request: IncomingRequestFacts): boolean {\n\tif (header(request.headers, 'origin')) return false;\n\tif (FORWARDING_HEADERS.some((name) => header(request.headers, name))) {\n\t\treturn false;\n\t}\n\treturn isPrivateAddress(request.remoteAddress);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,qBAAqB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;;AAGA,SAAS,gBAAgB,QAAoC;CAC5D,IAAI;EACH,MAAM,MAAM,IAAI,IAAI,MAAM;EAC1B,OAAO,IAAI,WAAW,SAAS,KAAA,IAAY,IAAI;CAChD,QAAQ;EACP;CACD;AACD;;;;;;AAOA,SAAgB,gBACf,QACA,gBACU;CACV,IAAI,CAAC,UAAU,CAAC,gBAAgB,QAAQ,OAAO;CAC/C,MAAM,aAAa,gBAAgB,MAAM;CACzC,IAAI,CAAC,YAAY,OAAO;CACxB,OAAO,eAAe,MACpB,YAAY,YAAY,OAAO,gBAAgB,OAAO,MAAM,UAC9D;AACD;;;;;;AAOA,SAAgB,iBAAiB,SAAsC;CACtE,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,KAAK,QAAQ,YAAY,CAAC,CAAC,QAAQ,YAAY,EAAE;CAEvD,MAAM,KAAK,GAAG,MAAM,8CAA8C;CAClE,IAAI,IAAI;EACP,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,GAAG,EAAE,GAAG,OAAO,GAAG,EAAE,CAAC;EAC5C,OACC,MAAM,OACN,MAAM,MACL,MAAM,OAAO,KAAK,MAAM,KAAK,MAC7B,MAAM,OAAO,MAAM,OACnB,MAAM,OAAO,MAAM;CAEtB;CAEA,IAAI,OAAO,OAAO,OAAO;CACzB,OAAO,qBAAqB,KAAK,EAAE,KAAK,qBAAqB,KAAK,EAAE;AACrE;AAUA,SAAS,OACR,SACA,MACqB;CACrB,IAAI,mBAAmB,SAAS,OAAO,QAAQ,IAAI,IAAI,KAAK,KAAA;CAC5D,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAAG;EACnD,IAAI,IAAI,YAAY,MAAM,MAAM;EAChC,OAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK;CAC1C;AAED;;;;;;;AAQA,SAAgB,iBAAiB,SAAwC;CACxE,IAAI,OAAO,QAAQ,SAAS,QAAQ,GAAG,OAAO;CAC9C,IAAI,mBAAmB,MAAM,SAAS,OAAO,QAAQ,SAAS,IAAI,CAAC,GAClE,OAAO;CAER,OAAO,iBAAiB,QAAQ,aAAa;AAC9C"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
//#region src/instrumentation/trust.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Whose `traceparent` an API continues.
|
|
4
|
-
*
|
|
5
|
-
* An incoming trace context is a claim made by the caller. Continued, it puts
|
|
6
|
-
* this request's span inside whatever trace the caller named, and its sampled
|
|
7
|
-
* flag asks this API to record it. From the API's own sites and from its own
|
|
8
|
-
* services that is the point; from anyone else it lets a stranger graft spans
|
|
9
|
-
* onto another user's trace, or force traces the stage's rate would not keep.
|
|
10
|
-
*
|
|
11
|
-
* So a request's context is continued only when it comes from a trusted source:
|
|
12
|
-
*
|
|
13
|
-
* - **its own sites** — an `Origin` header naming one of the API's allowed CORS
|
|
14
|
-
* origins (the sites with an edge to it). A browser sets `Origin` itself on
|
|
15
|
-
* every cross-origin request and a page cannot forge it;
|
|
16
|
-
* - **an internal caller** — no `Origin` at all, no header any reverse proxy
|
|
17
|
-
* adds (`X-Forwarded-For`, `Forwarded`, `X-Real-IP`, …), and a TCP peer on a
|
|
18
|
-
* loopback or private address. That is another service calling this one
|
|
19
|
-
* over the private network by its internal URL: a request from the internet
|
|
20
|
-
* reaches the API through the stack's proxy, which always adds a forwarding
|
|
21
|
-
* header, or from a public address.
|
|
22
|
-
*
|
|
23
|
-
* Anything else — an unknown origin, a request through the public proxy with
|
|
24
|
-
* no origin (curl, a server elsewhere) — starts a new trace, linked to the
|
|
25
|
-
* context it claimed so the hop can still be followed.
|
|
26
|
-
*
|
|
27
|
-
* Whether a trusted context is *sampled* is still this API's decision: see
|
|
28
|
-
* `traceSampler`, which caps an incoming sampled flag at the stage's rate.
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* Whether `origin` is one of `trustedOrigins` — exactly, scheme, host and
|
|
32
|
-
* port. A wildcard trusts nothing: an API that answers any origin's CORS has
|
|
33
|
-
* not said which sites are its own.
|
|
34
|
-
*/
|
|
35
|
-
export declare function isTrustedOrigin(origin: string | undefined, trustedOrigins: readonly string[] | undefined): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Whether `address` is loopback or private: 127/8, 10/8, 172.16/12,
|
|
38
|
-
* 192.168/16, 169.254/16, `::1`, `fc00::/7`, `fe80::/10`, and an IPv4 one
|
|
39
|
-
* mapped into IPv6.
|
|
40
|
-
*/
|
|
41
|
-
export declare function isPrivateAddress(address: string | undefined): boolean;
|
|
42
|
-
/** What the internal-caller rule looks at. */
|
|
43
|
-
export interface IncomingRequestFacts {
|
|
44
|
-
/** Every request header. */
|
|
45
|
-
headers: Headers | Record<string, string | string[] | undefined>;
|
|
46
|
-
/** The TCP peer's address, when the server knows it. */
|
|
47
|
-
remoteAddress?: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Whether a request is an internal caller's: no `Origin`, no forwarding
|
|
51
|
-
* header, and a loopback or private peer. Without a peer address — a request
|
|
52
|
-
* handed to the app in-process, a runtime that does not expose the socket —
|
|
53
|
-
* it is not.
|
|
54
|
-
*/
|
|
55
|
-
export declare function isInternalCaller(request: IncomingRequestFacts): boolean;
|
|
56
|
-
//#endregion
|
|
57
|
-
//# sourceMappingURL=trust.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trust.d.cts","names":[],"sources":["../../src/instrumentation/trust.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8DgB,gBACf,4BACA;;;;;;wBAee,iBAAiB;;iBAqBhB;;EAEhB,SAAS,UAAU;;EAEnB;;;;;;;;wBAqBe,iBAAiB,SAAS"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
//#region src/instrumentation/trust.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Whose `traceparent` an API continues.
|
|
4
|
-
*
|
|
5
|
-
* An incoming trace context is a claim made by the caller. Continued, it puts
|
|
6
|
-
* this request's span inside whatever trace the caller named, and its sampled
|
|
7
|
-
* flag asks this API to record it. From the API's own sites and from its own
|
|
8
|
-
* services that is the point; from anyone else it lets a stranger graft spans
|
|
9
|
-
* onto another user's trace, or force traces the stage's rate would not keep.
|
|
10
|
-
*
|
|
11
|
-
* So a request's context is continued only when it comes from a trusted source:
|
|
12
|
-
*
|
|
13
|
-
* - **its own sites** — an `Origin` header naming one of the API's allowed CORS
|
|
14
|
-
* origins (the sites with an edge to it). A browser sets `Origin` itself on
|
|
15
|
-
* every cross-origin request and a page cannot forge it;
|
|
16
|
-
* - **an internal caller** — no `Origin` at all, no header any reverse proxy
|
|
17
|
-
* adds (`X-Forwarded-For`, `Forwarded`, `X-Real-IP`, …), and a TCP peer on a
|
|
18
|
-
* loopback or private address. That is another service calling this one
|
|
19
|
-
* over the private network by its internal URL: a request from the internet
|
|
20
|
-
* reaches the API through the stack's proxy, which always adds a forwarding
|
|
21
|
-
* header, or from a public address.
|
|
22
|
-
*
|
|
23
|
-
* Anything else — an unknown origin, a request through the public proxy with
|
|
24
|
-
* no origin (curl, a server elsewhere) — starts a new trace, linked to the
|
|
25
|
-
* context it claimed so the hop can still be followed.
|
|
26
|
-
*
|
|
27
|
-
* Whether a trusted context is *sampled* is still this API's decision: see
|
|
28
|
-
* `traceSampler`, which caps an incoming sampled flag at the stage's rate.
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* Whether `origin` is one of `trustedOrigins` — exactly, scheme, host and
|
|
32
|
-
* port. A wildcard trusts nothing: an API that answers any origin's CORS has
|
|
33
|
-
* not said which sites are its own.
|
|
34
|
-
*/
|
|
35
|
-
export declare function isTrustedOrigin(origin: string | undefined, trustedOrigins: readonly string[] | undefined): boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Whether `address` is loopback or private: 127/8, 10/8, 172.16/12,
|
|
38
|
-
* 192.168/16, 169.254/16, `::1`, `fc00::/7`, `fe80::/10`, and an IPv4 one
|
|
39
|
-
* mapped into IPv6.
|
|
40
|
-
*/
|
|
41
|
-
export declare function isPrivateAddress(address: string | undefined): boolean;
|
|
42
|
-
/** What the internal-caller rule looks at. */
|
|
43
|
-
export interface IncomingRequestFacts {
|
|
44
|
-
/** Every request header. */
|
|
45
|
-
headers: Headers | Record<string, string | string[] | undefined>;
|
|
46
|
-
/** The TCP peer's address, when the server knows it. */
|
|
47
|
-
remoteAddress?: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Whether a request is an internal caller's: no `Origin`, no forwarding
|
|
51
|
-
* header, and a loopback or private peer. Without a peer address — a request
|
|
52
|
-
* handed to the app in-process, a runtime that does not expose the socket —
|
|
53
|
-
* it is not.
|
|
54
|
-
*/
|
|
55
|
-
export declare function isInternalCaller(request: IncomingRequestFacts): boolean;
|
|
56
|
-
//#endregion
|
|
57
|
-
//# sourceMappingURL=trust.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trust.d.mts","names":[],"sources":["../../src/instrumentation/trust.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8DgB,gBACf,4BACA;;;;;;wBAee,iBAAiB;;iBAqBhB;;EAEhB,SAAS,UAAU;;EAEnB;;;;;;;;wBAqBe,iBAAiB,SAAS"}
|