Skip to content

Commit 6e35eb1

Browse files
author
Luca Forstner
committed
make work lol
1 parent 5aade8a commit 6e35eb1

File tree

2 files changed

+27
-29
lines changed
  • dev-packages/e2e-tests/test-applications/nestjs-basic/src
  • packages/node/src/integrations/tracing

2 files changed

+27
-29
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {MiddlewareConsumer, Module} from '@nestjs/common';
1+
import { MiddlewareConsumer, Module } from '@nestjs/common';
22
import { ScheduleModule } from '@nestjs/schedule';
33
import { SentryModule } from '@sentry/nestjs/setup';
44
import { AppController } from './app.controller';
55
import { AppService } from './app.service';
6-
import { LoggerMiddleware } from "./logger.middleware";
6+
import { LoggerMiddleware } from './logger.middleware';
77

88
@Module({
99
imports: [SentryModule.forRoot(), ScheduleModule.forRoot()],
@@ -13,8 +13,6 @@ import { LoggerMiddleware } from "./logger.middleware";
1313
export class AppModule {
1414
configure(consumer: MiddlewareConsumer): void {
1515
console.log('Add class middleware.');
16-
consumer
17-
.apply(LoggerMiddleware)
18-
.forRoutes(AppController);
16+
consumer.apply(LoggerMiddleware).forRoutes(AppController);
1917
}
2018
}

packages/node/src/integrations/tracing/nest.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import { isWrapped } from '@opentelemetry/core';
2+
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
3+
import {
4+
InstrumentationBase,
5+
InstrumentationNodeModuleDefinition,
6+
InstrumentationNodeModuleFile,
7+
} from '@opentelemetry/instrumentation';
18
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';
29
import {
310
SEMANTIC_ATTRIBUTE_SENTRY_OP,
@@ -12,12 +19,6 @@ import {
1219
import type { IntegrationFn, Span } from '@sentry/types';
1320
import { logger } from '@sentry/utils';
1421
import { generateInstrumentOnce } from '../../otel/instrument';
15-
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
16-
import {
17-
InstrumentationBase,
18-
InstrumentationNodeModuleDefinition, InstrumentationNodeModuleFile
19-
} from '@opentelemetry/instrumentation';
20-
import { isWrapped } from '@opentelemetry/core';
2122

2223
interface MinimalNestJsExecutionContext {
2324
getType: () => string;
@@ -68,23 +69,17 @@ export class SentryNestInstrumentation extends InstrumentationBase {
6869
/**
6970
*
7071
*/
71-
public init(): void {
72-
logger.log('init!');
73-
const module = new InstrumentationNodeModuleDefinition(
74-
SentryNestInstrumentation.COMPONENT,
75-
supportedVersions
76-
)
77-
78-
module.files.push(
79-
this._getInjectableFileInstrumentation(supportedVersions)
80-
)
72+
public init(): InstrumentationNodeModuleDefinition {
73+
const moduleDef = new InstrumentationNodeModuleDefinition(SentryNestInstrumentation.COMPONENT, supportedVersions);
74+
75+
moduleDef.files.push(this._getInjectableFileInstrumentation(supportedVersions));
76+
return moduleDef;
8177
}
8278

8379
/**
8480
*
8581
*/
8682
private _getInjectableFileInstrumentation(versions: string[]): InstrumentationNodeModuleFile {
87-
logger.log('create instrumentation node module file');
8883
return new InstrumentationNodeModuleFile(
8984
'@nestjs/common/decorators/core/injectable.decorator.js',
9085
versions,
@@ -98,8 +93,8 @@ export class SentryNestInstrumentation extends InstrumentationBase {
9893
},
9994
(moduleExports: any) => {
10095
this._unwrap(moduleExports, 'Injectable');
101-
}
102-
)
96+
},
97+
);
10398
}
10499

105100
/**
@@ -109,11 +104,18 @@ export class SentryNestInstrumentation extends InstrumentationBase {
109104
return function wrapInjectable(original: any) {
110105
return function wrappedInjectable(options?: any) {
111106
return function (target: any) {
112-
logger.log('Injectable target:', target);
113-
107+
// TODO: Check if the class was already patched à la
108+
// if (target[sentryPatchedSymbol]) {
109+
// return original(options)(target);
110+
// } else {
111+
// addNonEnumerableProperty(target, sentryPatchedSymbol, true);
112+
// }
113+
114+
// TODO: proper typing
114115
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
115116
if (typeof target.prototype.use === 'function') {
116-
logger.log('middleware!');
117+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-console
118+
console.log('middleware!');
117119
}
118120

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

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

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

0 commit comments

Comments
 (0)