Skip to content

fix(replay): Expand replay user.geo tag if an object is found #91885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions static/app/utils/replays/replayDataUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import invariant from 'invariant';
import isPlainObject from 'lodash/isPlainObject';
import {duration} from 'moment-timezone';

import {deviceNameMapper} from 'sentry/components/deviceName';
Expand All @@ -10,13 +11,23 @@ const defaultValues = {
has_viewed: false,
};

export function mapResponseToReplayRecord(apiResponse: any): ReplayRecord {
// Marshal special fields into tags
const user = Object.fromEntries(
Object.entries(apiResponse.user)
function mapUser(user: any): ReplayRecord['tags'] {
return Object.fromEntries(
Object.entries(user)
.filter(([key, value]) => key !== 'display_name' && value)
.map(([key, value]) => [`user.${key}`, [value]])
.flatMap(([key, value]) => {
if (isPlainObject(value)) {
return Object.entries(value as Record<PropertyKey, unknown>).map(
([subKey, subValue]) => [`user.${key}.${subKey}`, [String(subValue)]]
);
}
return [[`user.${key}`, [String(value)]]];
})
);
}

export function mapResponseToReplayRecord(apiResponse: any): ReplayRecord {
// Marshal special fields into tags
const unorderedTags: ReplayRecord['tags'] = {
...apiResponse.tags,
...(apiResponse.browser?.name ? {'browser.name': [apiResponse.browser.name]} : {}),
Expand All @@ -40,7 +51,7 @@ export function mapResponseToReplayRecord(apiResponse: any): ReplayRecord {
...(apiResponse.os?.version ? {'os.version': [apiResponse.os.version]} : {}),
...(apiResponse.sdk?.name ? {'sdk.name': [apiResponse.sdk.name]} : {}),
...(apiResponse.sdk?.version ? {'sdk.version': [apiResponse.sdk.version]} : {}),
...user,
...mapUser(apiResponse.user ?? {}),
};

const startedAt = new Date(apiResponse.started_at);
Expand Down
10 changes: 10 additions & 0 deletions static/app/views/replays/types.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import type {Duration} from 'moment-timezone';

type Geo = Record<string, string>;
// Geo could be this, not sure:
// {
// city?: string;
// country_code?: string;
// region?: string;
// subdivision?: string;
// };

// Keep this in sync with the backend blueprint
// "ReplayRecord" is distinct from the common: "replay = new ReplayReader()"
export type ReplayRecord = {
Expand Down Expand Up @@ -78,6 +87,7 @@ export type ReplayRecord = {
id: null | string;
ip: null | string;
username: null | string;
geo?: Geo;
};
/**
* The number of dead clicks associated with the replay.
Expand Down
Loading