From c0678bab1536fe5f1fb57ffd4e65b8f3b85766a6 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 25 Mar 2025 14:09:37 +0100 Subject: [PATCH] feat(db): insert current_url for errors and issues --- backend/pkg/db/clickhouse/connector.go | 7 +++-- backend/pkg/db/types/error-event.go | 41 ++++---------------------- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/backend/pkg/db/clickhouse/connector.go b/backend/pkg/db/clickhouse/connector.go index ed67b5c24..25ebc8a1e 100644 --- a/backend/pkg/db/clickhouse/connector.go +++ b/backend/pkg/db/clickhouse/connector.go @@ -111,12 +111,12 @@ var batches = map[string]string{ "pages": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", "$current_url", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, "clicks": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", "$current_url", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, "inputs": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", "$duration_s", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, - "errors": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", error_id, "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + "errors": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", error_id, "$current_url", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, "performance": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, "requests": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", "$duration_s", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, "custom": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, "graphql": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, - "issuesEvents": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", issue_type, issue_id, "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + "issuesEvents": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", issue_type, issue_id, "$current_url", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, "issues": "INSERT INTO experimental.issues (project_id, issue_id, type, context_string) VALUES (?, ?, ?, ?)", "mobile_sessions": "INSERT INTO experimental.sessions (session_id, project_id, user_id, user_uuid, user_os, user_os_version, user_device, user_device_type, user_country, user_state, user_city, datetime, duration, pages_count, events_count, errors_count, issue_score, referrer, issue_types, tracker_version, user_browser, user_browser_version, metadata_1, metadata_2, metadata_3, metadata_4, metadata_5, metadata_6, metadata_7, metadata_8, metadata_9, metadata_10, platform, timezone) VALUES (?, ?, SUBSTR(?, 1, 8000), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SUBSTR(?, 1, 8000), ?, ?, ?, ?, SUBSTR(?, 1, 8000), SUBSTR(?, 1, 8000), SUBSTR(?, 1, 8000), SUBSTR(?, 1, 8000), SUBSTR(?, 1, 8000), SUBSTR(?, 1, 8000), SUBSTR(?, 1, 8000), SUBSTR(?, 1, 8000), SUBSTR(?, 1, 8000), SUBSTR(?, 1, 8000), ?, ?)", "mobile_custom": `INSERT INTO product_analytics.events (session_id, project_id, event_id, "$event_name", created_at, "$time", distinct_id, "$auto_captured", "$device", "$os_version", "$properties") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, @@ -309,6 +309,7 @@ func (c *connectorImpl) InsertMouseThrashing(session *sessions.Session, msg *mes session.UserOSVersion, "mouse_thrashing", issueID, + cropString(msg.Url), jsonString, ); err != nil { c.checkError("issuesEvents", err) @@ -365,6 +366,7 @@ func (c *connectorImpl) InsertIssue(session *sessions.Session, msg *messages.Iss session.UserOSVersion, msg.Type, issueID, + cropString(msg.Url), jsonString, ); err != nil { c.checkError("issuesEvents", err) @@ -552,6 +554,7 @@ func (c *connectorImpl) InsertWebErrorEvent(session *sessions.Session, msg *type session.Platform, session.UserOSVersion, msgID, + cropString(msg.Url), jsonString, ); err != nil { c.checkError("errors", err) diff --git a/backend/pkg/db/types/error-event.go b/backend/pkg/db/types/error-event.go index df137347a..550174cde 100644 --- a/backend/pkg/db/types/error-event.go +++ b/backend/pkg/db/types/error-event.go @@ -5,10 +5,11 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/google/uuid" "hash/fnv" "strconv" + "github.com/google/uuid" + . "openreplay/backend/pkg/messages" ) @@ -23,41 +24,7 @@ type ErrorEvent struct { Payload string Tags map[string]*string OriginType int -} - -func unquote(s string) string { - if s[0] == '"' { - return s[1 : len(s)-1] - } - return s -} -func parseTags(tagsJSON string) (tags map[string]*string, err error) { - if len(tagsJSON) == 0 { - return nil, fmt.Errorf("empty tags") - } - if tagsJSON[0] == '[' { - var tagsArr []json.RawMessage - if err = json.Unmarshal([]byte(tagsJSON), &tagsArr); err != nil { - return - } - - tags = make(map[string]*string) - for _, keyBts := range tagsArr { - tags[unquote(string(keyBts))] = nil - } - } else if tagsJSON[0] == '{' { - var tagsObj map[string]json.RawMessage - if err = json.Unmarshal([]byte(tagsJSON), &tagsObj); err != nil { - return - } - - tags = make(map[string]*string) - for key, valBts := range tagsObj { - val := unquote(string(valBts)) - tags[key] = &val - } - } - return + Url string } func WrapJSException(m *JSException) (*ErrorEvent, error) { @@ -69,6 +36,7 @@ func WrapJSException(m *JSException) (*ErrorEvent, error) { Message: m.Message, Payload: m.Payload, OriginType: m.TypeID(), + Url: m.Url, }, nil } @@ -81,6 +49,7 @@ func WrapIntegrationEvent(m *IntegrationEvent) *ErrorEvent { Message: m.Message, Payload: m.Payload, OriginType: m.TypeID(), + Url: m.Url, } }