@dxos/observability 0.8.4-main.cb12b3f963 → 0.8.4-main.d05539e30a

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 (73) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/browser/{chunk-3534PNWM.mjs → chunk-PSFTIG54.mjs} +9 -2
  3. package/dist/lib/browser/chunk-PSFTIG54.mjs.map +7 -0
  4. package/dist/lib/browser/index.mjs +68 -44
  5. package/dist/lib/browser/index.mjs.map +3 -3
  6. package/dist/lib/browser/{logs-A2VDAHHD.mjs → logs-UTNIFYHF.mjs} +4 -3
  7. package/dist/lib/browser/logs-UTNIFYHF.mjs.map +7 -0
  8. package/dist/lib/browser/meta.json +1 -1
  9. package/dist/lib/browser/{metrics-6OSN54ZV.mjs → metrics-PRGSYAZJ.mjs} +4 -3
  10. package/dist/lib/browser/metrics-PRGSYAZJ.mjs.map +7 -0
  11. package/dist/lib/browser/{traces-browser-6MRGAKFC.mjs → traces-browser-XRINKQUA.mjs} +7 -4
  12. package/dist/lib/browser/traces-browser-XRINKQUA.mjs.map +7 -0
  13. package/dist/lib/node-esm/{chunk-SYPJQI4L.mjs → chunk-EDDZWPYV.mjs} +9 -2
  14. package/dist/lib/node-esm/chunk-EDDZWPYV.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +68 -44
  16. package/dist/lib/node-esm/index.mjs.map +3 -3
  17. package/dist/lib/node-esm/{logs-TA32MBMW.mjs → logs-ARJUVN3T.mjs} +4 -3
  18. package/dist/lib/node-esm/logs-ARJUVN3T.mjs.map +7 -0
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/{metrics-C5IKPAWD.mjs → metrics-DREJOOAC.mjs} +4 -3
  21. package/dist/lib/node-esm/metrics-DREJOOAC.mjs.map +7 -0
  22. package/dist/lib/node-esm/{traces-5LKHMVVG.mjs → traces-74F7JUKF.mjs} +7 -4
  23. package/dist/lib/node-esm/traces-74F7JUKF.mjs.map +7 -0
  24. package/dist/types/src/extensions/otel/extension.d.ts.map +1 -1
  25. package/dist/types/src/extensions/otel/extension.js +29 -10
  26. package/dist/types/src/extensions/otel/extension.js.map +1 -1
  27. package/dist/types/src/extensions/otel/logs.d.ts.map +1 -1
  28. package/dist/types/src/extensions/otel/logs.js +2 -2
  29. package/dist/types/src/extensions/otel/logs.js.map +1 -1
  30. package/dist/types/src/extensions/otel/metrics.d.ts.map +1 -1
  31. package/dist/types/src/extensions/otel/metrics.js +2 -2
  32. package/dist/types/src/extensions/otel/metrics.js.map +1 -1
  33. package/dist/types/src/extensions/otel/otel.d.ts +7 -0
  34. package/dist/types/src/extensions/otel/otel.d.ts.map +1 -1
  35. package/dist/types/src/extensions/otel/otel.js +12 -0
  36. package/dist/types/src/extensions/otel/otel.js.map +1 -1
  37. package/dist/types/src/extensions/otel/traces-browser.d.ts.map +1 -1
  38. package/dist/types/src/extensions/otel/traces-browser.js +2 -1
  39. package/dist/types/src/extensions/otel/traces-browser.js.map +1 -1
  40. package/dist/types/src/extensions/otel/traces.d.ts.map +1 -1
  41. package/dist/types/src/extensions/otel/traces.js +2 -1
  42. package/dist/types/src/extensions/otel/traces.js.map +1 -1
  43. package/dist/types/src/extensions/posthog/extension.d.ts +6 -0
  44. package/dist/types/src/extensions/posthog/extension.d.ts.map +1 -1
  45. package/dist/types/src/extensions/posthog/extension.js +33 -21
  46. package/dist/types/src/extensions/posthog/extension.js.map +1 -1
  47. package/dist/types/src/observability-extension.d.ts +1 -1
  48. package/dist/types/src/observability-extension.d.ts.map +1 -1
  49. package/dist/types/src/observability.d.ts.map +1 -1
  50. package/dist/types/src/observability.js +4 -2
  51. package/dist/types/src/observability.js.map +1 -1
  52. package/dist/types/src/observability.test.js +1 -1
  53. package/dist/types/src/observability.test.js.map +1 -1
  54. package/dist/types/tsconfig.tsbuildinfo +1 -1
  55. package/package.json +33 -33
  56. package/src/extensions/otel/extension.ts +31 -10
  57. package/src/extensions/otel/logs.ts +2 -2
  58. package/src/extensions/otel/metrics.ts +2 -2
  59. package/src/extensions/otel/otel.ts +13 -0
  60. package/src/extensions/otel/traces-browser.ts +2 -2
  61. package/src/extensions/otel/traces.ts +2 -2
  62. package/src/extensions/posthog/extension.ts +38 -20
  63. package/src/observability-extension.ts +1 -1
  64. package/src/observability.test.ts +1 -1
  65. package/src/observability.ts +4 -2
  66. package/dist/lib/browser/chunk-3534PNWM.mjs.map +0 -7
  67. package/dist/lib/browser/logs-A2VDAHHD.mjs.map +0 -7
  68. package/dist/lib/browser/metrics-6OSN54ZV.mjs.map +0 -7
  69. package/dist/lib/browser/traces-browser-6MRGAKFC.mjs.map +0 -7
  70. package/dist/lib/node-esm/chunk-SYPJQI4L.mjs.map +0 -7
  71. package/dist/lib/node-esm/logs-TA32MBMW.mjs.map +0 -7
  72. package/dist/lib/node-esm/metrics-C5IKPAWD.mjs.map +0 -7
  73. package/dist/lib/node-esm/traces-5LKHMVVG.mjs.map +0 -7
