@grafana/faro-transport-otlp-http 2.9.0 → 2.11.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.
Files changed (91) hide show
  1. package/dist/bundle/faro-transport-otlp-http.iife.js +3 -1
  2. package/dist/bundle/faro-transport-otlp-http.iife.js.map +1 -0
  3. package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/asyncToGenerator.js +28 -0
  4. package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/defineProperty.js +13 -0
  5. package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectSpread2.js +26 -0
  6. package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectWithoutProperties.js +14 -0
  7. package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectWithoutPropertiesLoose.js +13 -0
  8. package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPrimitive.js +15 -0
  9. package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPropertyKey.js +10 -0
  10. package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/typeof.js +17 -0
  11. package/dist/cjs/index.js +2 -4
  12. package/dist/cjs/payload/OtelPayload.js +52 -61
  13. package/dist/cjs/payload/OtelPayload.js.map +1 -1
  14. package/dist/cjs/payload/attribute/attributeUtils.js +21 -40
  15. package/dist/cjs/payload/attribute/attributeUtils.js.map +1 -1
  16. package/dist/cjs/payload/attribute/index.js +4 -6
  17. package/dist/cjs/payload/index.js +2 -4
  18. package/dist/cjs/payload/transform/index.js +3 -5
  19. package/dist/cjs/payload/transform/transform.js +185 -169
  20. package/dist/cjs/payload/transform/transform.js.map +1 -1
  21. package/dist/cjs/payload/transform/types.js +0 -1
  22. package/dist/cjs/payload/types.js +0 -1
  23. package/dist/cjs/semconv.js +39 -23
  24. package/dist/cjs/semconv.js.map +1 -1
  25. package/dist/cjs/transport.js +117 -138
  26. package/dist/cjs/transport.js.map +1 -1
  27. package/dist/cjs/types.js +0 -1
  28. package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/asyncToGenerator.js +27 -0
  29. package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/defineProperty.js +12 -0
  30. package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectSpread2.js +25 -0
  31. package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectWithoutProperties.js +13 -0
  32. package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
  33. package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPrimitive.js +14 -0
  34. package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPropertyKey.js +9 -0
  35. package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/typeof.js +11 -0
  36. package/dist/esm/index.js +2 -2
  37. package/dist/esm/payload/OtelPayload.js +53 -60
  38. package/dist/esm/payload/OtelPayload.js.map +1 -1
  39. package/dist/esm/payload/attribute/attributeUtils.js +22 -40
  40. package/dist/esm/payload/attribute/attributeUtils.js.map +1 -1
  41. package/dist/esm/payload/attribute/index.js +2 -2
  42. package/dist/esm/payload/index.js +2 -2
  43. package/dist/esm/payload/transform/index.js +2 -2
  44. package/dist/esm/payload/transform/transform.js +186 -169
  45. package/dist/esm/payload/transform/transform.js.map +1 -1
  46. package/dist/esm/payload/transform/types.js +0 -2
  47. package/dist/esm/payload/types.js +0 -2
  48. package/dist/esm/semconv.js +25 -21
  49. package/dist/esm/semconv.js.map +1 -1
  50. package/dist/esm/transport.js +118 -137
  51. package/dist/esm/transport.js.map +1 -1
  52. package/dist/esm/types.js +0 -2
  53. package/dist/types/index.d.ts +3 -2
  54. package/dist/types/payload/OtelPayload.d.ts +18 -16
  55. package/dist/types/payload/attribute/attributeUtils.d.ts +7 -4
  56. package/dist/types/payload/attribute/index.d.ts +2 -1
  57. package/dist/types/payload/index.d.ts +5 -3
  58. package/dist/types/payload/transform/index.d.ts +3 -2
  59. package/dist/types/payload/transform/transform.d.ts +8 -5
  60. package/dist/types/payload/transform/types.d.ts +45 -42
  61. package/dist/types/payload/types.d.ts +10 -6
  62. package/dist/types/semconv.d.ts +24 -21
  63. package/dist/types/transport.d.ts +19 -17
  64. package/dist/types/types.d.ts +25 -22
  65. package/package.json +8 -16
  66. package/dist/bundle/types/index.d.ts +0 -2
  67. package/dist/bundle/types/payload/OtelPayload.d.ts +0 -19
  68. package/dist/bundle/types/payload/attribute/attributeUtils.d.ts +0 -4
  69. package/dist/bundle/types/payload/attribute/index.d.ts +0 -1
  70. package/dist/bundle/types/payload/index.d.ts +0 -3
  71. package/dist/bundle/types/payload/transform/index.d.ts +0 -2
  72. package/dist/bundle/types/payload/transform/transform.d.ts +0 -5
  73. package/dist/bundle/types/payload/transform/types.d.ts +0 -52
  74. package/dist/bundle/types/payload/types.d.ts +0 -7
  75. package/dist/bundle/types/semconv.d.ts +0 -22
  76. package/dist/bundle/types/transport.d.ts +0 -18
  77. package/dist/bundle/types/types.d.ts +0 -24
  78. package/dist/cjs/index.js.map +0 -1
  79. package/dist/cjs/payload/attribute/index.js.map +0 -1
  80. package/dist/cjs/payload/index.js.map +0 -1
  81. package/dist/cjs/payload/transform/index.js.map +0 -1
  82. package/dist/cjs/payload/transform/types.js.map +0 -1
  83. package/dist/cjs/payload/types.js.map +0 -1
  84. package/dist/cjs/types.js.map +0 -1
  85. package/dist/esm/index.js.map +0 -1
  86. package/dist/esm/payload/attribute/index.js.map +0 -1
  87. package/dist/esm/payload/index.js.map +0 -1
  88. package/dist/esm/payload/transform/index.js.map +0 -1
  89. package/dist/esm/payload/transform/types.js.map +0 -1
  90. package/dist/esm/payload/types.js.map +0 -1
  91. package/dist/esm/types.js.map +0 -1
