package.build.esm.metrics.envelope.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
Base implementation for all Sentry JavaScript SDKs
{"version":3,"file":"envelope.js","sources":["../../../src/metrics/envelope.ts"],"sourcesContent":["import type { Client, DsnComponents, MetricBucketItem, SdkMetadata, StatsdEnvelope, StatsdItem } from '@sentry/types';\nimport { createEnvelope, dsnToString, logger } from '@sentry/utils';\nimport { serializeMetricBuckets } from './utils';\n\n/**\n * Captures aggregated metrics to the supplied client.\n */\nexport function captureAggregateMetrics(client: Client, metricBucketItems: Array): void {\n logger.log(`Flushing aggregated metrics, number of metrics: ${metricBucketItems.length}`);\n const dsn = client.getDsn();\n const metadata = client.getSdkMetadata();\n const tunnel = client.getOptions().tunnel;\n\n const metricsEnvelope = createMetricEnvelope(metricBucketItems, dsn, metadata, tunnel);\n\n // sendEnvelope should not throw\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n client.sendEnvelope(metricsEnvelope);\n}\n\n/**\n * Create envelope from a metric aggregate.\n */\nexport function createMetricEnvelope(\n metricBucketItems: Array,\n dsn?: DsnComponents,\n metadata?: SdkMetadata,\n tunnel?: string,\n): StatsdEnvelope {\n const headers: StatsdEnvelope[0] = {\n sent_at: new Date().toISOString(),\n };\n\n if (metadata && metadata.sdk) {\n headers.sdk = {\n name: metadata.sdk.name,\n version: metadata.sdk.version,\n };\n }\n\n if (!!tunnel && dsn) {\n headers.dsn = dsnToString(dsn);\n }\n\n const item = createMetricEnvelopeItem(metricBucketItems);\n return createEnvelope(headers, [item]);\n}\n\nfunction createMetricEnvelopeItem(metricBucketItems: MetricBucketItem[]): StatsdItem {\n const payload = serializeMetricBuckets(metricBucketItems);\n const metricHeaders: StatsdItem[0] = {\n type: 'statsd',\n length: payload.length,\n };\n return [metricHeaders, payload];\n}\n"],"names":[],"mappings":";;;AAIA;AACA;AACA;AACO,SAAS,uBAAuB,CAAC,MAAM,EAAU,iBAAiB,EAAi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