@vtex/api 6.45.4
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 +1685 -0
- package/README.md +65 -0
- package/gen/manifest.schema +189 -0
- package/lib/HttpClient/GraphQLClient.d.ts +28 -0
- package/lib/HttpClient/GraphQLClient.js +30 -0
- package/lib/HttpClient/HttpClient.d.ts +29 -0
- package/lib/HttpClient/HttpClient.js +130 -0
- package/lib/HttpClient/agents.d.ts +3 -0
- package/lib/HttpClient/agents.js +24 -0
- package/lib/HttpClient/index.d.ts +6 -0
- package/lib/HttpClient/index.js +14 -0
- package/lib/HttpClient/middlewares/cache.d.ts +35 -0
- package/lib/HttpClient/middlewares/cache.js +173 -0
- package/lib/HttpClient/middlewares/cancellationToken.d.ts +3 -0
- package/lib/HttpClient/middlewares/cancellationToken.js +72 -0
- package/lib/HttpClient/middlewares/inflight.d.ts +5 -0
- package/lib/HttpClient/middlewares/inflight.js +50 -0
- package/lib/HttpClient/middlewares/memoization.d.ts +7 -0
- package/lib/HttpClient/middlewares/memoization.js +40 -0
- package/lib/HttpClient/middlewares/metrics.d.ts +9 -0
- package/lib/HttpClient/middlewares/metrics.js +110 -0
- package/lib/HttpClient/middlewares/notFound.d.ts +7 -0
- package/lib/HttpClient/middlewares/notFound.js +20 -0
- package/lib/HttpClient/middlewares/recorder.d.ts +3 -0
- package/lib/HttpClient/middlewares/recorder.js +21 -0
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +14 -0
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +37 -0
- package/lib/HttpClient/middlewares/request/index.d.ts +18 -0
- package/lib/HttpClient/middlewares/request/index.js +83 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +1 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.js +20 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +48 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +7 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.d.ts +8 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +51 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.d.ts +4 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +29 -0
- package/lib/HttpClient/middlewares/tracing.d.ts +15 -0
- package/lib/HttpClient/middlewares/tracing.js +54 -0
- package/lib/HttpClient/typings.d.ts +123 -0
- package/lib/HttpClient/typings.js +11 -0
- package/lib/caches/CacheLayer.d.ts +7 -0
- package/lib/caches/CacheLayer.js +2 -0
- package/lib/caches/DiskCache.d.ts +17 -0
- package/lib/caches/DiskCache.js +70 -0
- package/lib/caches/LRUCache.d.ts +16 -0
- package/lib/caches/LRUCache.js +48 -0
- package/lib/caches/LRUDiskCache.d.ts +21 -0
- package/lib/caches/LRUDiskCache.js +132 -0
- package/lib/caches/MultilayeredCache.d.ts +14 -0
- package/lib/caches/MultilayeredCache.js +68 -0
- package/lib/caches/index.d.ts +6 -0
- package/lib/caches/index.js +9 -0
- package/lib/caches/typings.d.ts +48 -0
- package/lib/caches/typings.js +2 -0
- package/lib/clients/IOClient.d.ts +13 -0
- package/lib/clients/IOClient.js +19 -0
- package/lib/clients/IOClients.d.ts +37 -0
- package/lib/clients/IOClients.js +89 -0
- package/lib/clients/IOGraphQLClient.d.ts +13 -0
- package/lib/clients/IOGraphQLClient.js +16 -0
- package/lib/clients/apps/AppClient.d.ts +9 -0
- package/lib/clients/apps/AppClient.js +34 -0
- package/lib/clients/apps/AppGraphQLClient.d.ts +9 -0
- package/lib/clients/apps/AppGraphQLClient.js +34 -0
- package/lib/clients/apps/Billing.d.ts +12 -0
- package/lib/clients/apps/Billing.js +21 -0
- package/lib/clients/apps/Builder.d.ts +45 -0
- package/lib/clients/apps/Builder.js +114 -0
- package/lib/clients/apps/MessagesGraphQL.d.ts +61 -0
- package/lib/clients/apps/MessagesGraphQL.js +121 -0
- package/lib/clients/apps/Settings.d.ts +14 -0
- package/lib/clients/apps/Settings.js +38 -0
- package/lib/clients/apps/catalogGraphQL/brand.d.ts +13 -0
- package/lib/clients/apps/catalogGraphQL/brand.js +18 -0
- package/lib/clients/apps/catalogGraphQL/category.d.ts +11 -0
- package/lib/clients/apps/catalogGraphQL/category.js +16 -0
- package/lib/clients/apps/catalogGraphQL/index.d.ts +22 -0
- package/lib/clients/apps/catalogGraphQL/index.js +88 -0
- package/lib/clients/apps/catalogGraphQL/product.d.ts +25 -0
- package/lib/clients/apps/catalogGraphQL/product.js +30 -0
- package/lib/clients/apps/catalogGraphQL/sku.d.ts +26 -0
- package/lib/clients/apps/catalogGraphQL/sku.js +30 -0
- package/lib/clients/apps/index.d.ts +7 -0
- package/lib/clients/apps/index.js +12 -0
- package/lib/clients/external/ExternalClient.d.ts +9 -0
- package/lib/clients/external/ExternalClient.js +21 -0
- package/lib/clients/external/ID.d.ts +23 -0
- package/lib/clients/external/ID.js +60 -0
- package/lib/clients/external/Masterdata.d.ts +93 -0
- package/lib/clients/external/Masterdata.js +223 -0
- package/lib/clients/external/PaymentProvider.d.ts +31 -0
- package/lib/clients/external/PaymentProvider.js +42 -0
- package/lib/clients/external/index.d.ts +4 -0
- package/lib/clients/external/index.js +9 -0
- package/lib/clients/index.d.ts +9 -0
- package/lib/clients/index.js +17 -0
- package/lib/clients/infra/Apps.d.ts +88 -0
- package/lib/clients/infra/Apps.js +508 -0
- package/lib/clients/infra/Assets.d.ts +34 -0
- package/lib/clients/infra/Assets.js +165 -0
- package/lib/clients/infra/BillingMetrics.d.ts +13 -0
- package/lib/clients/infra/BillingMetrics.js +15 -0
- package/lib/clients/infra/Events.d.ts +12 -0
- package/lib/clients/infra/Events.js +33 -0
- package/lib/clients/infra/Housekeeper.d.ts +10 -0
- package/lib/clients/infra/Housekeeper.js +30 -0
- package/lib/clients/infra/InfraClient.d.ts +9 -0
- package/lib/clients/infra/InfraClient.js +34 -0
- package/lib/clients/infra/Metadata.d.ts +26 -0
- package/lib/clients/infra/Metadata.js +83 -0
- package/lib/clients/infra/Registry.d.ts +59 -0
- package/lib/clients/infra/Registry.js +207 -0
- package/lib/clients/infra/Router.d.ts +34 -0
- package/lib/clients/infra/Router.js +81 -0
- package/lib/clients/infra/Sphinx.d.ts +13 -0
- package/lib/clients/infra/Sphinx.js +29 -0
- package/lib/clients/infra/VBase.d.ts +60 -0
- package/lib/clients/infra/VBase.js +171 -0
- package/lib/clients/infra/Workspaces.d.ts +18 -0
- package/lib/clients/infra/Workspaces.js +65 -0
- package/lib/clients/infra/index.d.ts +12 -0
- package/lib/clients/infra/index.js +17 -0
- package/lib/clients/janus/JanusClient.d.ts +21 -0
- package/lib/clients/janus/JanusClient.js +30 -0
- package/lib/clients/janus/LicenseManager.d.ts +7 -0
- package/lib/clients/janus/LicenseManager.js +58 -0
- package/lib/clients/janus/Segment.d.ts +36 -0
- package/lib/clients/janus/Segment.js +79 -0
- package/lib/clients/janus/Session.d.ts +15 -0
- package/lib/clients/janus/Session.js +75 -0
- package/lib/clients/janus/Tenant.d.ts +29 -0
- package/lib/clients/janus/Tenant.js +28 -0
- package/lib/clients/janus/index.d.ts +5 -0
- package/lib/clients/janus/index.js +10 -0
- package/lib/constants.d.ts +59 -0
- package/lib/constants.js +65 -0
- package/lib/errors/AuthenticationError.d.ts +18 -0
- package/lib/errors/AuthenticationError.js +24 -0
- package/lib/errors/ForbiddenError.d.ts +18 -0
- package/lib/errors/ForbiddenError.js +24 -0
- package/lib/errors/NotFoundError.d.ts +18 -0
- package/lib/errors/NotFoundError.js +24 -0
- package/lib/errors/RequestCancelledError.d.ts +6 -0
- package/lib/errors/RequestCancelledError.js +11 -0
- package/lib/errors/ResolverError.d.ts +29 -0
- package/lib/errors/ResolverError.js +35 -0
- package/lib/errors/ResolverWarning.d.ts +21 -0
- package/lib/errors/ResolverWarning.js +28 -0
- package/lib/errors/TooManyRequestsError.d.ts +4 -0
- package/lib/errors/TooManyRequestsError.js +9 -0
- package/lib/errors/UserInputError.d.ts +18 -0
- package/lib/errors/UserInputError.js +24 -0
- package/lib/errors/customGraphQLError.d.ts +4 -0
- package/lib/errors/customGraphQLError.js +9 -0
- package/lib/errors/index.d.ts +8 -0
- package/lib/errors/index.js +13 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +21 -0
- package/lib/metrics/MetricsAccumulator.d.ts +35 -0
- package/lib/metrics/MetricsAccumulator.js +125 -0
- package/lib/responses.d.ts +79 -0
- package/lib/responses.js +2 -0
- package/lib/service/index.d.ts +2 -0
- package/lib/service/index.js +30 -0
- package/lib/service/loaders.d.ts +8 -0
- package/lib/service/loaders.js +54 -0
- package/lib/service/logger/console.d.ts +10 -0
- package/lib/service/logger/console.js +36 -0
- package/lib/service/logger/index.d.ts +2 -0
- package/lib/service/logger/index.js +7 -0
- package/lib/service/logger/logger.d.ts +35 -0
- package/lib/service/logger/logger.js +73 -0
- package/lib/service/logger/metricsLogger.d.ts +40 -0
- package/lib/service/logger/metricsLogger.js +149 -0
- package/lib/service/master.d.ts +2 -0
- package/lib/service/master.js +91 -0
- package/lib/service/tracing/TracerSingleton.d.ts +7 -0
- package/lib/service/tracing/TracerSingleton.js +54 -0
- package/lib/service/tracing/metrics/MetricNames.d.ts +60 -0
- package/lib/service/tracing/metrics/MetricNames.js +44 -0
- package/lib/service/tracing/metrics/instruments.d.ts +9 -0
- package/lib/service/tracing/metrics/instruments.js +11 -0
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.d.ts +9 -0
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +25 -0
- package/lib/service/tracing/tracingMiddlewares.d.ts +5 -0
- package/lib/service/tracing/tracingMiddlewares.js +119 -0
- package/lib/service/worker/index.d.ts +11 -0
- package/lib/service/worker/index.js +193 -0
- package/lib/service/worker/listeners.d.ts +3 -0
- package/lib/service/worker/listeners.js +43 -0
- package/lib/service/worker/runtime/Service.d.ts +17 -0
- package/lib/service/worker/runtime/Service.js +23 -0
- package/lib/service/worker/runtime/builtIn/handlers.d.ts +4 -0
- package/lib/service/worker/runtime/builtIn/handlers.js +27 -0
- package/lib/service/worker/runtime/builtIn/middlewares.d.ts +4 -0
- package/lib/service/worker/runtime/builtIn/middlewares.js +40 -0
- package/lib/service/worker/runtime/events/index.d.ts +4 -0
- package/lib/service/worker/runtime/events/index.js +46 -0
- package/lib/service/worker/runtime/events/middlewares/body.d.ts +3 -0
- package/lib/service/worker/runtime/events/middlewares/body.js +22 -0
- package/lib/service/worker/runtime/events/middlewares/context.d.ts +3 -0
- package/lib/service/worker/runtime/events/middlewares/context.js +22 -0
- package/lib/service/worker/runtime/events/router.d.ts +2 -0
- package/lib/service/worker/runtime/events/router.js +27 -0
- package/lib/service/worker/runtime/graphql/index.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/index.js +27 -0
- package/lib/service/worker/runtime/graphql/middlewares/context.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/context.js +16 -0
- package/lib/service/worker/runtime/graphql/middlewares/error.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/error.js +93 -0
- package/lib/service/worker/runtime/graphql/middlewares/query.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/query.js +52 -0
- package/lib/service/worker/runtime/graphql/middlewares/response.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/response.js +38 -0
- package/lib/service/worker/runtime/graphql/middlewares/run.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/run.js +19 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +4 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +28 -0
- package/lib/service/worker/runtime/graphql/middlewares/upload.d.ts +4 -0
- package/lib/service/worker/runtime/graphql/middlewares/upload.js +12 -0
- package/lib/service/worker/runtime/graphql/schema/index.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/index.js +31 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +79 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.js +73 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.js +37 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.d.ts +11 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +61 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.js +40 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Sanitize.d.ts +9 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Sanitize.js +35 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +34 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/SmartCacheDirective.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/SmartCacheDirective.js +29 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +39 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +33 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.d.ts +22 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +36 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +12 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/ioUpload.d.ts +3 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/ioUpload.js +16 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.d.ts +10 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.js +39 -0
- package/lib/service/worker/runtime/graphql/typings.d.ts +31 -0
- package/lib/service/worker/runtime/graphql/typings.js +2 -0
- package/lib/service/worker/runtime/graphql/utils/cacheControl.d.ts +1 -0
- package/lib/service/worker/runtime/graphql/utils/cacheControl.js +32 -0
- package/lib/service/worker/runtime/graphql/utils/error.d.ts +1 -0
- package/lib/service/worker/runtime/graphql/utils/error.js +76 -0
- package/lib/service/worker/runtime/graphql/utils/pathname.d.ts +1 -0
- package/lib/service/worker/runtime/graphql/utils/pathname.js +7 -0
- package/lib/service/worker/runtime/graphql/utils/translations.d.ts +14 -0
- package/lib/service/worker/runtime/graphql/utils/translations.js +38 -0
- package/lib/service/worker/runtime/http/index.d.ts +5 -0
- package/lib/service/worker/runtime/http/index.js +58 -0
- package/lib/service/worker/runtime/http/middlewares/authTokens.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/authTokens.js +12 -0
- package/lib/service/worker/runtime/http/middlewares/cancellationToken.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/cancellationToken.js +18 -0
- package/lib/service/worker/runtime/http/middlewares/clients.d.ts +4 -0
- package/lib/service/worker/runtime/http/middlewares/clients.js +12 -0
- package/lib/service/worker/runtime/http/middlewares/context.d.ts +4 -0
- package/lib/service/worker/runtime/http/middlewares/context.js +36 -0
- package/lib/service/worker/runtime/http/middlewares/error.d.ts +2 -0
- package/lib/service/worker/runtime/http/middlewares/error.js +84 -0
- package/lib/service/worker/runtime/http/middlewares/rateLimit.d.ts +6 -0
- package/lib/service/worker/runtime/http/middlewares/rateLimit.js +42 -0
- package/lib/service/worker/runtime/http/middlewares/requestStats.d.ts +17 -0
- package/lib/service/worker/runtime/http/middlewares/requestStats.js +40 -0
- package/lib/service/worker/runtime/http/middlewares/setCookie.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/setCookie.js +52 -0
- package/lib/service/worker/runtime/http/middlewares/settings.d.ts +9 -0
- package/lib/service/worker/runtime/http/middlewares/settings.js +43 -0
- package/lib/service/worker/runtime/http/middlewares/timings.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/timings.js +45 -0
- package/lib/service/worker/runtime/http/middlewares/vary.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/vary.js +52 -0
- package/lib/service/worker/runtime/http/router.d.ts +2 -0
- package/lib/service/worker/runtime/http/router.js +23 -0
- package/lib/service/worker/runtime/http/routes.d.ts +19 -0
- package/lib/service/worker/runtime/http/routes.js +12 -0
- package/lib/service/worker/runtime/method.d.ts +9 -0
- package/lib/service/worker/runtime/method.js +23 -0
- package/lib/service/worker/runtime/statusTrack.d.ts +14 -0
- package/lib/service/worker/runtime/statusTrack.js +37 -0
- package/lib/service/worker/runtime/typings.d.ts +172 -0
- package/lib/service/worker/runtime/typings.js +2 -0
- package/lib/service/worker/runtime/utils/compose.d.ts +5 -0
- package/lib/service/worker/runtime/utils/compose.js +11 -0
- package/lib/service/worker/runtime/utils/context.d.ts +2 -0
- package/lib/service/worker/runtime/utils/context.js +40 -0
- package/lib/service/worker/runtime/utils/diff.d.ts +12 -0
- package/lib/service/worker/runtime/utils/diff.js +21 -0
- package/lib/service/worker/runtime/utils/recorder.d.ts +8 -0
- package/lib/service/worker/runtime/utils/recorder.js +37 -0
- package/lib/service/worker/runtime/utils/toArray.d.ts +1 -0
- package/lib/service/worker/runtime/utils/toArray.js +3 -0
- package/lib/service/worker/runtime/utils/tokenBucket.d.ts +2 -0
- package/lib/service/worker/runtime/utils/tokenBucket.js +16 -0
- package/lib/tracing/LogEvents.d.ts +31 -0
- package/lib/tracing/LogEvents.js +3 -0
- package/lib/tracing/LogFields.d.ts +61 -0
- package/lib/tracing/LogFields.js +3 -0
- package/lib/tracing/Tags.d.ts +79 -0
- package/lib/tracing/Tags.js +7 -0
- package/lib/tracing/UserLandTracer.d.ts +27 -0
- package/lib/tracing/UserLandTracer.js +55 -0
- package/lib/tracing/errorReporting/ErrorReport.d.ts +31 -0
- package/lib/tracing/errorReporting/ErrorReport.js +61 -0
- package/lib/tracing/index.d.ts +9 -0
- package/lib/tracing/index.js +19 -0
- package/lib/tracing/spanReference/SpanReferenceTypes.d.ts +4 -0
- package/lib/tracing/spanReference/SpanReferenceTypes.js +7 -0
- package/lib/tracing/spanReference/createSpanReference.d.ts +3 -0
- package/lib/tracing/spanReference/createSpanReference.js +8 -0
- package/lib/tracing/utils.d.ts +13 -0
- package/lib/tracing/utils.js +40 -0
- package/lib/utils/MineWinsConflictsResolver.d.ts +28 -0
- package/lib/utils/MineWinsConflictsResolver.js +130 -0
- package/lib/utils/app.d.ts +23 -0
- package/lib/utils/app.js +48 -0
- package/lib/utils/appsStaleIfError.d.ts +11 -0
- package/lib/utils/appsStaleIfError.js +63 -0
- package/lib/utils/billingOptions.d.ts +36 -0
- package/lib/utils/billingOptions.js +9 -0
- package/lib/utils/binding.d.ts +13 -0
- package/lib/utils/binding.js +38 -0
- package/lib/utils/cancel.d.ts +3 -0
- package/lib/utils/cancel.js +12 -0
- package/lib/utils/domain.d.ts +1 -0
- package/lib/utils/domain.js +5 -0
- package/lib/utils/error.d.ts +8 -0
- package/lib/utils/error.js +94 -0
- package/lib/utils/index.d.ts +9 -0
- package/lib/utils/index.js +14 -0
- package/lib/utils/message.d.ts +25 -0
- package/lib/utils/message.js +23 -0
- package/lib/utils/renameBy.d.ts +1 -0
- package/lib/utils/renameBy.js +4 -0
- package/lib/utils/retry.d.ts +4 -0
- package/lib/utils/retry.js +32 -0
- package/lib/utils/status.d.ts +1 -0
- package/lib/utils/status.js +11 -0
- package/lib/utils/tenant.d.ts +5 -0
- package/lib/utils/tenant.js +6 -0
- package/lib/utils/throwOnGraphQLErrors.d.ts +2 -0
- package/lib/utils/throwOnGraphQLErrors.js +15 -0
- package/lib/utils/time.d.ts +31 -0
- package/lib/utils/time.js +118 -0
- package/package.json +127 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import koaCompose from 'koa-compose';
|
|
2
|
+
import { IOClients } from '../../../../clients/IOClients';
|
|
3
|
+
import { ParamsContext, RecorderState } from '../typings';
|
|
4
|
+
export declare const compose: <ClientsT extends IOClients, StateT extends RecorderState, CustomT extends ParamsContext>(middlewares: koaCompose.Middleware<import("../typings").ServiceContext<ClientsT, StateT, CustomT>>[]) => koaCompose.ComposedMiddleware<import("../typings").ServiceContext<ClientsT, StateT, CustomT>>;
|
|
5
|
+
export declare const composeForEvents: <ClientsT extends IOClients, StateT extends RecorderState>(middlewares: koaCompose.Middleware<import("../typings").EventContext<ClientsT, StateT>>[]) => koaCompose.ComposedMiddleware<import("../typings").EventContext<ClientsT, StateT>>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const koa_compose_1 = __importDefault(require("koa-compose"));
|
|
7
|
+
const ramda_1 = require("ramda");
|
|
8
|
+
const cancel_1 = require("../../../../utils/cancel");
|
|
9
|
+
const time_1 = require("../../../../utils/time");
|
|
10
|
+
exports.compose = (middlewares) => koa_compose_1.default(middlewares.map(ramda_1.pipe(time_1.timer, cancel_1.cancel)));
|
|
11
|
+
exports.composeForEvents = (middlewares) => koa_compose_1.default(middlewares.map(time_1.timerForEvents));
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { IOContext, TracingContext } from '../typings';
|
|
2
|
+
export declare const prepareHandlerCtx: (header: any, tracingContext: TracingContext) => Pick<IOContext, "host" | "logger" | "account" | "workspace" | "requestId" | "operationId" | "production" | "platform" | "authToken" | "adminUserAuthToken" | "storeUserAuthToken" | "locale" | "product" | "recorder" | "region" | "userAgent" | "segmentToken" | "sessionToken" | "janusEnv" | "serverTiming" | "eventInfo" | "tenant" | "binding" | "cancellation" | "settings" | "tracer">;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const v4_1 = __importDefault(require("uuid/v4"));
|
|
7
|
+
const constants_1 = require("../../../../constants");
|
|
8
|
+
const UserLandTracer_1 = require("../../../../tracing/UserLandTracer");
|
|
9
|
+
const tenant_1 = require("../../../../utils/tenant");
|
|
10
|
+
const logger_1 = require("../../../logger");
|
|
11
|
+
const binding_1 = require("./../../../../utils/binding");
|
|
12
|
+
const getPlatform = (account) => {
|
|
13
|
+
return account.startsWith('gc-') ? 'gocommerce' : 'vtex';
|
|
14
|
+
};
|
|
15
|
+
exports.prepareHandlerCtx = (header, tracingContext) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const partialContext = {
|
|
18
|
+
account: header[constants_1.ACCOUNT_HEADER],
|
|
19
|
+
authToken: header[constants_1.CREDENTIAL_HEADER],
|
|
20
|
+
binding: header[constants_1.BINDING_HEADER] ? binding_1.parseBindingHeaderValue(header[constants_1.BINDING_HEADER]) : undefined,
|
|
21
|
+
host: header[constants_1.FORWARDED_HOST_HEADER],
|
|
22
|
+
locale: header[constants_1.LOCALE_HEADER],
|
|
23
|
+
operationId: header[constants_1.OPERATION_ID_HEADER] || v4_1.default(),
|
|
24
|
+
platform: header[constants_1.PLATFORM_HEADER] || getPlatform(header[constants_1.ACCOUNT_HEADER]),
|
|
25
|
+
product: header[constants_1.PRODUCT_HEADER],
|
|
26
|
+
production: ((_a = header[constants_1.WORKSPACE_IS_PRODUCTION_HEADER]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'true' || false,
|
|
27
|
+
region: constants_1.REGION,
|
|
28
|
+
requestId: header[constants_1.REQUEST_ID_HEADER],
|
|
29
|
+
segmentToken: header[constants_1.SEGMENT_HEADER],
|
|
30
|
+
sessionToken: header[constants_1.SESSION_HEADER],
|
|
31
|
+
tenant: header[constants_1.TENANT_HEADER] ? tenant_1.parseTenantHeaderValue(header[constants_1.TENANT_HEADER]) : undefined,
|
|
32
|
+
tracer: new UserLandTracer_1.UserLandTracer(tracingContext.tracer, tracingContext.currentSpan),
|
|
33
|
+
userAgent: process.env.VTEX_APP_ID || '',
|
|
34
|
+
workspace: header[constants_1.WORKSPACE_HEADER],
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
...partialContext,
|
|
38
|
+
logger: new logger_1.Logger(partialContext),
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export interface Snapshot {
|
|
3
|
+
usage: NodeJS.CpuUsage;
|
|
4
|
+
time: number;
|
|
5
|
+
}
|
|
6
|
+
interface CpuUsage {
|
|
7
|
+
user: number;
|
|
8
|
+
system: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function cpuSnapshot(): Snapshot;
|
|
11
|
+
export declare function snapshotDiff(curr: Snapshot, last: Snapshot): CpuUsage;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function cpuSnapshot() {
|
|
4
|
+
return {
|
|
5
|
+
time: microtime(),
|
|
6
|
+
usage: process.cpuUsage(),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
exports.cpuSnapshot = cpuSnapshot;
|
|
10
|
+
function snapshotDiff(curr, last) {
|
|
11
|
+
const timeDiff = curr.time - last.time;
|
|
12
|
+
return {
|
|
13
|
+
system: (curr.usage.system - last.usage.system) / timeDiff,
|
|
14
|
+
user: (curr.usage.user - last.usage.user) / timeDiff,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.snapshotDiff = snapshotDiff;
|
|
18
|
+
function microtime() {
|
|
19
|
+
const hrTime = process.hrtime();
|
|
20
|
+
return hrTime[0] * 1000000 + hrTime[1] / 1000;
|
|
21
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ramda_1 = require("ramda");
|
|
4
|
+
const constants_1 = require("./../../../../constants");
|
|
5
|
+
const HEADERS = [constants_1.META_HEADER, constants_1.META_HEADER_BUCKET];
|
|
6
|
+
class Recorder {
|
|
7
|
+
constructor() {
|
|
8
|
+
this._record = HEADERS.reduce((acc, headerName) => {
|
|
9
|
+
acc[headerName] = new Set();
|
|
10
|
+
return acc;
|
|
11
|
+
}, {});
|
|
12
|
+
}
|
|
13
|
+
clear() {
|
|
14
|
+
HEADERS.forEach(headerName => this._record[headerName].clear());
|
|
15
|
+
}
|
|
16
|
+
record(headers) {
|
|
17
|
+
HEADERS.forEach(headerName => {
|
|
18
|
+
const h = headers === null || headers === void 0 ? void 0 : headers[headerName];
|
|
19
|
+
if (h) {
|
|
20
|
+
h.split(',').map(ramda_1.trim).forEach(hh => this._record[headerName].add(hh));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
flush(ctx) {
|
|
25
|
+
HEADERS.forEach(headerName => {
|
|
26
|
+
const newValueSet = new Set(this._record[headerName]);
|
|
27
|
+
const currentValue = ctx.response.get(headerName);
|
|
28
|
+
const parsedCurrentValue = typeof currentValue === 'string' ? currentValue.split(',') : currentValue;
|
|
29
|
+
parsedCurrentValue.forEach(cur => newValueSet.add(ramda_1.trim(cur)));
|
|
30
|
+
const deduped = Array.from(newValueSet).filter(x => !!x);
|
|
31
|
+
if (deduped.length > 0) {
|
|
32
|
+
ctx.set(headerName, deduped);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Recorder = Recorder;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const toArray: <T>(x: T | T[]) => T[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const tokenbucket_1 = __importDefault(require("tokenbucket"));
|
|
7
|
+
function createTokenBucket(rateLimit, globalRateTokenBucket) {
|
|
8
|
+
return rateLimit ? new tokenbucket_1.default({
|
|
9
|
+
interval: 'minute',
|
|
10
|
+
parentBucket: globalRateTokenBucket,
|
|
11
|
+
size: Math.ceil(rateLimit / 2.0),
|
|
12
|
+
spread: true,
|
|
13
|
+
tokensToAddPerInterval: rateLimit,
|
|
14
|
+
}) : globalRateTokenBucket;
|
|
15
|
+
}
|
|
16
|
+
exports.createTokenBucket = createTokenBucket;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file has all events logged by the runtime's distributed tracing
|
|
3
|
+
* instrumentation. In the code you would see something like:
|
|
4
|
+
* ```
|
|
5
|
+
* span.log({ event: HttpEvents.CACHE_KEY_CREATE })
|
|
6
|
+
* ```
|
|
7
|
+
*/
|
|
8
|
+
export declare const enum HttpLogEvents {
|
|
9
|
+
/** Event holding the cache key created */
|
|
10
|
+
CACHE_KEY_CREATE = "cache-key-created",
|
|
11
|
+
/** Event representing that the memoization cache has just saved a response */
|
|
12
|
+
MEMOIZATION_CACHE_SAVED = "memoization-cache-saved",
|
|
13
|
+
/** Event representing that the memoization cache has just saved a error response */
|
|
14
|
+
MEMOIZATION_CACHE_SAVED_ERROR = "memoization-cache-saved-error",
|
|
15
|
+
/** Event holding information on a local cache hit that just happened */
|
|
16
|
+
LOCAL_CACHE_HIT_INFO = "local-cache-hit-info",
|
|
17
|
+
/** Event holding information on the cache config that will be used to decide whether or not to update the local cache */
|
|
18
|
+
CACHE_CONFIG = "cache-config",
|
|
19
|
+
/** Event informing the decision to not update or save to local cache */
|
|
20
|
+
NO_LOCAL_CACHE_SAVE = "no-local-cache-save",
|
|
21
|
+
/** Event holding information on the local cache save that just happened */
|
|
22
|
+
LOCAL_CACHE_SAVED = "local-cache-saved",
|
|
23
|
+
/** A request that is retryable just failed - this event will hold info on the retry that may happen */
|
|
24
|
+
SETUP_REQUEST_RETRY = "setup-request-retry"
|
|
25
|
+
}
|
|
26
|
+
export declare const enum RuntimeLogEvents {
|
|
27
|
+
/** Event representing that userland middlewares are about to start */
|
|
28
|
+
USER_MIDDLEWARES_START = "user-middlewares-start",
|
|
29
|
+
/** Event representing that userland middlewares just finished */
|
|
30
|
+
USER_MIDDLEWARES_FINISH = "user-middlewares-finish"
|
|
31
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When using span.log({ field1: string1, field2: object2, ... })
|
|
3
|
+
* The jaeger backend indexes for search the first-level fields that hold strings
|
|
4
|
+
* These fields then can be searched on jaeger-ui using: 'field1=string'
|
|
5
|
+
* This file concentrates all log fields used in node-vtex-api that hold
|
|
6
|
+
* strings and can be searched in the jaeger-ui
|
|
7
|
+
*/
|
|
8
|
+
export declare const enum ErrorReportLogFields {
|
|
9
|
+
/**
|
|
10
|
+
* ErrorReport class has some meta info on the error
|
|
11
|
+
* The following log fields hold this meta info
|
|
12
|
+
*/
|
|
13
|
+
ERROR_KIND = "error.kind",
|
|
14
|
+
ERROR_ID = "error.id",
|
|
15
|
+
/**
|
|
16
|
+
* VTEX's Infra errors adds error details to the response
|
|
17
|
+
* The following log fields are supposed to hold these fields
|
|
18
|
+
*/
|
|
19
|
+
ERROR_SERVER_CODE = "error.server.code",
|
|
20
|
+
ERROR_SERVER_REQUEST_ID = "error.server.request_id"
|
|
21
|
+
}
|
|
22
|
+
export declare const enum RuntimeLogFields {
|
|
23
|
+
/** Time in ms spent to run the user middlewares */
|
|
24
|
+
USER_MIDDLEWARES_DURATION = "user-middlewares-duration"
|
|
25
|
+
}
|
|
26
|
+
export declare const enum HttpCacheLogFields {
|
|
27
|
+
/** The generated cache key for Memoization or Local caches */
|
|
28
|
+
KEY = "key",
|
|
29
|
+
/** The generated cache key for local cache with the segment added to it */
|
|
30
|
+
KEY_WITH_SEGMENT = "key-with-segment",
|
|
31
|
+
/** The key that was just set on the cache */
|
|
32
|
+
KEY_SET = "key-set",
|
|
33
|
+
/** The type of cache: 'disk', 'memory' or 'memoization' */
|
|
34
|
+
CACHE_TYPE = "cache-type",
|
|
35
|
+
/** The etag for the current request used for caching decisions. Can be undefined. */
|
|
36
|
+
ETAG = "etag",
|
|
37
|
+
/** The expiration time in seconds of the current cache entry (either just saved or fetched from the storage) */
|
|
38
|
+
EXPIRATION_TIME = "expiration-time",
|
|
39
|
+
/** The http response type. Can be undefined. */
|
|
40
|
+
RESPONSE_TYPE = "response-type",
|
|
41
|
+
/** The http response encoding. Can be undefined. */
|
|
42
|
+
RESPONSE_ENCONDING = "response-encoding",
|
|
43
|
+
/**
|
|
44
|
+
* The forceMaxAge option on the incoming RequestConfig. This can be set to override no-cache or no-store headers.
|
|
45
|
+
* Can be undefined.
|
|
46
|
+
*/
|
|
47
|
+
FORCE_MAX_AGE = "force-max-age",
|
|
48
|
+
/** The calculated max-age the current response will have if stored */
|
|
49
|
+
CALCULATED_MAX_AGE = "calculated-max-age",
|
|
50
|
+
/** Content parsed from the incoming response headers */
|
|
51
|
+
AGE = "age",
|
|
52
|
+
NO_CACHE = "no-cache",
|
|
53
|
+
NO_STORE = "no-store",
|
|
54
|
+
MAX_AGE = "max-age"
|
|
55
|
+
}
|
|
56
|
+
export declare const enum HttpRetryLogFields {
|
|
57
|
+
/** The retry number scheduled (e.g, 1, 2, meaning that is the first or second retry) */
|
|
58
|
+
RETRY_NUMBER = "retry-number",
|
|
59
|
+
/** How much time in ms will be waited until this retry happens */
|
|
60
|
+
RETRY_IN = "retry-in"
|
|
61
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Tags as OpentracingTags } from 'opentracing';
|
|
2
|
+
export { OpentracingTags };
|
|
3
|
+
/**
|
|
4
|
+
* The following tags are process tags - defined when the tracer is instantiated.
|
|
5
|
+
* Those will annotate all spans created
|
|
6
|
+
*/
|
|
7
|
+
export declare const enum AppTags {
|
|
8
|
+
/** Boolean indicating if the app is linked or not */
|
|
9
|
+
VTEX_APP_LINKED = "app.linked",
|
|
10
|
+
/** The value of the NODE_ENV environment variable */
|
|
11
|
+
VTEX_APP_NODE_ENV = "app.node_env",
|
|
12
|
+
/** The @vtex/api version used (e.g. '6.1.2') */
|
|
13
|
+
VTEX_APP_NODE_VTEX_API_VERSION = "app.node_vtex_api_version",
|
|
14
|
+
/** The value of the VTEX_PRODUCTION environment variable - whether the app is in a production workspace */
|
|
15
|
+
VTEX_APP_PRODUCTION = "app.production",
|
|
16
|
+
/** The value of the VTEX_REGION environment variable (e.g. 'aws-us-east-1') */
|
|
17
|
+
VTEX_APP_REGION = "app.region",
|
|
18
|
+
/** The app version (e.g. '1.2.0') */
|
|
19
|
+
VTEX_APP_VERSION = "app.version",
|
|
20
|
+
/** The workspace in which the app is installed or linked */
|
|
21
|
+
VTEX_APP_WORKSPACE = "app.workspace"
|
|
22
|
+
}
|
|
23
|
+
/** The following tags annotate the entrypoint span on incoming requests */
|
|
24
|
+
export declare const enum VTEXIncomingRequestTags {
|
|
25
|
+
/** The account being served by the request */
|
|
26
|
+
VTEX_ACCOUNT = "vtex.incoming.account",
|
|
27
|
+
/** The request id header value */
|
|
28
|
+
VTEX_REQUEST_ID = "vtex.request_id",
|
|
29
|
+
/** The workspace being served by the request */
|
|
30
|
+
VTEX_WORKSPACE = "vtex.incoming.workspace"
|
|
31
|
+
}
|
|
32
|
+
export declare const enum CustomHttpTags {
|
|
33
|
+
HTTP_PATH = "http.path",
|
|
34
|
+
/** Set to true when the client had no response, probably meaning that there was a client error */
|
|
35
|
+
HTTP_NO_RESPONSE = "http.no_response",
|
|
36
|
+
/** The HTTP client name (e.g. Apps, Registry, Router) */
|
|
37
|
+
HTTP_CLIENT_NAME = "http.client.name",
|
|
38
|
+
/**
|
|
39
|
+
* CACHE_ENABLED tags indicate if the Cache strategy is enabled
|
|
40
|
+
* for the specific request.
|
|
41
|
+
*/
|
|
42
|
+
HTTP_MEMOIZATION_CACHE_ENABLED = "http.cache.memoization.enabled",
|
|
43
|
+
HTTP_DISK_CACHE_ENABLED = "http.cache.disk.enabled",
|
|
44
|
+
HTTP_MEMORY_CACHE_ENABLED = "http.cache.memory.enabled",
|
|
45
|
+
/**
|
|
46
|
+
* CACHE_RESULT tags indicate the result for that cache strategy
|
|
47
|
+
* (HIT or MISS for example). Since there may be many layers
|
|
48
|
+
* of cache a ENABLED flag for a strategy may be 'true', but
|
|
49
|
+
* the RESULT for that strategy may not be present.
|
|
50
|
+
*/
|
|
51
|
+
HTTP_MEMORY_CACHE_RESULT = "http.cache.memory",
|
|
52
|
+
HTTP_MEMOIZATION_CACHE_RESULT = "http.cache.memoization",
|
|
53
|
+
HTTP_DISK_CACHE_RESULT = "http.cache.disk",
|
|
54
|
+
HTTP_ROUTER_CACHE_RESULT = "http.cache.router"
|
|
55
|
+
}
|
|
56
|
+
export declare const UserlandTags: {
|
|
57
|
+
SPAN_KIND: "span.kind";
|
|
58
|
+
SPAN_KIND_RPC_CLIENT: "client";
|
|
59
|
+
SPAN_KIND_RPC_SERVER: "server";
|
|
60
|
+
SPAN_KIND_MESSAGING_PRODUCER: "producer";
|
|
61
|
+
SPAN_KIND_MESSAGING_CONSUMER: "consumer";
|
|
62
|
+
ERROR: "error";
|
|
63
|
+
COMPONENT: "component";
|
|
64
|
+
SAMPLING_PRIORITY: "sampling.priority";
|
|
65
|
+
PEER_SERVICE: "peer.service";
|
|
66
|
+
PEER_HOSTNAME: "peer.hostname";
|
|
67
|
+
PEER_ADDRESS: "peer.address";
|
|
68
|
+
PEER_HOST_IPV4: "peer.ipv4";
|
|
69
|
+
PEER_HOST_IPV6: "peer.ipv6";
|
|
70
|
+
PEER_PORT: "peer.port";
|
|
71
|
+
HTTP_URL: "http.url";
|
|
72
|
+
HTTP_METHOD: "http.method";
|
|
73
|
+
HTTP_STATUS_CODE: "http.status_code";
|
|
74
|
+
MESSAGE_BUS_DESTINATION: "message_bus.destination";
|
|
75
|
+
DB_INSTANCE: "db.instance";
|
|
76
|
+
DB_STATEMENT: "db.statement";
|
|
77
|
+
DB_TYPE: "db.type";
|
|
78
|
+
DB_USER: "db.user";
|
|
79
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Span, SpanContext, SpanOptions, Tracer } from 'opentracing';
|
|
2
|
+
export interface IUserLandTracer {
|
|
3
|
+
traceId: string;
|
|
4
|
+
isTraceSampled: boolean;
|
|
5
|
+
startSpan: Tracer['startSpan'];
|
|
6
|
+
inject: Tracer['inject'];
|
|
7
|
+
fallbackSpanContext: () => SpanContext;
|
|
8
|
+
}
|
|
9
|
+
export declare const createTracingContextFromCarrier: (newSpanName: string, carrier: Record<string, any>) => {
|
|
10
|
+
span: Span;
|
|
11
|
+
tracer: IUserLandTracer;
|
|
12
|
+
};
|
|
13
|
+
export declare class UserLandTracer implements IUserLandTracer {
|
|
14
|
+
private tracer;
|
|
15
|
+
private fallbackSpan;
|
|
16
|
+
private fallbackSpanLock;
|
|
17
|
+
private _isSampled;
|
|
18
|
+
private _traceId;
|
|
19
|
+
constructor(tracer: Tracer, fallbackSpan: Span);
|
|
20
|
+
get traceId(): string;
|
|
21
|
+
get isTraceSampled(): boolean;
|
|
22
|
+
lockFallbackSpan(): void;
|
|
23
|
+
setFallbackSpan(newSpan: Span): void;
|
|
24
|
+
startSpan(name: string, options?: SpanOptions): Span;
|
|
25
|
+
inject(spanContext: SpanContext | Span, format: string, carrier: any): void;
|
|
26
|
+
fallbackSpanContext(): SpanContext;
|
|
27
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const opentracing_1 = require("opentracing");
|
|
4
|
+
const TracerSingleton_1 = require("../service/tracing/TracerSingleton");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
exports.createTracingContextFromCarrier = (newSpanName, carrier) => {
|
|
7
|
+
const tracer = TracerSingleton_1.TracerSingleton.getTracer();
|
|
8
|
+
const rootSpan = tracer.extract(opentracing_1.FORMAT_HTTP_HEADERS, carrier);
|
|
9
|
+
if (rootSpan == null) {
|
|
10
|
+
throw new Error('Missing span context data on carrier');
|
|
11
|
+
}
|
|
12
|
+
const span = tracer.startSpan(newSpanName, { childOf: rootSpan });
|
|
13
|
+
const userlandTracer = new UserLandTracer(tracer, span);
|
|
14
|
+
userlandTracer.lockFallbackSpan();
|
|
15
|
+
return { span, tracer: userlandTracer };
|
|
16
|
+
};
|
|
17
|
+
class UserLandTracer {
|
|
18
|
+
constructor(tracer, fallbackSpan) {
|
|
19
|
+
this.tracer = tracer;
|
|
20
|
+
this.fallbackSpan = fallbackSpan;
|
|
21
|
+
this.fallbackSpanLock = false;
|
|
22
|
+
const { traceId, isSampled } = utils_1.getTraceInfo(fallbackSpan);
|
|
23
|
+
this._traceId = traceId;
|
|
24
|
+
this._isSampled = isSampled;
|
|
25
|
+
}
|
|
26
|
+
get traceId() {
|
|
27
|
+
return this._traceId;
|
|
28
|
+
}
|
|
29
|
+
get isTraceSampled() {
|
|
30
|
+
return this._isSampled;
|
|
31
|
+
}
|
|
32
|
+
lockFallbackSpan() {
|
|
33
|
+
this.fallbackSpanLock = true;
|
|
34
|
+
}
|
|
35
|
+
setFallbackSpan(newSpan) {
|
|
36
|
+
if (this.fallbackSpanLock) {
|
|
37
|
+
throw new Error(`FallbackSpan is locked, can't change it`);
|
|
38
|
+
}
|
|
39
|
+
this.fallbackSpan = newSpan;
|
|
40
|
+
}
|
|
41
|
+
startSpan(name, options) {
|
|
42
|
+
var _a;
|
|
43
|
+
if (options && (options.childOf || ((_a = options.references) === null || _a === void 0 ? void 0 : _a.length))) {
|
|
44
|
+
return this.tracer.startSpan(name, options);
|
|
45
|
+
}
|
|
46
|
+
return this.tracer.startSpan(name, { ...options, childOf: this.fallbackSpan });
|
|
47
|
+
}
|
|
48
|
+
inject(spanContext, format, carrier) {
|
|
49
|
+
return this.tracer.inject(spanContext, format, carrier);
|
|
50
|
+
}
|
|
51
|
+
fallbackSpanContext() {
|
|
52
|
+
return this.fallbackSpan.context();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.UserLandTracer = UserLandTracer;
|