@@ -1,23 +1,27 @@
1
+ //#region src/semconv.ts
1
2
  /**
2
- Unstable SemConv
3
- Because the "incubating" entry-point may include breaking changes in minor versions,
4
- it is recommended that instrumentation libraries not import @opentelemetry/semantic-conventions/incubating in runtime code,
5
- but instead copy relevant definitions into their own code base. (This is the same recommendation as for other languages.)
6
-
7
- See: https://www.npmjs.com/package/@opentelemetry/semantic-conventions#:~:text=%7D)%3B-,Unstable%20SemConv,-Because%20the%20%22incubating
8
- */
9
- export const ATTR_BROWSER_BRANDS = 'browser.brands';
10
- export const ATTR_BROWSER_LANGUAGE = 'browser.language';
11
- export const ATTR_BROWSER_MOBILE = 'browser.mobile';
12
- export const ATTR_BROWSER_PLATFORM = 'browser.platform';
13
- export const ATTR_DEPLOYMENT_ENVIRONMENT_NAME = 'deployment.environment.name';
14
- export const ATTR_SERVICE_NAMESPACE = 'service.namespace';
15
- export const ATTR_SESSION_ID = 'session.id';
16
- export const ATTR_USER_ATTRIBUTES = 'user.attributes';
17
- export const ATTR_USER_EMAIL = 'user.email';
18
- export const ATTR_USER_FULL_NAME = 'user.full_name';
19
- export const ATTR_USER_HASH = 'user.hash';
20
- export const ATTR_USER_ID = 'user.id';
21
- export const ATTR_USER_NAME = 'user.name';
22
- export const ATTR_USER_ROLES = 'user.roles';
3
+ Unstable SemConv
4
+ Because the "incubating" entry-point may include breaking changes in minor versions,
5
+ it is recommended that instrumentation libraries not import @opentelemetry/semantic-conventions/incubating in runtime code,
6
+ but instead copy relevant definitions into their own code base. (This is the same recommendation as for other languages.)
7
+
8
+ See: https://www.npmjs.com/package/@opentelemetry/semantic-conventions#:~:text=%7D)%3B-,Unstable%20SemConv,-Because%20the%20%22incubating
9
+ */
10
+ const ATTR_BROWSER_BRANDS = "browser.brands";
11
+ const ATTR_BROWSER_LANGUAGE = "browser.language";
12
+ const ATTR_BROWSER_MOBILE = "browser.mobile";
13
+ const ATTR_BROWSER_PLATFORM = "browser.platform";
14
+ const ATTR_DEPLOYMENT_ENVIRONMENT_NAME = "deployment.environment.name";
15
+ const ATTR_SERVICE_NAMESPACE = "service.namespace";
16
+ const ATTR_SESSION_ID = "session.id";
17
+ const ATTR_USER_ATTRIBUTES = "user.attributes";
18
+ const ATTR_USER_EMAIL = "user.email";
19
+ const ATTR_USER_FULL_NAME = "user.full_name";
20
+ const ATTR_USER_HASH = "user.hash";
21
+ const ATTR_USER_ID = "user.id";
22
+ const ATTR_USER_NAME = "user.name";
23
+ const ATTR_USER_ROLES = "user.roles";
24
+ //#endregion
25
+ export { ATTR_BROWSER_BRANDS, ATTR_BROWSER_LANGUAGE, ATTR_BROWSER_MOBILE, ATTR_BROWSER_PLATFORM, ATTR_DEPLOYMENT_ENVIRONMENT_NAME, ATTR_SERVICE_NAMESPACE, ATTR_SESSION_ID, ATTR_USER_ATTRIBUTES, ATTR_USER_EMAIL, ATTR_USER_FULL_NAME, ATTR_USER_HASH, ATTR_USER_ID, ATTR_USER_NAME, ATTR_USER_ROLES };
26
+
23
27
  //# sourceMappingURL=semconv.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AACpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AACxD,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AACpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AACxD,MAAM,CAAC,MAAM,gCAAgC,GAAG,6BAA6B,CAAC;AAC9E,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAC1D,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAC5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC;AAC5C,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AACpD,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAC1C,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAC;AACtC,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAC1C,MAAM,CAAC,MAAM,eAAe,GAAG,YAAY,CAAC","sourcesContent":["/**\n Unstable SemConv\n Because the \"incubating\" entry-point may include breaking changes in minor versions,\n it is recommended that instrumentation libraries not import @opentelemetry/semantic-conventions/incubating in runtime code,\n but instead copy relevant definitions into their own code base. (This is the same recommendation as for other languages.)\n \n See: https://www.npmjs.com/package/@opentelemetry/semantic-conventions#:~:text=%7D)%3B-,Unstable%20SemConv,-Because%20the%20%22incubating\n */\n\nexport const ATTR_BROWSER_BRANDS = 'browser.brands';\nexport const ATTR_BROWSER_LANGUAGE = 'browser.language';\nexport const ATTR_BROWSER_MOBILE = 'browser.mobile';\nexport const ATTR_BROWSER_PLATFORM = 'browser.platform';\nexport const ATTR_DEPLOYMENT_ENVIRONMENT_NAME = 'deployment.environment.name';\nexport const ATTR_SERVICE_NAMESPACE = 'service.namespace';\nexport const ATTR_SESSION_ID = 'session.id';\nexport const ATTR_USER_ATTRIBUTES = 'user.attributes';\nexport const ATTR_USER_EMAIL = 'user.email';\nexport const ATTR_USER_FULL_NAME = 'user.full_name';\nexport const ATTR_USER_HASH = 'user.hash';\nexport const ATTR_USER_ID = 'user.id';\nexport const ATTR_USER_NAME = 'user.name';\nexport const ATTR_USER_ROLES = 'user.roles';\n"]}
