-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
3,914 additions
and
64 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
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,24 @@ | ||
import { ParameterizedMessageObject, Span, Transaction } from 'elastic-apm-node' | ||
|
||
import apm from 'elastic-apm-node' | ||
|
||
function readConfig() { | ||
if (process.env.ELASTIC_APM_SERVER_URL && process.env.ELASTIC_APM_API_KEY && process.env.ELASTIC_APM_ENVIRONMENT) { | ||
return { | ||
ELASTIC_APM_SERVER_URL: process.env.ELASTIC_APM_SERVER_URL, | ||
ELASTIC_APM_API_KEY: process.env.ELASTIC_APM_API_KEY, | ||
ELASTIC_APM_ENVIRONMENT: process.env.ELASTIC_APM_ENVIRONMENT, | ||
} | ||
} | ||
} | ||
export const apmConfig = readConfig() | ||
|
||
export const startTransaction = (...args: any[]): Transaction => { | ||
return apm.startTransaction(...args) | ||
} | ||
export const captureError = (err: Error | string | ParameterizedMessageObject) => { | ||
return apm.captureError(err) | ||
} | ||
export const startSpan = (...args: any[]): Span | any => { | ||
return apm.startSpan(...args) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
import { apm } from '../config/tracer' | ||
|
||
export const prisma = new PrismaClient() | ||
|
||
if (process.env.ELASTIC_APM_SERVER_URL && process.env.ELASTIC_APM_API_KEY) { | ||
prisma.$use(async (params: any, next: any) => { | ||
const spanName = params.model ? `prisma.${params.model}.${params.action}` : `prisma.${params.action}` | ||
const span = apm.startSpan(spanName) | ||
if (span) { | ||
span.type = 'DB' | ||
span.subtype = 'prisma' | ||
span.action = 'query' | ||
} | ||
try { | ||
const result = await next(params) | ||
span?.end() | ||
return result | ||
} catch (e) { | ||
span?.end() | ||
throw e | ||
} | ||
}) | ||
} |
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
Oops, something went wrong.