@sailfish-ai/recorder 1.8.10 → 1.8.12-alpha-2

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/README.md CHANGED
@@ -7,3 +7,5 @@
7
7
  ## Trigger build - 06112025 0854PM GMT+4
8
8
 
9
9
  ## Trigger build - 11182025 1125AM GMT+4
10
+
11
+ ## Trigger build - 02122025 0330PM GMT+4
package/dist/graphql.js CHANGED
@@ -42,6 +42,13 @@ export function fetchCaptureSettings(apiKey, backendApi) {
42
42
  }
43
43
  `, { apiKey, backendApi });
44
44
  }
45
+ export function fetchFunctionSpanTrackingEnabled(apiKey, backendApi) {
46
+ return sendGraphQLRequest("GetFunctionSpanTrackingEnabledFromApiKey", `
47
+ query GetFunctionSpanTrackingEnabledFromApiKey($apiKey: String!) {
48
+ isFunctionSpanTrackingEnabledFromApiKey(apiKey: $apiKey)
49
+ }
50
+ `, { apiKey, backendApi });
51
+ }
45
52
  export function startRecordingSession(apiKey, recordingId, backendApi, serviceIdentifier, serviceVersion, mapUuid, gitSha, library, serviceAdditionalMetadata) {
46
53
  // These must be sent as None/Null for now (not user-provided)
47
54
  const startRecordingFilePath = null;
package/dist/index.js CHANGED
@@ -5,14 +5,14 @@ import { NetworkRequestEventId, STATIC_EXTENSIONS, xSf3RidHeader, } from "./cons
5
5
  import { gatherAndCacheDeviceInfo } from "./deviceInfo";
6
6
  import { readGitSha } from "./env";
7
7
  import { initializeErrorInterceptor } from "./errorInterceptor";
8
- import { fetchCaptureSettings, sendDomainsToNotPropagateHeaderTo, startRecordingSession, } from "./graphql";
8
+ import { fetchCaptureSettings, fetchFunctionSpanTrackingEnabled, sendDomainsToNotPropagateHeaderTo, startRecordingSession, } from "./graphql";
9
9
  import { setupIssueReporting } from "./inAppReportIssueModal";
10
10
  import { sendMapUuidIfAvailable } from "./mapUuid";
11
11
  import { getUrlAndStoredUuids, initializeConsolePlugin, initializeDomContentEvents, initializeRecording, } from "./recording";
12
12
  import { HAS_DOCUMENT, HAS_LOCAL_STORAGE, HAS_SESSION_STORAGE, HAS_WINDOW, } from "./runtimeEnv";
13
13
  import { getOrSetSessionId } from "./session";
14
14
  import { withAppUrlMetadata } from "./utils";
15
- import { getFuncSpanHeader, sendEvent, sendMessage } from "./websocket";
15
+ import { clearStaleFuncSpanState, getFuncSpanHeader, isFunctionSpanTrackingEnabled, sendEvent, sendMessage, } from "./websocket";
16
16
  const DEBUG = readDebugFlag(); // A wrapper around fetch that suppresses connection refused errors
17
17
  // Default list of domains to ignore
18
18
  const DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT = [
@@ -455,8 +455,8 @@ function setupXMLHttpRequestInterceptor(domainsToNotPropagateHeaderTo = []) {
455
455
  const allHeaders = this.getAllResponseHeaders();
456
456
  if (allHeaders) {
457
457
  // Parse headers string into object
458
- allHeaders.split('\r\n').forEach(line => {
459
- const parts = line.split(': ');
458
+ allHeaders.split("\r\n").forEach((line) => {
459
+ const parts = line.split(": ");
460
460
  if (parts.length === 2) {
461
461
  responseHeaders[parts[0]] = parts[1];
462
462
  }
@@ -788,6 +788,7 @@ export async function startRecording({ apiKey, backendApi = "https://api-service
788
788
  g.sessionId = sessionId;
789
789
  g.apiKey = apiKey;
790
790
  g.backendApi = backendApi;
791
+ g.serviceAdditionalMetadata = serviceAdditionalMetadata;
791
792
  // Already fully initialized for this session with an open socket? No-op.
792
793
  if (g.initialized &&
793
794
  g.sessionId === sessionId &&
@@ -813,6 +814,32 @@ export async function startRecording({ apiKey, backendApi = "https://api-service
813
814
  trackDomainChangesOnce();
814
815
  sessionStorage.setItem("sailfishApiKey", apiKey);
815
816
  sessionStorage.setItem("sailfishBackendApi", backendApi);
817
+ // Function span tracking state is loaded from localStorage on module init (websocket.tsx)
818
+ // Validate localStorage state with backend if tracking appears to be enabled but WebSocket not connected
819
+ if (isFunctionSpanTrackingEnabled() && (!g.ws || g.ws.readyState !== 1)) {
820
+ fetchFunctionSpanTrackingEnabled(apiKey, backendApi)
821
+ .then((funcSpanResponse) => {
822
+ const isEnabled = funcSpanResponse.data?.isFunctionSpanTrackingEnabledFromApiKey ?? false;
823
+ if (!isEnabled) {
824
+ // Backend says tracking is NOT active, clear stale localStorage data
825
+ clearStaleFuncSpanState();
826
+ if (DEBUG) {
827
+ console.log("[Sailfish] Cleared stale function span tracking state - backend validation shows tracking is not active");
828
+ }
829
+ }
830
+ else {
831
+ if (DEBUG) {
832
+ console.log("[Sailfish] Function span tracking state validated with backend: ACTIVE");
833
+ }
834
+ }
835
+ })
836
+ .catch((error) => {
837
+ if (DEBUG) {
838
+ console.warn("[Sailfish] Failed to validate function span tracking status with backend:", error);
839
+ }
840
+ // On error, keep the localStorage state and let WebSocket correct it when it connects
841
+ });
842
+ }
816
843
  if (!g.sentDoNotPropagateOnce) {
817
844
  sendDomainsToNotPropagateHeaderTo(apiKey, [
818
845
  ...domainsToNotPropagateHeaderTo,
@@ -842,7 +869,9 @@ export async function startRecording({ apiKey, backendApi = "https://api-service
842
869
  // Create/ensure a server-side recording session once per browser session
843
870
  const sessionResponse = await startRecordingSession(apiKey, sessionId, backendApi, effectiveServiceIdentifier, effectiveServiceVersion, effectiveMapUuid, effectiveGitSha, effectiveLibrary, metadataWithAppUrl);
844
871
  if (sessionResponse.data?.startRecordingSession) {
845
- const websocket = await initializeRecording(captureSettings, backendApi, apiKey, sessionId);
872
+ // Extract env value from serviceAdditionalMetadata
873
+ const envValue = serviceAdditionalMetadata?.env || serviceAdditionalMetadata?.environment;
874
+ const websocket = await initializeRecording(captureSettings, backendApi, apiKey, sessionId, envValue);
846
875
  g.ws = websocket;
847
876
  g.initialized = true;
848
877
  if (!g.sentMapUuidOnce) {
@@ -909,6 +938,7 @@ export * from "./graphql";
909
938
  export { openReportIssueModal } from "./inAppReportIssueModal";
910
939
  export * from "./recording";
911
940
  export * from "./sendSailfishMessages";
941
+ export { getOrSetSessionId } from "./session";
912
942
  export * from "./types";
913
943
  export * from "./utils";
914
944
  export * from "./websocket";