Skip to content

Commit

Permalink
make work lol
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Jul 26, 2024
1 parent 5aade8a commit 6e35eb1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {MiddlewareConsumer, Module} from '@nestjs/common';
import { MiddlewareConsumer, Module } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';
import { SentryModule } from '@sentry/nestjs/setup';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { LoggerMiddleware } from "./logger.middleware";
import { LoggerMiddleware } from './logger.middleware';

@Module({
imports: [SentryModule.forRoot(), ScheduleModule.forRoot()],
Expand All @@ -13,8 +13,6 @@ import { LoggerMiddleware } from "./logger.middleware";
export class AppModule {
configure(consumer: MiddlewareConsumer): void {
console.log('Add class middleware.');
consumer
.apply(LoggerMiddleware)
.forRoutes(AppController);
consumer.apply(LoggerMiddleware).forRoutes(AppController);
}
}
48 changes: 24 additions & 24 deletions packages/node/src/integrations/tracing/nest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { isWrapped } from '@opentelemetry/core';
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
} from '@opentelemetry/instrumentation';
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';
import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
Expand All @@ -12,12 +19,6 @@ import {
import type { IntegrationFn, Span } from '@sentry/types';
import { logger } from '@sentry/utils';
import { generateInstrumentOnce } from '../../otel/instrument';
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition, InstrumentationNodeModuleFile
} from '@opentelemetry/instrumentation';
import { isWrapped } from '@opentelemetry/core';

interface MinimalNestJsExecutionContext {
getType: () => string;
Expand Down Expand Up @@ -68,23 +69,17 @@ export class SentryNestInstrumentation extends InstrumentationBase {
/**
*
*/
public init(): void {
logger.log('init!');
const module = new InstrumentationNodeModuleDefinition(
SentryNestInstrumentation.COMPONENT,
supportedVersions
)

module.files.push(
this._getInjectableFileInstrumentation(supportedVersions)
)
public init(): InstrumentationNodeModuleDefinition {
const moduleDef = new InstrumentationNodeModuleDefinition(SentryNestInstrumentation.COMPONENT, supportedVersions);

moduleDef.files.push(this._getInjectableFileInstrumentation(supportedVersions));
return moduleDef;
}

/**
*
*/
private _getInjectableFileInstrumentation(versions: string[]): InstrumentationNodeModuleFile {
logger.log('create instrumentation node module file');
return new InstrumentationNodeModuleFile(
'@nestjs/common/decorators/core/injectable.decorator.js',
versions,
Expand All @@ -98,8 +93,8 @@ export class SentryNestInstrumentation extends InstrumentationBase {
},
(moduleExports: any) => {
this._unwrap(moduleExports, 'Injectable');
}
)
},
);
}

/**
Expand All @@ -109,11 +104,18 @@ export class SentryNestInstrumentation extends InstrumentationBase {
return function wrapInjectable(original: any) {
return function wrappedInjectable(options?: any) {
return function (target: any) {
logger.log('Injectable target:', target);

// TODO: Check if the class was already patched à la
// if (target[sentryPatchedSymbol]) {
// return original(options)(target);
// } else {
// addNonEnumerableProperty(target, sentryPatchedSymbol, true);
// }

// TODO: proper typing
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (typeof target.prototype.use === 'function') {
logger.log('middleware!');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-console
console.log('middleware!');
}

return original(options)(target);
Expand All @@ -124,12 +126,10 @@ export class SentryNestInstrumentation extends InstrumentationBase {
}

const instrumentNestCore = generateInstrumentOnce('Nest-Core', () => {
logger.log('init nest core instrumentation');
return new NestInstrumentation();
});

const instrumentMiddleware = generateInstrumentOnce('Nest-Middleware', () => {
logger.log('init nest middleware instrumentation');
return new SentryNestInstrumentation();
});

Expand Down

0 comments on commit 6e35eb1

Please sign in to comment.