package/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2023 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -6,8 +6,15 @@ var setDiagLogger = (level) => {
6
6
  diag.setLogger(new DiagConsoleLogger(), logLevel);
7
7
  }
8
8
  };
9
+ var resolveOtlpUrl = (url) => {
10
+ if (typeof window !== "undefined" && url.startsWith("/")) {
11
+ return new URL(url, window.location.origin).toString();
12
+ }
13
+ return url;
14
+ };
9
15
 
10
16
  export {
11
- setDiagLogger
17
+ setDiagLogger,
18
+ resolveOtlpUrl
12
19
  };
13
- //# sourceMappingURL=chunk-3534PNWM.mjs.map
20
+ //# sourceMappingURL=chunk-PSFTIG54.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/extensions/otel/otel.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api';\nimport { type Resource } from '@opentelemetry/resources';\n\nexport type OtelOptions = {\n endpoint: string;\n headers: Record<string, string>;\n resource: Resource;\n getTags: () => { [key: string]: string };\n consoleDiagLogLevel?: string;\n};\n\nexport const setDiagLogger = (level?: string) => {\n const logLevel = DiagLogLevel[level as keyof typeof DiagLogLevel];\n if (logLevel) {\n diag.setLogger(new DiagConsoleLogger(), logLevel);\n }\n};\n\n/**\n * Resolve a possibly-relative OTLP exporter URL to an absolute URL.\n * The OpenTelemetry browser HTTP exporter validates user-provided URLs with `new URL(url)`,\n * which throws on relative paths like `/api/otel/v1/logs`. In a browser context we resolve\n * against `window.location.origin`; outside the browser we return the input unchanged.\n */\nexport const resolveOtlpUrl = (url: string): string => {\n if (typeof window !== 'undefined' && url.startsWith('/')) {\n return new URL(url, window.location.origin).toString();\n }\n return url;\n};\n"],
5
+ "mappings": ";AAIA,SAASA,mBAAmBC,cAAcC,YAAY;AAW/C,IAAMC,gBAAgB,CAACC,UAAAA;AAC5B,QAAMC,WAAWJ,aAAaG,KAAAA;AAC9B,MAAIC,UAAU;AACZH,SAAKI,UAAU,IAAIN,kBAAAA,GAAqBK,QAAAA;EAC1C;AACF;AAQO,IAAME,iBAAiB,CAACC,QAAAA;AAC7B,MAAI,OAAOC,WAAW,eAAeD,IAAIE,WAAW,GAAA,GAAM;AACxD,WAAO,IAAIC,IAAIH,KAAKC,OAAOG,SAASC,MAAM,EAAEC,SAAQ;EACtD;AACA,SAAON;AACT;",
6
+ "names": ["DiagConsoleLogger", "DiagLogLevel", "diag", "setDiagLogger", "level", "logLevel", "setLogger", "resolveOtlpUrl", "url", "window", "startsWith", "URL", "location", "origin", "toString"]
7
+ }
@@ -204,10 +204,12 @@ var ObservabilityImpl = class {
204
204
  }
