This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use elastic apm instrumentation (#15)
- Loading branch information
1 parent
0394885
commit 1bf66b1
Showing
17 changed files
with
2,724 additions
and
1,458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common' | ||
import { ConfigModule } from '@nestjs/config' | ||
|
||
import { ApmService } from './apm.service' | ||
|
||
@Module({ | ||
imports: [ConfigModule], | ||
exports: [ApmService], | ||
providers: [ApmService], | ||
}) | ||
export class ApmModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { ConfigService } from '@nestjs/config' | ||
import * as ElasticAPM from 'elastic-apm-node' | ||
|
||
export const SERVICE_NAME = | ||
process.env.TRACING_SERVICE_NAME || 'executor-service' | ||
export const SERVICE_VERSION = process.env.TRACING_SERVICE_VERSION || 'unknown' | ||
export const ELASTIC_APM_ENDPOINT = process.env.ELASTIC_APM_ENDPOINT || '' | ||
export const ELASTIC_APM_TOKEN = process.env.ELASTIC_APM_TOKEN || '' | ||
|
||
@Injectable() | ||
export class ApmService { | ||
private _apm: ElasticAPM.Agent | ||
|
||
constructor(private configService: ConfigService) { | ||
this._apm = ElasticAPM.start({ | ||
serviceName: | ||
this.configService.get('TRACING_SERVICE_NAME') || 'executor-service', | ||
secretToken: this.configService.get('ELASTIC_APM_TOKEN') || '', | ||
serverUrl: this.configService.get('ELASTIC_APM_ENDPOINT') || '', | ||
environment: this.configService.get('SERVICE_VERSION') || 'unknown', | ||
opentelemetryBridgeEnabled: true, | ||
captureBody: 'all', | ||
}) | ||
} | ||
|
||
startTransaction(name: string, traceparent?: string) { | ||
return this._apm.startTransaction( | ||
name, | ||
traceparent | ||
? { | ||
childOf: traceparent, | ||
} | ||
: undefined | ||
) | ||
} | ||
|
||
captureError(error: string) { | ||
this._apm.captureError(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { BullModule } from '@nestjs/bull' | ||
import { Module } from '@nestjs/common' | ||
import { ConfigModule } from '@nestjs/config' | ||
import { ConfigService } from '@nestjs/config' | ||
|
||
import { ApmModule } from '../apm/apm.module' | ||
import { AuthModule } from '../auth/auth.module' | ||
import { ExecuteControllerV1 } from './execute.controller' | ||
import { ExecutionProcessorV1 } from './execute.processor' | ||
import { ExecuteServiceV1 } from './execute.service' | ||
|
||
@Module({ | ||
controllers: [ExecuteControllerV1], | ||
imports: [ConfigModule, BullModule.registerQueue({ name: 'execute' })], | ||
providers: [ExecutionProcessorV1, ExecuteServiceV1], | ||
imports: [BullModule.registerQueue({ name: 'execute' }), ApmModule, AuthModule], | ||
providers: [ExecutionProcessorV1, ExecuteServiceV1, ConfigService], | ||
}) | ||
export class ExecuteModuleV1 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.