Skip to content

Commit

Permalink
Merge pull request #700 from avrae/AVR-542
Browse files Browse the repository at this point in the history
AVR-542: Enable Datadog Support in Avrae.IO
  • Loading branch information
tiberius0954 authored Dec 18, 2024
2 parents 4810626 + 8b80052 commit 4e1a5e9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@angular/platform-server": "^13.3.9",
"@angular/router": "^13.3.9",
"@auth0/angular-jwt": "^5.0.2",
"@datadog/browser-rum": "^5.34.0",
"@nguniversal/express-engine": "^13.1.1",
"@sentry/browser": "^6.18.1",
"compression": "^1.7.4",
Expand Down
4 changes: 3 additions & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Component, OnInit} from '@angular/core';
import {MatIconRegistry} from '@angular/material/icon';
import {DomSanitizer, Meta} from '@angular/platform-browser';
import {environment} from '../environments/environment';
import {MonitoringService} from './shared/monitoring/monitoring.service'

@Component({
selector: 'avr-root',
Expand All @@ -15,7 +16,7 @@ export class AppComponent implements OnInit {
'Featuring advanced dice, SRD and character sheet integration, and initiative tracking, ' +
'you\'ll never need another D&D bot.';

constructor(private meta: Meta, private iconRegistry: MatIconRegistry, private domSanitizer: DomSanitizer) {
constructor(private meta: Meta, private iconRegistry: MatIconRegistry, private domSanitizer: DomSanitizer, private monitoringService: MonitoringService ) {
this.meta.addTags([
{name: 'description', content: this.description},
{property: 'og:title', content: this.title},
Expand All @@ -35,5 +36,6 @@ export class AppComponent implements OnInit {

// On init function (make sure to implement OnInit is called when component is initialized
ngOnInit() {
this.monitoringService.initializeDatadog();
}
}
16 changes: 16 additions & 0 deletions src/app/shared/monitoring/monitoring.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { MonitoringService } from './monitoring.service';

describe('MonitoringService', () => {
let service: MonitoringService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(MonitoringService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
28 changes: 28 additions & 0 deletions src/app/shared/monitoring/monitoring.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Injectable } from '@angular/core';
import { datadogRum } from '@datadog/browser-rum';
import { environment } from 'src/environments/environment';

@Injectable({
providedIn: 'root'
})
export class MonitoringService {

constructor() {}

public initializeDatadog(): void {
datadogRum.init({
applicationId: environment.datadogAplicationId,
clientToken: environment.datadogClientToken,
site: 'datadoghq.com',
service: 'avrae.io',
env: environment.production ? 'prod' : 'test',
version: '1.0.0',
sessionSampleRate: 100,
sessionReplaySampleRate: 20,
trackUserInteractions: true,
trackResources: true,
trackLongTasks: true,
defaultPrivacyLevel: 'mask-user-input',
});
}
}
4 changes: 3 additions & 1 deletion src/environments/environment.beta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export const environment = {
loginURL: 'https://discordapp.com/api/oauth2/authorize',
apiURL: 'https://api.avrae.io',
mediaURL: 'https://media.avrae.io',
baseURL: 'https://avrae.dev'
baseURL: 'https://avrae.dev',
datadogAplicationId: '7350206a-687c-4dc4-942b-c3f0d1bb024b',
datadogClientToken: 'pubf700faf5c2632d84266ee5171c2eb062'
};

// The beta environment is pretty much the same as the prod environment, except that it's hosted on avrae.dev
Expand Down
4 changes: 3 additions & 1 deletion src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export const environment = {
loginURL: 'https://discordapp.com/api/oauth2/authorize',
apiURL: 'https://api.avrae.io',
mediaURL: 'https://media.avrae.io',
baseURL: 'https://avrae.io'
baseURL: 'https://avrae.io',
datadogAplicationId: '7350206a-687c-4dc4-942b-c3f0d1bb024b',
datadogClientToken: 'pubf700faf5c2632d84266ee5171c2eb062'
};
10 changes: 9 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export const environment = {
loginURL: 'https://discordapp.com/api/oauth2/authorize',
apiURL: 'http://127.0.0.1:5000',
mediaURL: 'https://media.avrae.io',
baseURL: 'http://127.0.0.1:4200'
baseURL: 'http://127.0.0.1:4200',
datadogAplicationId: '7350206a-687c-4dc4-942b-c3f0d1bb024b',
datadogClientToken: 'pubf700faf5c2632d84266ee5171c2eb062'
};

/*
Expand All @@ -17,4 +19,10 @@ export const environment = {
* below file. Don't forget to comment it out in production mode
* because it will have a performance impact when errors are thrown
*/

/*
Currently, the datadog `clientToken` and `applicationId` are public since they're
not sensitive data, and they are designed to be used in client-side code which is
a common and safe practice when integrating Datadog RUM.
*/
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.

0 comments on commit 4e1a5e9

Please sign in to comment.