Skip to content

Commit

Permalink
Add Nest.js framework support
Browse files Browse the repository at this point in the history
Add official OpenTelemetry Nest.js core instrumentation to the default
instrumentations set. It adds Nest.js specific instrumentation such as
controllers and requests handlers. Nest specific spans are properly
structured inside the HTTP/Express ones.

Co-authored-by: Noemi Lapresta <noemi@appsignal.com>
  • Loading branch information
luismiramirez and unflxw committed Oct 19, 2022
1 parent 78bd040 commit c07b3a4
Show file tree
Hide file tree
Showing 29 changed files with 16,920 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .changesets/add-support-for-nest-js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

Add support for Nest.js
3 changes: 3 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ blocks:
- name: Next.js
commands:
- script/integration_test_app nextjs
- name: Nest.js
commands:
- script/integration_test_app nestjs
- name: Node.js 19 - Build
dependencies:
- Validation
Expand Down
3 changes: 3 additions & 0 deletions build_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ semaphore: # Default `.semaphore/semaphore.yml` contents
- name: Next.js
commands:
- script/integration_test_app nextjs
- name: Nest.js
commands:
- script/integration_test_app nestjs

matrix:
nodejs:
Expand Down
146 changes: 110 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@opentelemetry/instrumentation-koa": "^0.32.0",
"@opentelemetry/instrumentation-mysql2": "^0.32.0",
"@opentelemetry/instrumentation-mysql": "^0.31.1",
"@opentelemetry/instrumentation-nestjs-core": "^0.31.0",
"@opentelemetry/instrumentation-pg": "^0.31.1",
"@opentelemetry/instrumentation-redis-4": "^0.33.0",
"@opentelemetry/instrumentation-redis": "^0.33.0",
Expand Down
2 changes: 2 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { KoaInstrumentation } from "@opentelemetry/instrumentation-koa"
import { MySQL2Instrumentation } from "@opentelemetry/instrumentation-mysql2"
import { MySQLInstrumentation } from "@opentelemetry/instrumentation-mysql"
import { NodeSDK, NodeSDKConfiguration } from "@opentelemetry/sdk-node"
import { NestInstrumentation } from "@opentelemetry/instrumentation-nestjs-core"
import { PgInstrumentation } from "@opentelemetry/instrumentation-pg"
import { PrismaInstrumentation } from "@prisma/instrumentation"
import { RedisDbStatementSerializer } from "./instrumentation/redis/serializer"
Expand All @@ -36,6 +37,7 @@ const DefaultInstrumentations = {
"@opentelemetry/instrumentation-koa": KoaInstrumentation,
"@opentelemetry/instrumentation-mysql2": MySQL2Instrumentation,
"@opentelemetry/instrumentation-mysql": MySQLInstrumentation,
"@opentelemetry/instrumentation-nestjs-core": NestInstrumentation,
"@opentelemetry/instrumentation-pg": PgInstrumentation,
"@opentelemetry/instrumentation-redis": RedisInstrumentation,
"@opentelemetry/instrumentation-redis-4": Redis4Instrumentation,
Expand Down
21 changes: 21 additions & 0 deletions test/helpers/nestjs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

RSpec::Matchers.define :have_nest_context_span do
match do |actual|
context_span = Span.find_by_name!(actual)
raise "No Nest.js request context span found with name: '#{actual}'" unless context_span

Span.root.transitive_parent_of?(context_span) &&
context_span.instrumentation_library_name == "@opentelemetry/instrumentation-nestjs-core"
end
end

RSpec::Matchers.define :have_nest_handler_span do
match do |actual|
handler_span = Span.find_by_name!(actual)
raise "No Nest.js handler span found with name: '#{actual}'" unless handler_span

Span.root.transitive_parent_of?(handler_span) &&
handler_span.instrumentation_library_name == "@opentelemetry/instrumentation-nestjs-core"
end
end

0 comments on commit c07b3a4

Please sign in to comment.