Skip to content

feat: add surface label#1162

Merged
joaquin-diaz merged 9 commits intomainfrom
joaquin-diaz/feat/EMBR-10673-add-surface-label
Mar 2, 2026
Merged

feat: add surface label#1162
joaquin-diaz merged 9 commits intomainfrom
joaquin-diaz/feat/EMBR-10673-add-surface-label

Conversation

@joaquin-diaz
Copy link
Contributor

What problem is this solving?

Allows users to group telemetry by document title until they provide a better default or they use the (future) URL regex to label parsing in the dash

Short description of changes

  • Add surface label api to Page api
  • Add surface label to all telemetry
  • Grab surface label from document.title if is not set

How has this been tested?

Unit tests, e2e tests, local run

image

@joaquin-diaz joaquin-diaz requested a review from a team as a code owner February 23, 2026 20:43
@joaquin-diaz joaquin-diaz changed the title feat: add surface label feat: add surface label Feb 23, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2026

Chrome DevTools Protocol Tracing (Script: 122.04ms, Heap: 14.20MB)
Number of Requests Size of Requests Script Duration Task Duration Heap Used Size
Requests +3 requests +30.33 KB
Page Loaded +18.54 ms +16.42 ms +1.02 MB
Generate 100 fetch requests +25.25 ms +113.02 ms +1.63 MB
Generate 100 XHR requests +43.36 ms +121.86 ms +2.05 MB
Click 100 buttons and generate 100 logs +23.68 ms +26.95 ms +3.16 MB
Throw a 100 exceptions +2.74 ms +35.89 ms +2.85 MB
End Session +8.46 ms +12.87 ms +3.49 MB
Total +3 requests +30.33 KB +122.04 ms +327.01 ms +14.20 MB
Lighthouse (Script Eval: 132.94ms)
Difference Description
Total Blocking Time +19 ms Difference in Total Blocking Time: Sum of all time periods between FCP and Time to Interactive, when task length exceeded 50ms, expressed in milliseconds. Learn more about the Total Blocking Time metric.
Main Thread Time +114.46 ms Difference in Main Thread Time: Consider reducing the time spent parsing, compiling and executing JS. You may find delivering smaller JS payloads helps with this. Learn how to minimize main-thread work
Script Evaluation Time +132.94 ms Difference in Script Evaluation Time: Consider reducing the time spent parsing, compiling, and executing JS. You may find delivering smaller JS payloads helps with this. Learn how to reduce Javascript execution time.
Platform Tests (vite-7 es2015 gzip: 66.48KB)

vite-6 Platform Tests

Total Uncompressed Size Total Gzip Size
vite-6 - es2015 +187.23 KB +66.52 KB

vite-7 Platform Tests

Total Uncompressed Size Total Gzip Size
vite-7 - es2015 +187.23 KB +66.48 KB

webpack-5 Platform Tests

Total Uncompressed Size Total Gzip Size
webpack-5 - es2015 +136.33 KB +49.29 KB

@joaquin-diaz joaquin-diaz force-pushed the joaquin-diaz/feat/EMBR-10673-add-surface-label branch from a6709e4 to 95918bc Compare February 24, 2026 15:00
);
}

const appSurfaceLabel = this._pageManager.getAppSurfaceLabel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to the check above should we avoid doing this if KEY_APP_SURFACE_LABEL is already set?

span.attributes[KEY_EMB_PAGE_ID] = currentPageId;
}

const appSurfaceLabel = this._pageManager.getAppSurfaceLabel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar question


public getCurrentRoute = () => this._currentRoute;

public setAppSurfaceLabel = (label: string): void => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should label instead be included as part of Route and set with setCurrentRoute? Could we end up with inconsistencies with this being set separately?

Copy link
Contributor Author

@joaquin-diaz joaquin-diaz Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case you'll be forced to pass something as route.path where you might not have it. I think I'd rather keep them independent right now. I can add it as a optional route value so users can set that up when they setCurrentRoute but I'd still keep the label setter. I'm also going to change the API to be:
setRouteLabel and getRouteLabel to be consistent

span.attributes[KEY_EMB_PAGE_ID] = currentPageId;
}

const appSurfaceLabel = this._pageManager.getPageLabel();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more on this one and packages/web-sdk/src/processors/PageLogRecordProcessor/PageLogRecordProcessor.ts, feel free to ignore if it's a situation that can't really happen:

should the early exit above just wrap the above block instead? e.g.:

// If the span already has page attributes, do not override them
if (
      !(span.attributes[KEY_EMB_PAGE_PATH] &&
      span.attributes[KEY_EMB_PAGE_ID])
    ) {

    const currentRoute = this._pageManager.getCurrentRoute();
    const currentPageId = this._pageManager.getCurrentPageId();

    if (currentRoute && currentPageId) {
      span.attributes[KEY_EMB_PAGE_PATH] = currentRoute.path;
      span.attributes[KEY_EMB_PAGE_ID] = currentPageId;
    }
}

just wondering if there would ever be a case where those attributes are set but we'd still want to continue with the surface label logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I missed that. It made sense before but not after my changes, updating

path: string;
// This is the URL of the route after replacing the URL params. i.e. /products/123
url: string;
// Optional label for the route, used as app.surface.label
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the examples given above. Maybe you could add something like:
"OLED Televisions - Electronics - BigStore.com"

if (
logRecord.attributes[KEY_EMB_PAGE_PATH] ||
logRecord.attributes[KEY_EMB_PAGE_ID]
!logRecord.attributes[KEY_EMB_PAGE_PATH] ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the logic changed here inadvertently, before it was skipping the setting if either were set, now it could override if one is set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If either is missing it overrides both

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if one is missing I override both so make sure they are using the same route. This shouldn't happen in theory, we always set them at the same time but just to be safe. That's why before if either one was present we don't change it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yep that makes sense to me

this._currentRoute = route;

if (route.label) {
this._pageLabel = route.label;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the route changes but no label is set, it will reuse the previous label. Should this be cleared out instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good catch

if (
logRecord.attributes[KEY_EMB_PAGE_PATH] ||
logRecord.attributes[KEY_EMB_PAGE_ID]
!logRecord.attributes[KEY_EMB_PAGE_PATH] ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If either is missing it overrides both

if (
logRecord.attributes[KEY_EMB_PAGE_PATH] ||
logRecord.attributes[KEY_EMB_PAGE_ID]
!logRecord.attributes[KEY_EMB_PAGE_PATH] ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yep that makes sense to me

@joaquin-diaz joaquin-diaz merged commit 0159adc into main Mar 2, 2026
18 checks passed
@joaquin-diaz joaquin-diaz deleted the joaquin-diaz/feat/EMBR-10673-add-surface-label branch March 2, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants