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: update APM instrumentation (#10)
- Loading branch information
1 parent
27001a0
commit 477fde4
Showing
9 changed files
with
156 additions
and
154 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
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,39 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { ConfigService } from '@nestjs/config' | ||
import apm, * as ElasticAPM from 'elastic-apm-node' | ||
|
||
@Injectable() | ||
export class ApmService { | ||
private _apm: ElasticAPM.Agent | ||
|
||
constructor(private configService: ConfigService) { | ||
this._apm = ElasticAPM.start({ | ||
serviceName: | ||
this.configService.get('TRACING_SERVICE_NAME') || 'faucet-server', | ||
secretToken: this.configService.get('ELASTIC_APM_TOKEN') || '', | ||
serverUrl: this.configService.get('ELASTIC_APM_ENDPOINT') || '', | ||
environment: | ||
this.configService.get('TRACING_SERVICE_VERSION') || 'unknown', | ||
captureBody: 'all', | ||
}) | ||
} | ||
|
||
startTransaction(name: string, traceparent?: string) { | ||
return this._apm.startTransaction( | ||
name, | ||
traceparent | ||
? { | ||
childOf: traceparent, | ||
} | ||
: undefined | ||
) | ||
} | ||
|
||
startChildSpan(name: string) { | ||
return this._apm.startSpan(name) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { Module } from '@nestjs/common' | ||
|
||
import { ApmModule } from '../apm/apm.module' | ||
import { FaucetController } from './faucet.controller' | ||
import { FaucetService } from './faucet.service' | ||
|
||
@Module({ | ||
controllers: [FaucetController], | ||
imports: [ApmModule], | ||
providers: [FaucetService], | ||
}) | ||
export class FaucetModule {} |
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
Oops, something went wrong.