envelope.js 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const utils = require('@sentry/utils');
  3. const utils$1 = require('./utils.js');
  4. /**
  5. * Create envelope from a metric aggregate.
  6. */
  7. function createMetricEnvelope(
  8. metricBucketItems,
  9. dsn,
  10. metadata,
  11. tunnel,
  12. ) {
  13. const headers = {
  14. sent_at: new Date().toISOString(),
  15. };
  16. if (metadata && metadata.sdk) {
  17. headers.sdk = {
  18. name: metadata.sdk.name,
  19. version: metadata.sdk.version,
  20. };
  21. }
  22. if (!!tunnel && dsn) {
  23. headers.dsn = utils.dsnToString(dsn);
  24. }
  25. const item = createMetricEnvelopeItem(metricBucketItems);
  26. return utils.createEnvelope(headers, [item]);
  27. }
  28. function createMetricEnvelopeItem(metricBucketItems) {
  29. const payload = utils$1.serializeMetricBuckets(metricBucketItems);
  30. const metricHeaders = {
  31. type: 'statsd',
  32. length: payload.length,
  33. };
  34. return [metricHeaders, payload];
  35. }
  36. exports.createMetricEnvelope = createMetricEnvelope;
  37. //# sourceMappingURL=envelope.js.map