-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add Datadog RUM session tracking integration #20
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
Changes from 1 commit
d8729c3
83666e0
2bc9e94
bc2f0ed
dab38e0
7d54b63
5049a29
793a9b1
3997569
ea29994
a168d32
1300c9e
c67fc00
15c967c
ae06656
ec11d8a
d6e9ddb
39b98d9
eda02a9
e9e6e73
51e3578
33af87c
498f3f0
d85ce85
140c026
5617ea6
4d549ab
5b3c076
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| import { Injectable } from '@angular/core'; | ||
| import { datadogRum } from '@datadog/browser-rum'; | ||
| import { environment } from '../../../environments/environment'; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root', | ||
| }) | ||
| export class DatadogRumService { | ||
| private isInitialized = false; | ||
|
|
||
| public initialize(): void { | ||
| if (this.isInitialized || !environment.datadog.enabled) { | ||
| return; | ||
| } | ||
|
|
||
| if (!environment.datadog.applicationId || !environment.datadog.clientToken) { | ||
| console.warn('Datadog RUM: Missing applicationId or clientToken in environment configuration'); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| datadogRum.init({ | ||
| applicationId: environment.datadog.applicationId, | ||
| clientToken: environment.datadog.clientToken, | ||
| site: environment.datadog.site as 'datadoghq.com', | ||
| service: environment.datadog.service, | ||
| env: environment.datadog.env, | ||
| version: '1.0.0', | ||
|
||
| sessionSampleRate: 100, | ||
| sessionReplaySampleRate: 20, | ||
| trackUserInteractions: true, | ||
| trackResources: true, | ||
| trackLongTasks: true, | ||
| defaultPrivacyLevel: 'mask-user-input', | ||
| }); | ||
|
|
||
| this.isInitialized = true; | ||
| } catch (error) { | ||
| console.error('Failed to initialize Datadog RUM:', error); | ||
| } | ||
| } | ||
|
|
||
| public addAction(name: string, context?: object): void { | ||
| if (this.isInitialized) { | ||
| datadogRum.addAction(name, context); | ||
| } | ||
| } | ||
|
|
||
| public addError(error: Error, context?: object): void { | ||
| if (this.isInitialized) { | ||
| datadogRum.addError(error, context); | ||
| } | ||
| } | ||
|
|
||
| public setUser(user: { id?: string; name?: string; email?: string }): void { | ||
| if (this.isInitialized) { | ||
| datadogRum.setUser(user); | ||
| } | ||
| } | ||
|
|
||
| public setUserProperty(key: string, value: any): void { | ||
| if (this.isInitialized) { | ||
| datadogRum.setUserProperty(key, value); | ||
| } | ||
| } | ||
|
|
||
| public setGlobalContextProperty(key: string, value: any): void { | ||
| if (this.isInitialized) { | ||
| datadogRum.setGlobalContextProperty(key, value); | ||
| } | ||
| } | ||
|
|
||
| public removeGlobalContextProperty(key: string): void { | ||
| if (this.isInitialized) { | ||
| datadogRum.removeGlobalContextProperty(key); | ||
| } | ||
| } | ||
|
|
||
| public startView(name: string): void { | ||
| if (this.isInitialized) { | ||
| datadogRum.startView(name); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,4 +6,12 @@ export const environment = { | |||||||||||||||||||||
| urls: { | ||||||||||||||||||||||
| profile: 'https://myprofile.dev.platform.linuxfoundation.org/', | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| datadog: { | ||||||||||||||||||||||
| enabled: true, | ||||||||||||||||||||||
| applicationId: process.env['DD_APPLICATION_ID'] || '', | ||||||||||||||||||||||
| clientToken: process.env['DD_CLIENT_TOKEN'] || '', | ||||||||||||||||||||||
| site: 'datadoghq.com', | ||||||||||||||||||||||
| service: 'lfx-projects-self-service', | ||||||||||||||||||||||
| env: process.env['DD_ENV'] || 'dev', | ||||||||||||||||||||||
|
Comment on lines
+11
to
+15
|
||||||||||||||||||||||
| applicationId: process.env['DD_APPLICATION_ID'] || '', | |
| clientToken: process.env['DD_CLIENT_TOKEN'] || '', | |
| site: 'datadoghq.com', | |
| service: 'lfx-projects-self-service', | |
| env: process.env['DD_ENV'] || 'dev', | |
| applicationId: 'dev-application-id', // Replace with actual dev value or placeholder | |
| clientToken: 'dev-client-token', // Replace with actual dev value or placeholder | |
| site: 'datadoghq.com', | |
| service: 'lfx-projects-self-service', | |
| env: 'dev', // Replace with actual dev value or placeholder |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,4 +6,12 @@ export const environment = { | |||||||||||||||||||||
| urls: { | ||||||||||||||||||||||
| profile: 'https://openprofile.dev', | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| datadog: { | ||||||||||||||||||||||
| enabled: true, | ||||||||||||||||||||||
| applicationId: process.env['DD_APPLICATION_ID'] || '', | ||||||||||||||||||||||
| clientToken: process.env['DD_CLIENT_TOKEN'] || '', | ||||||||||||||||||||||
| site: 'datadoghq.com', | ||||||||||||||||||||||
| service: 'lfx-projects-self-service', | ||||||||||||||||||||||
| env: process.env['DD_ENV'] || 'prod', | ||||||||||||||||||||||
|
Comment on lines
+11
to
+15
|
||||||||||||||||||||||
| applicationId: process.env['DD_APPLICATION_ID'] || '', | |
| clientToken: process.env['DD_CLIENT_TOKEN'] || '', | |
| site: 'datadoghq.com', | |
| service: 'lfx-projects-self-service', | |
| env: process.env['DD_ENV'] || 'prod', | |
| applicationId: 'DD_APPLICATION_ID_PLACEHOLDER', | |
| clientToken: 'DD_CLIENT_TOKEN_PLACEHOLDER', | |
| site: 'datadoghq.com', | |
| service: 'lfx-projects-self-service', | |
| env: 'DD_ENV_PLACEHOLDER', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type assertion 'as "datadoghq.com"' is brittle and could break if the site value changes. Consider using proper typing or validation to ensure the site value is a valid Datadog site.