205
205
  get feedback() {
206
206
  return {
207
- captureUserFeedback: (form) => {
207
+ captureUserFeedback: async (form) => {
208
+ let eventUuid;
208
209
  for (const extension of this._getExtensions("feedback")) {
209
- extension.captureUserFeedback(form);
210
+ eventUuid = await extension.captureUserFeedback(form) ?? eventUuid;
210
211
  }
212
+ return eventUuid;
211
213
  }
212
214
  };
213
215
  }
@@ -253,13 +255,13 @@ var make = () => Effect.succeed(new ObservabilityImpl());
253
255
  var addExtension = (_extension) => Effect.fn(function* (_observability) {
254
256
  const observability = yield* _observability;
255
257
  const extension = yield* _extension;
256
- invariant("_addExtension" in observability && typeof observability._addExtension === "function", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 194, S: this, A: ["'_addExtension' in observability && typeof observability._addExtension === 'function'", ""] });
258
+ invariant("_addExtension" in observability && typeof observability._addExtension === "function", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 196, S: this, A: ["'_addExtension' in observability && typeof observability._addExtension === 'function'", ""] });
257
259
  observability._addExtension(extension);
258
260
  return observability;
259
261
  });
260
262
  var addDataProvider = (dataProvider) => Effect.fn(function* (_observability) {
261
263
  const observability = yield* _observability;
262
- invariant("_addDataProvider" in observability && typeof observability._addDataProvider === "function", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 200, S: this, A: ["'_addDataProvider' in observability && typeof observability._addDataProvider === 'function'", ""] });
264
+ invariant("_addDataProvider" in observability && typeof observability._addDataProvider === "function", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 202, S: this, A: ["'_addDataProvider' in observability && typeof observability._addDataProvider === 'function'", ""] });
263
265
  observability._addDataProvider(dataProvider);
264
266
  return observability;
265
267
  });
@@ -333,19 +335,22 @@ var extensions = Effect3.fn(function* ({
333
335
  metrics: metricsEnabled = false,
334
336
  traces: tracesEnabled = false
335
337
  }) {
336
- const { OtelLogs } = yield* Effect3.promise(() => import("./logs-A2VDAHHD.mjs"));
337
- const { OtelMetrics } = yield* Effect3.promise(() => import("./metrics-6OSN54ZV.mjs"));
338
- const { OtelTraces } = yield* Effect3.promise(() => import("./traces-browser-6MRGAKFC.mjs"));
338
+ const { OtelLogs } = yield* Effect3.promise(() => import("./logs-UTNIFYHF.mjs"));
339
+ const { OtelMetrics } = yield* Effect3.promise(() => import("./metrics-PRGSYAZJ.mjs"));
340
+ const { OtelTraces } = yield* Effect3.promise(() => import("./traces-browser-XRINKQUA.mjs"));
339
341
  const cachedDisabled = yield* Effect3.promise(() => isObservabilityDisabled(serviceName));
340
342
  const disabled = cachedDisabled || isObservabilityDisabledSync(serviceName);
341
343
  const enabledRef = yield* Ref.make(!disabled);
342
344
  const tags = /* @__PURE__ */ new Map();
343
- const endpoint = isNode() ? process.env.DX_OTEL_ENDPOINT ?? _endpoint ?? cli_observability_secrets_default.OTEL_ENDPOINT : config.values.runtime?.app?.env?.DX_OTEL_ENDPOINT;
345
+ const rawEndpoint = isNode() ? process.env.DX_OTEL_ENDPOINT ?? _endpoint ?? cli_observability_secrets_default.OTEL_ENDPOINT : config.values.runtime?.app?.env?.DX_OTEL_ENDPOINT ?? _endpoint;
346
+ const endpoint = !isNode() && rawEndpoint?.startsWith("/") ? resolveRelativeEndpoint(rawEndpoint) : rawEndpoint;
344
347
  const headers = _headers ?? Match.value(isNode()).pipe(Match.when(true, () => Option.fromNullable(process.env.DX_OTEL_HEADERS ?? cli_observability_secrets_default.OTEL_HEADERS)), Match.when(false, () => Option.fromNullable(config.values.runtime?.app?.env?.DX_OTEL_HEADERS)), Match.exhaustive, Option.map((raw) => parseHeaders(raw)), Option.getOrElse(() => void 0));
345
- if (!endpoint || !headers) {
346
- log3.info("Missing OTEL_ENDPOINT or OTEL_HEADERS", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 31, S: this });
348
+ if (!endpoint) {
349
+ log3.info("Missing OTEL_ENDPOINT", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 35, S: this });
347
350
  return stubExtension;
348
351
  }
352
+ const resolvedHeaders = headers ?? {};
353
+ const resolvedEndpoint = !isNode() && endpoint.startsWith("/") ? `${globalThis.location.origin}${endpoint}` : endpoint;
349
354
  const clientTag = resolveTelemetryTag(config);
350
355
  if (clientTag) {
351
356
  tags.set("ctx.tag", clientTag);
@@ -361,21 +366,21 @@ var extensions = Effect3.fn(function* ({
361
366
  } : {}
362
367
  }));
363
368
  const logs = logsEnabled ? new OtelLogs({
364
- endpoint,
365
- headers,
369
+ endpoint: resolvedEndpoint,
370
+ headers: resolvedHeaders,
366
371
  resource,
367
372
  getTags: () => Object.fromEntries(tags),
368
373
  logLevel
369
374
  }) : void 0;
370
375
  const metrics = metricsEnabled ? new OtelMetrics({
371
- endpoint,
372
- headers,
376
+ endpoint: resolvedEndpoint,
377
+ headers: resolvedHeaders,
373
378
  resource,
374
379
  getTags: () => Object.fromEntries(tags)
375
380
  }) : void 0;
376
381
  const traces = tracesEnabled ? new OtelTraces({
377
- endpoint,
378
- headers,
382
+ endpoint: resolvedEndpoint,
383
+ headers: resolvedHeaders,
379
384
  resource,
380
385
  getTags: () => Object.fromEntries(tags)
381
386
  }) : void 0;
@@ -406,7 +411,7 @@ var extensions = Effect3.fn(function* ({
406
411
  ]);
407
412
  for (const result of results) {
408
413
  if (result.status === "rejected") {
409
- log3.catch(result.reason, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 111, S: this });
414
+ log3.catch(result.reason, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 120, S: this });
410
415
  }
411
416
  }
412
417
  await traces?.close();
@@ -418,7 +423,7 @@ var extensions = Effect3.fn(function* ({
418
423
  ]);
419
424
  for (const result of results) {
420
425
  if (result.status === "rejected") {
421
- log3.catch(result.reason, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 126, S: this });
426
+ log3.catch(result.reason, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 135, S: this });
422
427
  }
423
428
  }
424
429
  await traces?.flush();
