-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to enable observability (APM, transactions, spans) (#1578)
- Loading branch information
1 parent
e418635
commit f3caeaf
Showing
8 changed files
with
816 additions
and
107 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
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,60 @@ | ||
import apm from 'elastic-apm-node' | ||
import process from 'node:process' | ||
import { logger } from './logger.js' | ||
|
||
const serviceName = process.env.KROKI_ELASTIC_APM_SERVICE_NAME || 'kroki-mermaid' | ||
const secretToken = process.env.KROKI_ELASTIC_APM_SECRET_TOKEN | ||
const serverUrl = process.env.KROKI_ELASTIC_APM_SECRET_URL | ||
const environment = process.env.KROKI_ELASTIC_APM_ENVIRONMENT || 'prod' | ||
|
||
if (secretToken && serverUrl) { | ||
try { | ||
apm.start({ | ||
serviceName, | ||
secretToken, | ||
serverUrl, | ||
environment | ||
}) | ||
} catch (err) { | ||
logger.error({ err }, 'Unable to start Elastic APM') | ||
} | ||
} | ||
|
||
/** | ||
* @param {string} name | ||
* @param {string} type | ||
* @param {apm.Labels} [labels] | ||
* @param {SpanOptions} [opts] | ||
* @returns {Span|undefined} | ||
*/ | ||
export function startSpan (name, type, labels, opts) { | ||
if (apm.isStarted()) { | ||
const span = apm.startSpan(name, opts) | ||
if (labels) { | ||
span.addLabels(labels) | ||
} | ||
return span | ||
} | ||
} | ||
|
||
/** | ||
* @param {Span|undefined} span | ||
*/ | ||
export function successfulSpan (span) { | ||
if (span) { | ||
span.setOutcome('success') | ||
span.end() | ||
} | ||
} | ||
|
||
/** | ||
* @param span | ||
* @param {Error} err | ||
*/ | ||
export function failureSpan (span, err) { | ||
if (span) { | ||
apm.logger.error({ err }) | ||
span.setOutcome('failure') | ||
span.end() | ||
} | ||
} |
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