Skip to content

Commit

Permalink
Merge pull request #363 from Swetrix/feature/hostname-tracking
Browse files Browse the repository at this point in the history
fix hostname detection
  • Loading branch information
Blaumaus authored Jan 9, 2025
2 parents 3033c6d + 2e5ade8 commit 1f49aba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
10 changes: 5 additions & 5 deletions backend/apps/cloud/src/analytics/analytics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ export class AnalyticsController {
const transformed = errorEventTransformer(
this.analyticsService.getErrorID(errorDTO),
errorDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
errorDTO.pg,
dv,
br,
Expand Down Expand Up @@ -1276,7 +1276,7 @@ export class AnalyticsController {
const transformed = customEventTransformer(
psid,
eventsDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
eventsDTO.ev,
eventsDTO.pg,
dv,
Expand Down Expand Up @@ -1384,7 +1384,7 @@ export class AnalyticsController {
const transformed = trafficTransformer(
psid,
logDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
logDTO.pg,
dv,
br,
Expand Down Expand Up @@ -1420,7 +1420,7 @@ export class AnalyticsController {

perfTransformed = performanceTransformer(
logDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
logDTO.pg,
dv,
br,
Expand Down Expand Up @@ -1518,7 +1518,7 @@ export class AnalyticsController {
const transformed = trafficTransformer(
psid,
logDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
null,
dv,
br,
Expand Down
9 changes: 9 additions & 0 deletions backend/apps/cloud/src/analytics/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,15 @@ export class AnalyticsService {
}
}

getHostFromOrigin(origin: string): string | null {
try {
const { hostname } = new URL(origin)
return hostname || null
} catch (error) {
return null
}
}

checkIpBlacklist(project: Project, ip: string): void {
// For some reasons the project.ipBlacklist sometimes may look like [''], let's filter it out
// TODO: Properly validate the ipBlacklist on project update
Expand Down
10 changes: 5 additions & 5 deletions backend/apps/community/src/analytics/analytics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ export class AnalyticsController {
const transformed = customEventTransformer(
psid,
eventsDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
eventsDTO.ev,
eventsDTO.pg,
dv,
Expand Down Expand Up @@ -1053,7 +1053,7 @@ export class AnalyticsController {
const transformed = trafficTransformer(
psid,
logDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
logDTO.pg,
dv,
br,
Expand Down Expand Up @@ -1089,7 +1089,7 @@ export class AnalyticsController {

perfTransformed = performanceTransformer(
logDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
logDTO.pg,
dv,
br,
Expand Down Expand Up @@ -1187,7 +1187,7 @@ export class AnalyticsController {
const transformed = trafficTransformer(
psid,
logDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
null,
dv,
br,
Expand Down Expand Up @@ -1480,7 +1480,7 @@ export class AnalyticsController {
const transformed = errorEventTransformer(
this.analyticsService.getErrorID(errorDTO),
errorDTO.pid,
headers.host,
this.analyticsService.getHostFromOrigin(headers.origin),
errorDTO.pg,
dv,
br,
Expand Down
9 changes: 9 additions & 0 deletions backend/apps/community/src/analytics/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ export class AnalyticsService {
}
}

getHostFromOrigin(origin: string): string | null {
try {
const { hostname } = new URL(origin)
return hostname || null
} catch (error) {
return null
}
}

checkIpBlacklist(project: Project, ip: string): void {
// For some reasons the project.ipBlacklist sometimes may look like [''], let's filter it out
// TODO: Properly validate the ipBlacklist on project update
Expand Down

0 comments on commit 1f49aba

Please sign in to comment.