1
+ {"version":3,"file":"semconv.js","names":[],"sources":["../../src/semconv.ts"],"sourcesContent":["/**\n Unstable SemConv\n Because the \"incubating\" entry-point may include breaking changes in minor versions,\n it is recommended that instrumentation libraries not import @opentelemetry/semantic-conventions/incubating in runtime code,\n but instead copy relevant definitions into their own code base. (This is the same recommendation as for other languages.)\n \n See: https://www.npmjs.com/package/@opentelemetry/semantic-conventions#:~:text=%7D)%3B-,Unstable%20SemConv,-Because%20the%20%22incubating\n */\n\nexport const ATTR_BROWSER_BRANDS = 'browser.brands';\nexport const ATTR_BROWSER_LANGUAGE = 'browser.language';\nexport const ATTR_BROWSER_MOBILE = 'browser.mobile';\nexport const ATTR_BROWSER_PLATFORM = 'browser.platform';\nexport const ATTR_DEPLOYMENT_ENVIRONMENT_NAME = 'deployment.environment.name';\nexport const ATTR_SERVICE_NAMESPACE = 'service.namespace';\nexport const ATTR_SESSION_ID = 'session.id';\nexport const ATTR_USER_ATTRIBUTES = 'user.attributes';\nexport const ATTR_USER_EMAIL = 'user.email';\nexport const ATTR_USER_FULL_NAME = 'user.full_name';\nexport const ATTR_USER_HASH = 'user.hash';\nexport const ATTR_USER_ID = 'user.id';\nexport const ATTR_USER_NAME = 'user.name';\nexport const ATTR_USER_ROLES = 'user.roles';\n"],"mappings":";;;;;;;;;AASA,MAAa,sBAAsB;AACnC,MAAa,wBAAwB;AACrC,MAAa,sBAAsB;AACnC,MAAa,wBAAwB;AACrC,MAAa,mCAAmC;AAChD,MAAa,yBAAyB;AACtC,MAAa,kBAAkB;AAC/B,MAAa,uBAAuB;AACpC,MAAa,kBAAkB;AAC/B,MAAa,sBAAsB;AACnC,MAAa,iBAAiB;AAC9B,MAAa,eAAe;AAC5B,MAAa,iBAAiB;AAC9B,MAAa,kBAAkB"}
@@ -1,140 +1,121 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
- import { BaseTransport, createPromiseBuffer, isArray, noop, VERSION } from '@grafana/faro-core';
22
- import { OtelPayload } from './payload';
1
+ import _objectSpread2 from "./_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectSpread2.js";
2
+ import { OtelPayload } from "./payload/OtelPayload.js";
3
+ import "./payload/index.js";
4
+ import _asyncToGenerator from "./_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/asyncToGenerator.js";
5
+ import _objectWithoutProperties from "./_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectWithoutProperties.js";
6
+ import { BaseTransport, VERSION, createPromiseBuffer, isArray, noop } from "@grafana/faro-core";
7
+ //#region src/transport.ts
8
+ const _excluded = ["headers"];
23
9
  const DEFAULT_BUFFER_SIZE = 30;
24
- const DEFAULT_CONCURRENCY = 5; // chrome supports 10 total, firefox 17
25
- const DEFAULT_RATE_LIMIT_BACKOFF_MS = 5000;
26
- const BEACON_BODY_SIZE_LIMIT = 60000;
10
+ const DEFAULT_CONCURRENCY = 5;
11
+ const DEFAULT_RATE_LIMIT_BACKOFF_MS = 5e3;
12
+ const BEACON_BODY_SIZE_LIMIT = 6e4;
27
13
  const TOO_MANY_REQUESTS = 429;
