@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.
- package/dist/bundle/faro-transport-otlp-http.iife.js +3 -1
- package/dist/bundle/faro-transport-otlp-http.iife.js.map +1 -0
- package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/asyncToGenerator.js +28 -0
- package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/defineProperty.js +13 -0
- package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectSpread2.js +26 -0
- package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectWithoutProperties.js +14 -0
- package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectWithoutPropertiesLoose.js +13 -0
- package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPrimitive.js +15 -0
- package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPropertyKey.js +10 -0
- package/dist/cjs/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/typeof.js +17 -0
- package/dist/cjs/index.js +2 -4
- package/dist/cjs/payload/OtelPayload.js +52 -61
- package/dist/cjs/payload/OtelPayload.js.map +1 -1
- package/dist/cjs/payload/attribute/attributeUtils.js +21 -40
- package/dist/cjs/payload/attribute/attributeUtils.js.map +1 -1
- package/dist/cjs/payload/attribute/index.js +4 -6
- package/dist/cjs/payload/index.js +2 -4
- package/dist/cjs/payload/transform/index.js +3 -5
- package/dist/cjs/payload/transform/transform.js +185 -169
- package/dist/cjs/payload/transform/transform.js.map +1 -1
- package/dist/cjs/payload/transform/types.js +0 -1
- package/dist/cjs/payload/types.js +0 -1
- package/dist/cjs/semconv.js +39 -23
- package/dist/cjs/semconv.js.map +1 -1
- package/dist/cjs/transport.js +117 -138
- package/dist/cjs/transport.js.map +1 -1
- package/dist/cjs/types.js +0 -1
- package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/asyncToGenerator.js +27 -0
- package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/defineProperty.js +12 -0
- package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectSpread2.js +25 -0
- package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectWithoutProperties.js +13 -0
- package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
- package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPrimitive.js +14 -0
- package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/toPropertyKey.js +9 -0
- package/dist/esm/_virtual/_@oxc-project_runtime@0.143.0/helpers/esm/typeof.js +11 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/payload/OtelPayload.js +53 -60
- package/dist/esm/payload/OtelPayload.js.map +1 -1
- package/dist/esm/payload/attribute/attributeUtils.js +22 -40
- package/dist/esm/payload/attribute/attributeUtils.js.map +1 -1
- package/dist/esm/payload/attribute/index.js +2 -2
- package/dist/esm/payload/index.js +2 -2
- package/dist/esm/payload/transform/index.js +2 -2
- package/dist/esm/payload/transform/transform.js +186 -169
- package/dist/esm/payload/transform/transform.js.map +1 -1
- package/dist/esm/payload/transform/types.js +0 -2
- package/dist/esm/payload/types.js +0 -2
- package/dist/esm/semconv.js +25 -21
- package/dist/esm/semconv.js.map +1 -1
- package/dist/esm/transport.js +118 -137
- package/dist/esm/transport.js.map +1 -1
- package/dist/esm/types.js +0 -2
- package/dist/types/index.d.ts +3 -2
- package/dist/types/payload/OtelPayload.d.ts +18 -16
- package/dist/types/payload/attribute/attributeUtils.d.ts +7 -4
- package/dist/types/payload/attribute/index.d.ts +2 -1
- package/dist/types/payload/index.d.ts +5 -3
- package/dist/types/payload/transform/index.d.ts +3 -2
- package/dist/types/payload/transform/transform.d.ts +8 -5
- package/dist/types/payload/transform/types.d.ts +45 -42
- package/dist/types/payload/types.d.ts +10 -6
- package/dist/types/semconv.d.ts +24 -21
- package/dist/types/transport.d.ts +19 -17
- package/dist/types/types.d.ts +25 -22
- package/package.json +8 -16
- package/dist/bundle/types/index.d.ts +0 -2
- package/dist/bundle/types/payload/OtelPayload.d.ts +0 -19
- package/dist/bundle/types/payload/attribute/attributeUtils.d.ts +0 -4
- package/dist/bundle/types/payload/attribute/index.d.ts +0 -1
- package/dist/bundle/types/payload/index.d.ts +0 -3
- package/dist/bundle/types/payload/transform/index.d.ts +0 -2
- package/dist/bundle/types/payload/transform/transform.d.ts +0 -5
- package/dist/bundle/types/payload/transform/types.d.ts +0 -52
- package/dist/bundle/types/payload/types.d.ts +0 -7
- package/dist/bundle/types/semconv.d.ts +0 -22
- package/dist/bundle/types/transport.d.ts +0 -18
- package/dist/bundle/types/types.d.ts +0 -24
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/payload/attribute/index.js.map +0 -1
- package/dist/cjs/payload/index.js.map +0 -1
- package/dist/cjs/payload/transform/index.js.map +0 -1
- package/dist/cjs/payload/transform/types.js.map +0 -1
- package/dist/cjs/payload/types.js.map +0 -1
- package/dist/cjs/types.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/payload/attribute/index.js.map +0 -1
- package/dist/esm/payload/index.js.map +0 -1
- package/dist/esm/payload/transform/index.js.map +0 -1
- package/dist/esm/payload/transform/types.js.map +0 -1
- package/dist/esm/payload/types.js.map +0 -1
- package/dist/esm/types.js.map +0 -1
package/dist/esm/semconv.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
+
//#region src/semconv.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
package/dist/esm/semconv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semconv.js","
|
|
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"}
|
package/dist/esm/transport.js
CHANGED
|
@@ -1,140 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
25
|
-
const DEFAULT_RATE_LIMIT_BACKOFF_MS =
|
|
26
|
-
const BEACON_BODY_SIZE_LIMIT =
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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","
|
|
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/B,MAAM,oBAAoB;AAE1B,IAAa,oBAAb,cAAuC,cAAc;CAUnD,YAAY,SAA2C;;EACrD,MAAM;EADY,KAAA,UAAA;EATpB,KAAS,OAAO;EAChB,KAAS,UAAkB;EAK3B,KAAQ,6CAAmC,IAAI,KAAK;EACpD,KAAQ,2CAAiC,IAAI,KAAK;EAIhD,KAAK,sBAAA,wBAAqB,QAAQ,+BAAA,QAAA,0BAAA,KAAA,IAAA,wBAA6B;EAE/D,KAAK,gBAAgB,oBAAoB;GACvC,OAAA,sBAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAM,QAAS,gBAAA,QAAA,wBAAA,KAAA,IAAA,sBAAc;GAC7B,cAAA,uBAAA,YAAA,QAAA,YAAA,KAAA,IAAA,KAAA,IAAa,QAAS,iBAAA,QAAA,yBAAA,KAAA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AGpC,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
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
internalLogger: InternalLogger;
|
|
7
|
+
transportItem?: TransportItem;
|
|
8
|
+
customOtlpTransform?: OtlpHttpTransportOptions["otlpTransform"];
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
20
|
+
//#endregion
|
|
21
|
+
export { OtelPayload };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
1
|
+
import { isAttribute, toAttribute, toAttributeValue } from "./attributeUtils.js";
|
|
2
|
+
export { isAttribute, toAttribute, toAttributeValue };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
type Scope = {
|
|
20
|
+
name: string;
|
|
21
|
+
version: string;
|
|
21
22
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
interface ScopeLog {
|
|
24
|
+
scope: Scope;
|
|
25
|
+
logRecords: LogRecord[];
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
interface ScopeSpan {
|
|
28
|
+
scope: Scope;
|
|
29
|
+
logRecords: LogRecord[];
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
interface ResourceLog {
|
|
32
|
+
resource: Resource;
|
|
33
|
+
scopeLogs: ScopeLog[];
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
type ResourceLogs = ResourceLog[];
|
|
36
|
+
interface ResourceSpan extends Omit<IResourceSpans, "resource"> {
|
|
37
|
+
resource: Resource;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
47
|
-
|
|
47
|
+
type TraceTransform = {
|
|
48
|
+
toResourceSpan: (transportItem: TransportItem<TraceEvent>) => ResourceSpan;
|
|
48
49
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
+
type Logs = Pick<OtelTransportPayload, "resourceLogs">;
|
|
9
|
+
type Traces = Pick<OtelTransportPayload, "resourceSpans">;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { Logs, OtelTransportPayload, Traces };
|