Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nicohrubec committed Jul 18, 2024
1 parent b32759e commit 4165d78
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core'
import * as Sentry from '@sentry/nestjs';
import { AppModule } from './app.module';

const app1Port = 3030;
const PORT = 3030;

async function bootstrap() {
const app = await NestFactory.create(AppModule);

const { httpAdapter } = app.get(HttpAdapterHost);
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));

await app.listen(app1Port);
await app.listen(PORT);
}

bootstrap();

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import './instrument';
// Import other modules
import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core';
import * as Sentry from '@sentry/nestjs';
import { AppModule1, AppModule2 } from './app.module';
import { TraceInitiatorModule } from './trace-initiator.module';
import { TraceReceiverModule } from './trace-receiver.module';

const app1Port = 3030;
const app2Port = 3040;
const TRACE_INITIATOR_PORT = 3030;
const TRACE_RECEIVER_PORT = 3040;

async function bootstrap() {
const app1 = await NestFactory.create(AppModule1);
const trace_initiator_app = await NestFactory.create(TraceInitiatorModule);

const { httpAdapter } = app1.get(HttpAdapterHost);
Sentry.setupNestErrorHandler(app1, new BaseExceptionFilter(httpAdapter));
const { httpAdapter } = trace_initiator_app.get(HttpAdapterHost);
Sentry.setupNestErrorHandler(trace_initiator_app, new BaseExceptionFilter(httpAdapter));

await app1.listen(app1Port);
await trace_initiator_app.listen(TRACE_INITIATOR_PORT);

const app2 = await NestFactory.create(AppModule2);
await app2.listen(app2Port);
const trace_receiver_app = await NestFactory.create(TraceReceiverModule);
await trace_receiver_app.listen(TRACE_RECEIVER_PORT);
}

bootstrap();
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Controller, Get, Headers, Param } from '@nestjs/common';
import { TraceInitiatorService } from './trace-initiator.service';

@Controller()
export class TraceInitiatorController {
constructor(private readonly traceInitiatorService: TraceInitiatorService) {}

@Get('test-inbound-headers/:id')
testInboundHeaders(@Headers() headers, @Param('id') id: string) {
return this.traceInitiatorService.testInboundHeaders(headers, id);
}

@Get('test-outgoing-http/:id')
async testOutgoingHttp(@Param('id') id: string) {
return this.traceInitiatorService.testOutgoingHttp(id);
}

@Get('test-outgoing-fetch/:id')
async testOutgoingFetch(@Param('id') id: string) {
return this.traceInitiatorService.testOutgoingFetch(id);
}

@Get('test-outgoing-fetch-external-allowed')
async testOutgoingFetchExternalAllowed() {
return this.traceInitiatorService.testOutgoingFetchExternalAllowed();
}

@Get('test-outgoing-fetch-external-disallowed')
async testOutgoingFetchExternalDisallowed() {
return this.traceInitiatorService.testOutgoingFetchExternalDisallowed();
}

@Get('test-outgoing-http-external-allowed')
async testOutgoingHttpExternalAllowed() {
return this.traceInitiatorService.testOutgoingHttpExternalAllowed();
}

@Get('test-outgoing-http-external-disallowed')
async testOutgoingHttpExternalDisallowed() {
return this.traceInitiatorService.testOutgoingHttpExternalDisallowed();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { TraceInitiatorController } from './trace-initiator.controller';
import { TraceInitiatorService } from './trace-initiator.service';

@Module({
imports: [],
controllers: [TraceInitiatorController],
providers: [TraceInitiatorService],
})
export class TraceInitiatorModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { makeHttpRequest } from './utils';

@Injectable()
export class AppService1 {
export class TraceInitiatorService {
constructor() {}

testInboundHeaders(headers: Record<string, string>, id: string) {
Expand Down Expand Up @@ -45,20 +45,3 @@ export class AppService1 {
return makeHttpRequest('http://localhost:3040/external-disallowed');
}
}

@Injectable()
export class AppService2 {
externalAllowed(headers: Record<string, string>) {
return {
headers,
route: 'external-allowed',
};
}

externalDisallowed(headers: Record<string, string>) {
return {
headers,
route: 'external-disallowed',
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Controller, Get, Headers } from '@nestjs/common';
import { TraceReceiverService } from './trace-receiver.service';

@Controller()
export class TraceReceiverController {
constructor(private readonly traceReceiverService: TraceReceiverService) {}

@Get('external-allowed')
externalAllowed(@Headers() headers) {
return this.traceReceiverService.externalAllowed(headers);
}

@Get('external-disallowed')
externalDisallowed(@Headers() headers) {
return this.traceReceiverService.externalDisallowed(headers);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { TraceReceiverController } from './trace-receiver.controller';
import { TraceReceiverService } from './trace-receiver.service';

@Module({
imports: [],
controllers: [TraceReceiverController],
providers: [TraceReceiverService],
})
export class TraceReceiverModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class TraceReceiverService {
externalAllowed(headers: Record<string, string>) {
return {
headers,
route: 'external-allowed',
};
}

externalDisallowed(headers: Record<string, string>) {
return {
headers,
route: 'external-disallowed',
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { BaseExceptionFilter, HttpAdapterHost, NestFactory } from '@nestjs/core'
import * as Sentry from '@sentry/nestjs';
import { AppModule } from './app.module';

const app1Port = 3030;
const PORT = 3030;

async function bootstrap() {
const app1 = await NestFactory.create(AppModule);
const app = await NestFactory.create(AppModule);

const { httpAdapter } = app1.get(HttpAdapterHost);
Sentry.setupNestErrorHandler(app1, new BaseExceptionFilter(httpAdapter));
const { httpAdapter } = app.get(HttpAdapterHost);
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));

await app1.listen(app1Port);
await app.listen(PORT);
}

bootstrap();

0 comments on commit 4165d78

Please sign in to comment.