28
- export class OtlpHttpTransport extends BaseTransport {
29
- constructor(options) {
30
- var _a, _b, _c;
31
- super();
32
- this.options = options;
33
- this.name = '@grafana/faro-web-sdk:transport-otlp-http';
34
- this.version = VERSION;
35
- this.sendingTracesDisabledUntil = new Date();
36
- this.sendingLogsDisabledUntil = new Date();
37
- this.rateLimitBackoffMs = (_a = options.defaultRateLimitBackoffMs) !== null && _a !== void 0 ? _a : DEFAULT_RATE_LIMIT_BACKOFF_MS;
38
- this.promiseBuffer = createPromiseBuffer({
39
- size: (_b = options === null || options === void 0 ? void 0 : options.bufferSize) !== null && _b !== void 0 ? _b : DEFAULT_BUFFER_SIZE,
40
- concurrency: (_c = options === null || options === void 0 ? void 0 : options.concurrency) !== null && _c !== void 0 ? _c : DEFAULT_CONCURRENCY,
41
- });
42
- }
43
- getIgnoreUrls() {
44
- var _a;
45
- const { tracesURL = '', logsURL = '' } = this.options;
46
- return [tracesURL, logsURL].filter(Boolean).concat((_a = this.config.ignoreUrls) !== null && _a !== void 0 ? _a : []);
47
- }
48
- isBatched() {
49
- return true;
50
- }
51
- send(items) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const otelPayload = new OtelPayload({
54
- internalLogger: this.internalLogger,
55
- customOtlpTransform: this.options.otlpTransform,
56
- });
57
- items.forEach((item) => otelPayload.addResourceItem(item));
58
- yield this.sendPayload(otelPayload.getPayload());
59
- });
60
- }
61
- sendPayload(payload) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- try {
64
- const { tracesURL = '', logsURL = '' } = this.options;
65
- for (const [key, value] of Object.entries(payload)) {
66
- if (!(isArray(value) && value.length > 0)) {
67
- continue;
68
- }
69
- let disabledUntil;
70
- let updateDisabledUntil = (_) => { };
71
- let url = '';
72
- switch (key) {
73
- case 'resourceSpans':
74
- url = tracesURL;
75
- disabledUntil = this.sendingTracesDisabledUntil;
76
- updateDisabledUntil = (retryAfterDate) => {
77
- this.sendingTracesDisabledUntil = retryAfterDate;
78
- };
79
- break;
80
- case 'resourceLogs':
81
- url = logsURL;
82
- disabledUntil = this.sendingLogsDisabledUntil;
83
- updateDisabledUntil = (retryAfterDate) => {
84
- this.sendingLogsDisabledUntil = retryAfterDate;
85
- };
86
- break;
87
- }
88
- if (disabledUntil && disabledUntil > new Date(Date.now())) {
89
- this.logWarn(`Dropping transport item due to too many requests. Backoff until ${disabledUntil}`);
90
- return undefined;
91
- }
92
- const body = JSON.stringify({ [key]: value });
93
- const { requestOptions, apiKey } = this.options;
94
- const _a = requestOptions !== null && requestOptions !== void 0 ? requestOptions : {}, { headers = {} } = _a, restOfRequestOptions = __rest(_a, ["headers"]);
95
- if (!url) {
96
- continue;
97
- }
98
- yield this.promiseBuffer.add(() => __awaiter(this, void 0, void 0, function* () {
99
- const resolvedHeaders = {};
100
- for (const [key, value] of Object.entries(headers)) {
101
- resolvedHeaders[key] = typeof value === 'function' ? yield Promise.resolve(value()) : value;
102
- }
103
- return fetch(url, Object.assign({ method: 'POST', headers: Object.assign(Object.assign({ 'Content-Type': 'application/json' }, resolvedHeaders), (apiKey ? { 'x-api-key': apiKey } : {})), body, keepalive: body.length <= BEACON_BODY_SIZE_LIMIT }, (restOfRequestOptions !== null && restOfRequestOptions !== void 0 ? restOfRequestOptions : {})))
104
- .then((response) => {
105
- if (response.status === TOO_MANY_REQUESTS) {
106
- updateDisabledUntil(this.getRetryAfterDate(response));
107
- this.logWarn(`Too many requests, backing off until ${disabledUntil}`);
108
- }
109
- // read the body so the connection can be closed
110
- response.text().catch(noop);
111
- return response;
112
- })
113
- .catch((error) => {
114
- this.logError('Failed sending payload to the receiver\n', JSON.parse(body), error);
115
- });
116
- }));
117
- }
118
- }
119
- catch (error) {
120
- this.logError(error);
121
- }
122
- });
123
- }
124
- getRetryAfterDate(response) {
125
- const now = Date.now();
126
- const retryAfterHeader = response.headers.get('Retry-After');
127
- if (retryAfterHeader) {
128
- const delay = Number(retryAfterHeader);
129
- if (!isNaN(delay)) {
130
- return new Date(delay * 1000 + now);
131
- }
132
- const date = Date.parse(retryAfterHeader);
133
- if (!isNaN(date)) {
134
- return new Date(date);
135
- }
136
- }
137
- return new Date(now + this.rateLimitBackoffMs);
138
- }
139
- }
14
+ var OtlpHttpTransport = class extends BaseTransport {
15
+ constructor(options) {
16
+ var _options$defaultRateL, _options$bufferSize, _options$concurrency;
17
+ super();
18
+ this.options = options;
19
+ this.name = "@grafana/faro-web-sdk:transport-otlp-http";
20
+ this.version = VERSION;
21
+ this.sendingTracesDisabledUntil = /* @__PURE__ */ new Date();
22
+ this.sendingLogsDisabledUntil = /* @__PURE__ */ new Date();
23
+ this.rateLimitBackoffMs = (_options$defaultRateL = options.defaultRateLimitBackoffMs) !== null && _options$defaultRateL !== void 0 ? _options$defaultRateL : DEFAULT_RATE_LIMIT_BACKOFF_MS;
24
+ this.promiseBuffer = createPromiseBuffer({
25
+ size: (_options$bufferSize = options === null || options === void 0 ? void 0 : options.bufferSize) !== null && _options$bufferSize !== void 0 ? _options$bufferSize : DEFAULT_BUFFER_SIZE,
26
+ concurrency: (_options$concurrency = options === null || options === void 0 ? void 0 : options.concurrency) !== null && _options$concurrency !== void 0 ? _options$concurrency : DEFAULT_CONCURRENCY
27
+ });
28
+ }
29
+ getIgnoreUrls() {
30
+ var _this$config$ignoreUr;
31
+ const { tracesURL = "", logsURL = "" } = this.options;
32
+ return [tracesURL, logsURL].filter(Boolean).concat((_this$config$ignoreUr = this.config.ignoreUrls) !== null && _this$config$ignoreUr !== void 0 ? _this$config$ignoreUr : []);
33
+ }
34
+ isBatched() {
35
+ return true;
36
+ }
37
+ send(items) {
38
+ var _this = this;
39
+ return _asyncToGenerator(function* () {
40
+ const otelPayload = new OtelPayload({
41
+ internalLogger: _this.internalLogger,
42
+ customOtlpTransform: _this.options.otlpTransform
43
+ });
44
+ items.forEach((item) => otelPayload.addResourceItem(item));
45
+ yield _this.sendPayload(otelPayload.getPayload());
46
+ })();
47
+ }
48
+ sendPayload(payload) {
49
+ var _this2 = this;
50
+ return _asyncToGenerator(function* () {
51
+ try {
52
+ const { tracesURL = "", logsURL = "" } = _this2.options;
53
+ for (const [key, value] of Object.entries(payload)) {
54
+ if (!(isArray(value) && value.length > 0)) continue;
55
+ let disabledUntil;
56
+ let updateDisabledUntil = (_) => {};
57
+ let url = "";
58
+ switch (key) {
59
+ case "resourceSpans":
60
+ url = tracesURL;
61
+ disabledUntil = _this2.sendingTracesDisabledUntil;
62
+ updateDisabledUntil = (retryAfterDate) => {
63
+ _this2.sendingTracesDisabledUntil = retryAfterDate;
64
+ };
65
+ break;
66
+ case "resourceLogs":
67
+ url = logsURL;
68
+ disabledUntil = _this2.sendingLogsDisabledUntil;
69
+ updateDisabledUntil = (retryAfterDate) => {
70
+ _this2.sendingLogsDisabledUntil = retryAfterDate;
71
+ };
72
+ }
73
+ if (disabledUntil && disabledUntil > new Date(Date.now())) {
74
+ _this2.logWarn(`Dropping transport item due to too many requests. Backoff until ${disabledUntil}`);
75
+ return;
76
+ }
77
+ const body = JSON.stringify({ [key]: value });
78
+ const { requestOptions, apiKey } = _this2.options;
79
+ const _ref = requestOptions !== null && requestOptions !== void 0 ? requestOptions : {}, { headers = {} } = _ref, restOfRequestOptions = _objectWithoutProperties(_ref, _excluded);
80
+ if (!url) continue;
81
+ yield _this2.promiseBuffer.add(_asyncToGenerator(function* () {
82
+ const resolvedHeaders = {};
83
+ for (const [key, value] of Object.entries(headers)) resolvedHeaders[key] = typeof value === "function" ? yield Promise.resolve(value()) : value;
84
+ return fetch(url, _objectSpread2({
85
+ method: "POST",
86
+ headers: _objectSpread2(_objectSpread2({ "Content-Type": "application/json" }, resolvedHeaders), apiKey ? { "x-api-key": apiKey } : {}),
87
+ body,
88
+ keepalive: body.length <= BEACON_BODY_SIZE_LIMIT
89
+ }, restOfRequestOptions !== null && restOfRequestOptions !== void 0 ? restOfRequestOptions : {})).then((response) => {
90
+ if (response.status === TOO_MANY_REQUESTS) {
91
+ updateDisabledUntil(_this2.getRetryAfterDate(response));
92
+ _this2.logWarn(`Too many requests, backing off until ${disabledUntil}`);
93
+ }
94
+ response.text().catch(noop);
95
+ return response;
96
+ }).catch((error) => {
97
+ _this2.logError("Failed sending payload to the receiver\n", JSON.parse(body), error);
98
+ });
99
+ }));
100
+ }
101
+ } catch (error) {
102
+ _this2.logError(error);
103
+ }
104
+ })();
105
+ }
106
+ getRetryAfterDate(response) {
107
+ const now = Date.now();
108
+ const retryAfterHeader = response.headers.get("Retry-After");
109
+ if (retryAfterHeader) {
110
+ const delay = Number(retryAfterHeader);
111
+ if (!isNaN(delay)) return new Date(delay * 1e3 + now);
112
+ const date = Date.parse(retryAfterHeader);
113
+ if (!isNaN(date)) return new Date(date);
114
+ }
115
+ return new Date(now + this.rateLimitBackoffMs);
116
+ }
117
+ };
118
+ //#endregion
119
+ export { OtlpHttpTransport };
120
+
140
121
  //# sourceMappingURL=transport.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGhG,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAIxC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,mBAAmB,GAAG,CAAC,CAAC,CAAC,uCAAuC;AACtE,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAE3C,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAE9B,MAAM,OAAO,iBAAkB,SAAQ,aAAa;IAUlD,YAAoB,OAAiC;;QACnD,KAAK,EAAE,CAAC;QADU,YAAO,GAAP,OAAO,CAA0B;QAT5C,SAAI,GAAG,2CAA2C,CAAC;QACnD,YAAO,GAAG,OAAO,CAAC;QAKnB,+BAA0B,GAAS,IAAI,IAAI,EAAE,CAAC;QAC9C,6BAAwB,GAAS,IAAI,IAAI,EAAE,CAAC;QAIlD,IAAI,CAAC,kBAAkB,GAAG,MAAA,OAAO,CAAC,yBAAyB,mCAAI,6BAA6B,CAAC;QAE7F,IAAI,CAAC,aAAa,GAAG,mBAAmB,CAAC;YACvC,IAAI,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,mCAAI,mBAAmB;YAChD,WAAW,EAAE,MAAA,OAAO,aAAP,OAAO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,CAAC;gBACf,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;KAAA;IAEO,iBAAiB,CAAC,QAAkB;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAE7D,IAAI,gBAAgB,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;YAEvC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBAClB,OAAO,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC;YACtC,CAAC;YAED,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YAE1C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjB,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QAED,OAAO,IAAI,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;IACjD,CAAC;CACF","sourcesContent":["import { BaseTransport, createPromiseBuffer, isArray, noop, VERSION } from '@grafana/faro-core';\nimport type { Patterns, PromiseBuffer, TransportItem } from '@grafana/faro-core';\n\nimport { OtelPayload } from './payload';\nimport type { OtelTransportPayload } from './payload';\nimport type { OtlpHttpTransportOptions } from './types';\n\nconst DEFAULT_BUFFER_SIZE = 30;\nconst DEFAULT_CONCURRENCY = 5; // chrome supports 10 total, firefox 17\nconst DEFAULT_RATE_LIMIT_BACKOFF_MS = 5000;\n\nconst BEACON_BODY_SIZE_LIMIT = 60000;\nconst TOO_MANY_REQUESTS = 429;\n\nexport class OtlpHttpTransport extends BaseTransport {\n readonly name = '@grafana/faro-web-sdk:transport-otlp-http';\n readonly version = VERSION;\n\n private readonly promiseBuffer: PromiseBuffer<Response | void>;\n private readonly rateLimitBackoffMs: number;\n\n private sendingTracesDisabledUntil: Date = new Date();\n private sendingLogsDisabledUntil: Date = new Date();\n\n constructor(private options: OtlpHttpTransportOptions) {\n super();\n this.rateLimitBackoffMs = options.defaultRateLimitBackoffMs ?? DEFAULT_RATE_LIMIT_BACKOFF_MS;\n\n this.promiseBuffer = createPromiseBuffer({\n size: options?.bufferSize ?? DEFAULT_BUFFER_SIZE,\n concurrency: options?.concurrency ?? DEFAULT_CONCURRENCY,\n });\n }\n\n override getIgnoreUrls(): Patterns {\n const { tracesURL = '', logsURL = '' } = this.options;\n return ([tracesURL, logsURL].filter(Boolean) as Patterns).concat(this.config.ignoreUrls ?? []);\n }\n\n override isBatched(): boolean {\n return true;\n }\n\n async send(items: TransportItem[]): Promise<void> {\n const otelPayload = new OtelPayload({\n internalLogger: this.internalLogger,\n customOtlpTransform: this.options.otlpTransform,\n });\n\n items.forEach((item) => otelPayload.addResourceItem(item));\n await this.sendPayload(otelPayload.getPayload());\n }\n\n private async sendPayload(payload: OtelTransportPayload): Promise<void> {\n try {\n const { tracesURL = '', logsURL = '' } = this.options;\n\n for (const [key, value] of Object.entries(payload)) {\n if (!(isArray(value) && value.length > 0)) {\n continue;\n }\n\n let disabledUntil: Date | undefined;\n let updateDisabledUntil = (_: Date) => {};\n let url = '';\n\n switch (key) {\n case 'resourceSpans':\n url = tracesURL;\n disabledUntil = this.sendingTracesDisabledUntil;\n updateDisabledUntil = (retryAfterDate: Date) => {\n this.sendingTracesDisabledUntil = retryAfterDate;\n };\n break;\n case 'resourceLogs':\n url = logsURL;\n disabledUntil = this.sendingLogsDisabledUntil;\n updateDisabledUntil = (retryAfterDate: Date) => {\n this.sendingLogsDisabledUntil = retryAfterDate;\n };\n break;\n }\n\n if (disabledUntil && disabledUntil > new Date(Date.now())) {\n this.logWarn(`Dropping transport item due to too many requests. Backoff until ${disabledUntil}`);\n return undefined;\n }\n\n const body = JSON.stringify({ [key]: value });\n\n const { requestOptions, apiKey } = this.options;\n const { headers = {}, ...restOfRequestOptions } = requestOptions ?? {};\n\n if (!url) {\n continue;\n }\n\n await this.promiseBuffer.add(async () => {\n const resolvedHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n resolvedHeaders[key] = typeof value === 'function' ? await Promise.resolve(value()) : value;\n }\n\n return fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...resolvedHeaders,\n ...(apiKey ? { 'x-api-key': apiKey } : {}),\n },\n body,\n keepalive: body.length <= BEACON_BODY_SIZE_LIMIT,\n ...(restOfRequestOptions ?? {}),\n })\n .then((response) => {\n if (response.status === TOO_MANY_REQUESTS) {\n updateDisabledUntil(this.getRetryAfterDate(response));\n this.logWarn(`Too many requests, backing off until ${disabledUntil}`);\n }\n\n // read the body so the connection can be closed\n response.text().catch(noop);\n return response;\n })\n .catch((error) => {\n this.logError('Failed sending payload to the receiver\\n', JSON.parse(body), error);\n });\n });\n }\n } catch (error) {\n this.logError(error);\n }\n }\n\n private getRetryAfterDate(response: Response): Date {\n const now = Date.now();\n const retryAfterHeader = response.headers.get('Retry-After');\n\n if (retryAfterHeader) {\n const delay = Number(retryAfterHeader);\n\n if (!isNaN(delay)) {\n return new Date(delay * 1000 + now);\n }\n\n const date = Date.parse(retryAfterHeader);\n\n if (!isNaN(date)) {\n return new Date(date);\n }\n }\n\n return new Date(now + this.rateLimitBackoffMs);\n }\n}\n"]}
