Browse Source

docs: Add warning to not instrument resolvers

Michael Bromley 2 months ago
parent
commit
02ae2f3578

+ 7 - 1
docs/docs/guides/how-to/telemetry/index.md

@@ -233,7 +233,7 @@ Clicking the blue "Run Query" button will show you the traces for that service.
 ## Instrumenting Your Plugins
 
 You can also instrument your own plugins and services with Open Telemetry. To do so,
-add the [Instrument decorator](/reference/typescript-api/telemetry/instrument) to your service class:
+add the [Instrument decorator](/reference/typescript-api/telemetry/instrument) to your **service class**:
 
 ```ts
 import { Injectable } from '@nestjs/common';
@@ -252,3 +252,9 @@ export class MyService {
 ```
 
 You should now be able to see calls to `MyService.myMethod` in your traces.
+
+:::warning
+You should _not_ decorate GraphQL resolvers & REST controllers with this decorator. Those will
+already be instrumented, and adding the `@Instrument()` decorator will potentially
+interfere with other NestJS decorators on your resolver methods.
+:::

+ 7 - 1
docs/docs/reference/typescript-api/telemetry/instrument.md

@@ -11,7 +11,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
 
 ## Instrument
 
-<GenerationInfo sourceFile="packages/core/src/common/instrument-decorator.ts" sourceLine="41" packageName="@vendure/core" since="3.3.0" />
+<GenerationInfo sourceFile="packages/core/src/common/instrument-decorator.ts" sourceLine="47" packageName="@vendure/core" since="3.3.0" />
 
 This decorator is used to apply instrumentation to a class. It is intended to be used in conjunction
 with an <a href='/reference/typescript-api/telemetry/instrumentation-strategy#instrumentationstrategy'>InstrumentationStrategy</a> which defines how the instrumentation should be applied.
@@ -20,6 +20,12 @@ In order for the instrumentation to be applied, the `VENDURE_ENABLE_INSTRUMENTAT
 variable (exported from the `@vendure/core` package as `ENABLE_INSTRUMENTATION_ENV_VAR`) must be set to `true`.
 This is done to avoid the overhead of instrumentation in environments where it is not needed.
 
+:::warning
+You should _not_ decorate GraphQL resolvers & REST controllers with this decorator. Those will
+already be instrumented, and adding the `@Instrument()` decorator will potentially
+interfere with other NestJS decorators on your resolver methods.
+:::
+
 For more information on how instrumentation is used, see docs on the TelemetryPlugin.
 
 *Example*

+ 6 - 0
packages/core/src/common/instrument-decorator.ts

@@ -16,6 +16,12 @@ type Constructor<T = any> = new (...args: any[]) => T;
  * variable (exported from the `@vendure/core` package as `ENABLE_INSTRUMENTATION_ENV_VAR`) must be set to `true`.
  * This is done to avoid the overhead of instrumentation in environments where it is not needed.
  *
+ * :::warning
+ * You should _not_ decorate GraphQL resolvers & REST controllers with this decorator. Those will
+ * already be instrumented, and adding the `@Instrument()` decorator will potentially
+ * interfere with other NestJS decorators on your resolver methods.
+ * :::
+ *
  * For more information on how instrumentation is used, see docs on the TelemetryPlugin.
  *
  * @example