@@ -478,6 +483,10 @@ var detectProcessType = () => {
478
483
  }
479
484
  return "dedicated-worker";
480
485
  };
486
+ var resolveRelativeEndpoint = (path) => {
487
+ const origin = globalThis.location?.origin;
488
+ return origin ? `${origin}${path}` : path;
489
+ };
481
490
  var parseHeaders = (unparsedHeaders) => {
482
491
  return unparsedHeaders.split(";").reduce((acc, header) => {
483
492
  const [key, ...rest] = header.split(":");
@@ -522,7 +531,7 @@ var uploadLogs = async (body) => {
522
531
  return void 0;
523
532
  }
524
533
  };
525
- var extensions2 = Effect4.fn(function* ({ config, release, environment, posthog: posthogConfig, logStore }) {
534
+ var extensions2 = Effect4.fn(function* ({ config, release, environment, posthog: posthogConfig, logStore, feedbackLogMaxSize }) {
526
535
  if (typeof window === "undefined") {
527
536
  log4("PostHog is being stubbed because it is running in a worker.", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 33, S: this });
528
537
  return stubExtension;
@@ -611,32 +620,47 @@ var extensions2 = Effect4.fn(function* ({ config, release, environment, posthog:
611
620
  kind: "feedback",
612
621
  // TODO(wittjosiah): Support custom surveys.
613
622
  captureUserFeedback: (form) => {
614
- posthog.getSurveys(async (surveys) => {
615
- const survey = surveys.find((survey2) => survey2.id === feedbackSurveyId);
616
- if (!survey || survey.questions.length === 0) {
617
- log4.error("Missing feedback survey or survey has no questions", {
618
- feedbackSurveyId
619
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 124, S: this });
620
- return;
621
- }
622
- let debugLogDumpKey = null;
623
- if (form.includeLogs !== false && logStore !== void 0) {
624
- const ndjson = await logStore.export();
625
- if (ndjson.length > 0) {
626
- debugLogDumpKey = await uploadLogs(ndjson) ?? "failed";
627
- }
628
- }
629
- const question = survey.questions[0];
630
- posthog.capture("survey sent", {
631
- $survey_id: survey.id,
632
- $survey_questions: [
633
- {
634
- id: question.id,
635
- question: question.question
623
+ return new Promise((resolve, reject) => {
624
+ posthog.getSurveys((surveys) => {
625
+ void (async () => {
626
+ try {
627
+ const survey = surveys.find((survey2) => survey2.id === feedbackSurveyId);
628
+ if (!survey || survey.questions.length === 0) {
629
+ log4.error("Missing feedback survey or survey has no questions", {
630
+ feedbackSurveyId
631
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 127, S: this });
632
+ resolve(void 0);
633
+ return;
634
+ }
635
+ let debugLogDumpKey = null;
636
+ if (form.includeLogs !== false && logStore !== void 0) {
637
+ const ndjson = await logStore.export({
638
+ maxSize: feedbackLogMaxSize
639
+ });
640
+ if (ndjson.length > 0) {
641
+ debugLogDumpKey = await uploadLogs(ndjson) ?? "failed";
642
+ }
643
+ }
644
+ const question = survey.questions[0];
645
+ const result = posthog.capture("survey sent", {
646
+ $survey_id: survey.id,
647
+ $survey_questions: [
648
+ {
649
+ id: question.id,
650
+ question: question.question
651
+ }
652
+ ],
653
+ [`$survey_response_${question.id}`]: form.message,
654
+ debug_log_dump_key: debugLogDumpKey
655
+ });
656
+ resolve(result?.uuid);
657
+ } catch (err) {
658
+ log4.error("Failed to capture user feedback", {
659
+ err
660
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 157, S: this });
661
+ reject(err);
636
662
  }
637
- ],
638
- [`$survey_response_${question.id}`]: form.message,
639
- debug_log_dump_key: debugLogDumpKey
663
+ })();
640
664
  });
641
665
  });
642
666
  },