1
+ {"version":3,"file":"transport.js","names":["this"],"sources":["../../src/transport.ts"],"sourcesContent":["import { BaseTransport, createPromiseBuffer, isArray, noop, VERSION } from '@grafana/faro-core';\nimport type { Patterns, PromiseBuffer, TransportItem } from '@grafana/faro-core';\n\nimport { OtelPayload } from './payload';\nimport type { OtelTransportPayload } from './payload';\nimport type { OtlpHttpTransportOptions } from './types';\n\nconst DEFAULT_BUFFER_SIZE = 30;\nconst DEFAULT_CONCURRENCY = 5; // chrome supports 10 total, firefox 17\nconst DEFAULT_RATE_LIMIT_BACKOFF_MS = 5000;\n\nconst BEACON_BODY_SIZE_LIMIT = 60000;\nconst TOO_MANY_REQUESTS = 429;\n\nexport class OtlpHttpTransport extends BaseTransport {\n readonly name = '@grafana/faro-web-sdk:transport-otlp-http';\n readonly version: string = VERSION;\n\n private readonly promiseBuffer: PromiseBuffer<Response | void>;\n private readonly rateLimitBackoffMs: number;\n\n private sendingTracesDisabledUntil: Date = new Date();\n private sendingLogsDisabledUntil: Date = new Date();\n\n constructor(private options: OtlpHttpTransportOptions) {\n super();\n this.rateLimitBackoffMs = options.defaultRateLimitBackoffMs ?? DEFAULT_RATE_LIMIT_BACKOFF_MS;\n\n this.promiseBuffer = createPromiseBuffer({\n size: options?.bufferSize ?? DEFAULT_BUFFER_SIZE,\n concurrency: options?.concurrency ?? DEFAULT_CONCURRENCY,\n });\n }\n\n override getIgnoreUrls(): Patterns {\n const { tracesURL = '', logsURL = '' } = this.options;\n return ([tracesURL, logsURL].filter(Boolean) as Patterns).concat(this.config.ignoreUrls ?? []);\n }\n\n override isBatched(): boolean {\n return true;\n }\n\n async send(items: TransportItem[]): Promise<void> {\n const otelPayload = new OtelPayload({\n internalLogger: this.internalLogger,\n customOtlpTransform: this.options.otlpTransform,\n });\n\n items.forEach((item) => otelPayload.addResourceItem(item));\n await this.sendPayload(otelPayload.getPayload());\n }\n\n private async sendPayload(payload: OtelTransportPayload): Promise<void> {\n try {\n const { tracesURL = '', logsURL = '' } = this.options;\n\n for (const [key, value] of Object.entries(payload)) {\n if (!(isArray(value) && value.length > 0)) {\n continue;\n }\n\n let disabledUntil: Date | undefined;\n let updateDisabledUntil = (_: Date) => {};\n let url = '';\n\n switch (key) {\n case 'resourceSpans':\n url = tracesURL;\n disabledUntil = this.sendingTracesDisabledUntil;\n updateDisabledUntil = (retryAfterDate: Date) => {\n this.sendingTracesDisabledUntil = retryAfterDate;\n };\n break;\n case 'resourceLogs':\n url = logsURL;\n disabledUntil = this.sendingLogsDisabledUntil;\n updateDisabledUntil = (retryAfterDate: Date) => {\n this.sendingLogsDisabledUntil = retryAfterDate;\n };\n break;\n }\n\n if (disabledUntil && disabledUntil > new Date(Date.now())) {\n this.logWarn(`Dropping transport item due to too many requests. Backoff until ${disabledUntil}`);\n return undefined;\n }\n\n const body = JSON.stringify({ [key]: value });\n\n const { requestOptions, apiKey } = this.options;\n const { headers = {}, ...restOfRequestOptions } = requestOptions ?? {};\n\n if (!url) {\n continue;\n }\n\n await this.promiseBuffer.add(async () => {\n const resolvedHeaders: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n resolvedHeaders[key] = typeof value === 'function' ? await Promise.resolve(value()) : value;\n }\n\n return fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...resolvedHeaders,\n ...(apiKey ? { 'x-api-key': apiKey } : {}),\n },\n body,\n keepalive: body.length <= BEACON_BODY_SIZE_LIMIT,\n ...(restOfRequestOptions ?? {}),\n })\n .then((response) => {\n if (response.status === TOO_MANY_REQUESTS) {\n updateDisabledUntil(this.getRetryAfterDate(response));\n this.logWarn(`Too many requests, backing off until ${disabledUntil}`);\n }\n\n // read the body so the connection can be closed\n response.text().catch(noop);\n return response;\n })\n .catch((error) => {\n this.logError('Failed sending payload to the receiver\\n', JSON.parse(body), error);\n });\n });\n }\n } catch (error) {\n this.logError(error);\n }\n }\n\n private getRetryAfterDate(response: Response): Date {\n const now = Date.now();\n const retryAfterHeader = response.headers.get('Retry-After');\n\n if (retryAfterHeader) {\n const delay = Number(retryAfterHeader);\n\n if (!isNaN(delay)) {\n return new Date(delay * 1000 + now);\n }\n\n const date = Date.parse(retryAfterHeader);\n\n if (!isNaN(date)) {\n return new Date(date);\n }\n }\n\n return new Date(now + this.rateLimitBackoffMs);\n }\n}\n"],"mappings":";;;;;;;AA2FgB,MAAA,YAAA,CAAA,SAAA;AApFhB,MAAM,sBAAsB;AAC5B,MAAM,sBAAsB;AAC5B,MAAM,gCAAgC;AAEtC,MAAM,yBAAyB;AAC/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QACpD,OAAK,QAAQ,wCAAwC,eAAe;OACtE;OAGA,SAAS,KAAK,CAAC,CAAC,MAAM,IAAI;OAC1B,OAAO;MACT,CAAC,CAAC,CACD,OAAO,UAAU;OAChB,OAAK,SAAS,4CAA4C,KAAK,MAAM,IAAI,GAAG,KAAK;MACnF,CAAC;KACL,CAAA,CAAC;IACH;GACF,SAAS,OAAO;IACd,OAAK,SAAS,KAAK;GACrB;EACF,CAAA,CAAA,CAAA;;CAEA,kBAA0B,UAA0B;EAClD,MAAM,MAAM,KAAK,IAAI;EACrB,MAAM,mBAAmB,SAAS,QAAQ,IAAI,aAAa;EAE3D,IAAI,kBAAkB;GACpB,MAAM,QAAQ,OAAO,gBAAgB;GAErC,IAAI,CAAC,MAAM,KAAK,GACd,OAAO,IAAI,KAAK,QAAQ,MAAO,GAAG;GAGpC,MAAM,OAAO,KAAK,MAAM,gBAAgB;GAExC,IAAI,CAAC,MAAM,IAAI,GACb,OAAO,IAAI,KAAK,IAAI;EAExB;EAEA,OAAO,IAAI,KAAK,MAAM,KAAK,kBAAkB;CAC/C;AACF"}
package/dist/esm/types.js CHANGED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1,2 +1,3 @@
1
- export { OtlpHttpTransport } from './transport';
2
- export type { OtlpHttpTransportOptions, OtlpTransportRequestOptions } from './types';
1
+ import { OtlpHttpTransportOptions, OtlpTransportRequestOptions } from "./types.js";
2
+ import { OtlpHttpTransport } from "./transport.js";
3
+ export { OtlpHttpTransport, type OtlpHttpTransportOptions, type OtlpTransportRequestOptions };
@@ -1,19 +1,21 @@
1
- import type { InternalLogger, TransportItem } from '@grafana/faro-core';
2
- import type { OtlpHttpTransportOptions } from '../types';
3
- import type { OtelTransportPayload } from './types';
1
+ import { OtlpHttpTransportOptions } from "../types.js";
2
+ import { OtelTransportPayload } from "./types.js";
3
+ import { InternalLogger, TransportItem } from "@grafana/faro-core";
4
+ //#region src/payload/OtelPayload.d.ts
4
5
  type OtelPayloadParams = {
5
- internalLogger: InternalLogger;
6
- transportItem?: TransportItem;
7
- customOtlpTransform?: OtlpHttpTransportOptions['otlpTransform'];
6
+ internalLogger: InternalLogger;
7
+ transportItem?: TransportItem;
8
+ customOtlpTransform?: OtlpHttpTransportOptions["otlpTransform"];
8
9
  };
9
- export declare class OtelPayload {
10
- private resourceLogs;
11
- private resourceSpans;
12
- private getLogTransforms;
13
- private getTraceTransforms;
14
- private internalLogger;
15
- constructor({ internalLogger, customOtlpTransform, transportItem }: OtelPayloadParams);
16
- getPayload(): OtelTransportPayload;
17
- addResourceItem(transportItem: TransportItem): void;
10
+ declare class OtelPayload {
11
+ private resourceLogs;
12
+ private resourceSpans;
13
+ private getLogTransforms;
14
+ private getTraceTransforms;
15
+ private internalLogger;
16
+ constructor({ internalLogger, customOtlpTransform, transportItem }: OtelPayloadParams);
17
+ getPayload(): OtelTransportPayload;
18
+ addResourceItem(transportItem: TransportItem): void;
18
19
  }
19
- export {};
20
+ //#endregion
21
+ export { OtelPayload };
@@ -1,4 +1,7 @@
1
- import type { IAnyValue, IKeyValue } from '@opentelemetry/otlp-transformer/build/src/common/internal-types';
2
- export declare function toAttributeValue(value: unknown): IAnyValue;
3
- export declare function toAttribute(attributeName: string, attributeValue: any): IKeyValue | undefined;
4
- export declare function isAttribute(item: any): item is IKeyValue;
1
+ import { IAnyValue, IKeyValue } from "@opentelemetry/otlp-transformer/build/src/common/internal-types";
2
+ //#region src/payload/attribute/attributeUtils.d.ts
3
+ declare function toAttributeValue(value: unknown): IAnyValue;
4
+ declare function toAttribute(attributeName: string, attributeValue: any): IKeyValue | undefined;
5
+ declare function isAttribute(item: any): item is IKeyValue;
6
+ //#endregion
7
+ export { isAttribute, toAttribute, toAttributeValue };
@@ -1 +1,2 @@
1
- export { toAttribute, toAttributeValue, isAttribute } from './attributeUtils';
1
+ import { isAttribute, toAttribute, toAttributeValue } from "./attributeUtils.js";
2
+ export { isAttribute, toAttribute, toAttributeValue };
@@ -1,3 +1,5 @@
1
- export { OtelPayload } from './OtelPayload';
2
- export type { LogRecord, LogTransportItem, Resource, ResourceLog, ResourceLogs, Scope, ScopeLog, } from './transform/index';
3
- export type { Logs, OtelTransportPayload, Traces } from './types';
1
+ import { LogRecord, LogTransportItem, Resource, ResourceLog, ResourceLogs, Scope, ScopeLog } from "./transform/types.js";
2
+ import "./transform/index.js";
3
+ import { Logs, OtelTransportPayload, Traces } from "./types.js";
4
+ import { OtelPayload } from "./OtelPayload.js";
5
+ export { type LogRecord, type LogTransportItem, type Logs, OtelPayload, type OtelTransportPayload, type Resource, type ResourceLog, type ResourceLogs, type Scope, type ScopeLog, type Traces };
@@ -1,2 +1,3 @@
1
- export { getLogTransforms, getTraceTransforms } from './transform';
2
- export type { LogRecord, LogTransportItem, ResourceLogs, LogsTransform, Resource, ResourceLog, ResourceSpan, ResourceSpans, Scope, ScopeLog, TraceTransform, StringValueNonNullable, } from './types';
1
+ import { LogRecord, LogTransportItem, LogsTransform, Resource, ResourceLog, ResourceLogs, ResourceSpan, ResourceSpans, Scope, ScopeLog, StringValueNonNullable, TraceTransform } from "./types.js";
2
+ import { getLogTransforms, getTraceTransforms } from "./transform.js";
3
+ export { type LogRecord, type LogTransportItem, type LogsTransform, type Resource, type ResourceLog, type ResourceLogs, type ResourceSpan, type ResourceSpans, type Scope, type ScopeLog, type StringValueNonNullable, type TraceTransform, getLogTransforms, getTraceTransforms };
@@ -1,5 +1,8 @@
1
- import type { InternalLogger } from '@grafana/faro-core';
2
- import type { OtlpHttpTransportOptions } from '../../types';
3
- import type { LogsTransform, TraceTransform } from './types';
4
- export declare function getLogTransforms(internalLogger: InternalLogger, customOtlpTransform?: OtlpHttpTransportOptions['otlpTransform']): LogsTransform;
5
- export declare function getTraceTransforms(_internalLogger?: InternalLogger): TraceTransform;
1
+ import { OtlpHttpTransportOptions } from "../../types.js";
2
+ import { LogsTransform, TraceTransform } from "./types.js";
3
+ import { InternalLogger } from "@grafana/faro-core";
4
+ //#region src/payload/transform/transform.d.ts
5
+ declare function getLogTransforms(internalLogger: InternalLogger, customOtlpTransform?: OtlpHttpTransportOptions["otlpTransform"]): LogsTransform;
6
+ declare function getTraceTransforms(_internalLogger?: InternalLogger): TraceTransform;
7
+ //#endregion
8
+ export { getLogTransforms, getTraceTransforms };
@@ -1,52 +1,55 @@
1
- import type { IKeyValue, Resource as OtelResource } from '@opentelemetry/otlp-transformer/build/src/common/internal-types';
2
- import type { IResourceSpans } from '@opentelemetry/otlp-transformer/build/src/trace/internal-types';
3
- import type { APIEvent, Meta, TraceEvent, TransportItem } from '@grafana/faro-core';
4
- export interface Resource extends Partial<Pick<OtelResource, 'droppedAttributesCount'>> {
5
- attributes: IKeyValue[];
1
+ import { APIEvent, Meta, TraceEvent, TransportItem } from "@grafana/faro-core";
2
+ import { IKeyValue, Resource as Resource$1 } from "@opentelemetry/otlp-transformer/build/src/common/internal-types";
3
+ import { IResourceSpans } from "@opentelemetry/otlp-transformer/build/src/trace/internal-types";
4
+ //#region src/payload/transform/types.d.ts
5
+ interface Resource extends Partial<Pick<Resource$1, "droppedAttributesCount">> {
6
+ attributes: IKeyValue[];
6
7
  }
7
- export interface LogRecord {
8
- timeUnixNano?: number;
9
- severityNumber?: number;
10
- severityText?: string;
11
- body?: {
12
- stringValue: string;
13
- };
14
- attributes?: IKeyValue[];
15
- traceId?: string;
16
- spanId?: string;
8
+ interface LogRecord {
9
+ timeUnixNano?: number;
10
+ severityNumber?: number;
11
+ severityText?: string;
12
+ body?: {
13
+ stringValue: string;
14
+ };
15
+ attributes?: IKeyValue[];
16
+ traceId?: string;
17
+ spanId?: string;
17
18
  }
18
- export type Scope = {
19
- name: string;
20
- version: string;
19
+ type Scope = {
20
+ name: string;
21
+ version: string;
21
22
  };
22
- export interface ScopeLog {
23
- scope: Scope;
24
- logRecords: LogRecord[];
23
+ interface ScopeLog {
24
+ scope: Scope;
25
+ logRecords: LogRecord[];
25
26
  }
26
- export interface ScopeSpan {
27
- scope: Scope;
28
- logRecords: LogRecord[];
27
+ interface ScopeSpan {
28
+ scope: Scope;
29
+ logRecords: LogRecord[];
29
30
  }
30
- export interface ResourceLog {
31
- resource: Resource;
32
- scopeLogs: ScopeLog[];
31
+ interface ResourceLog {
32
+ resource: Resource;
33
+ scopeLogs: ScopeLog[];
33
34
  }
34
- export type ResourceLogs = ResourceLog[];
35
- export interface ResourceSpan extends Omit<IResourceSpans, 'resource'> {
36
- resource: Resource;
35
+ type ResourceLogs = ResourceLog[];
36
+ interface ResourceSpan extends Omit<IResourceSpans, "resource"> {
37
+ resource: Resource;
37
38
  }
38
- export type ResourceSpans = ResourceSpan[];
39
- export type LogTransportItem = TransportItem<Exclude<APIEvent, 'TraceEvent'>>;
40
- export type TraceTransportItem = TransportItem<TraceEvent>;
41
- export type LogsTransform = {
42
- toResourceLog: (transportItem: LogTransportItem) => ResourceLog;
43
- toScopeLog: (transportItem: LogTransportItem) => ScopeLog;
44
- toLogRecord: (transportItem: LogTransportItem) => LogRecord;
39
+ type ResourceSpans = ResourceSpan[];
40
+ type LogTransportItem = TransportItem<Exclude<APIEvent, "TraceEvent">>;
41
+ type TraceTransportItem = TransportItem<TraceEvent>;
42
+ type LogsTransform = {
43
+ toResourceLog: (transportItem: LogTransportItem) => ResourceLog;
44
+ toScopeLog: (transportItem: LogTransportItem) => ScopeLog;
45
+ toLogRecord: (transportItem: LogTransportItem) => LogRecord;
45
46
  };
46
- export type TraceTransform = {
47
- toResourceSpan: (transportItem: TransportItem<TraceEvent>) => ResourceSpan;
47
+ type TraceTransform = {
48
+ toResourceSpan: (transportItem: TransportItem<TraceEvent>) => ResourceSpan;
48
49
  };
49
- export type ResourceMeta = Pick<Meta, 'app' | 'browser' | 'sdk'>;
50
- export type StringValueNonNullable = {
51
- stringValue: string;
50
+ type ResourceMeta = Pick<Meta, "app" | "browser" | "sdk">;
51
+ type StringValueNonNullable = {
52
+ stringValue: string;
52
53
  };
54
+ //#endregion
55
+ export { LogRecord, LogTransportItem, LogsTransform, Resource, ResourceLog, ResourceLogs, ResourceMeta, ResourceSpan, ResourceSpans, Scope, ScopeLog, ScopeSpan, StringValueNonNullable, TraceTransform, TraceTransportItem };
@@ -1,7 +1,11 @@
1
- import type { ResourceLogs, ResourceSpans } from './transform';
2
- export interface OtelTransportPayload {
3
- readonly resourceLogs: Readonly<ResourceLogs>;
4
- readonly resourceSpans: Readonly<ResourceSpans>;
1
+ import { ResourceLogs, ResourceSpans } from "./transform/types.js";
2
+ import "./transform/index.js";
3
+ //#region src/payload/types.d.ts
4
+ interface OtelTransportPayload {
5
+ readonly resourceLogs: Readonly<ResourceLogs>;
6
+ readonly resourceSpans: Readonly<ResourceSpans>;
5
7
  }
6
- export type Logs = Pick<OtelTransportPayload, 'resourceLogs'>;
7
- export type Traces = Pick<OtelTransportPayload, 'resourceSpans'>;
8
+ type Logs = Pick<OtelTransportPayload, "resourceLogs">;
9
+ type Traces = Pick<OtelTransportPayload, "resourceSpans">;
10
+ //#endregion
11
+ export { Logs, OtelTransportPayload, Traces };