Files
outline/server/logging/tracing.ts
Tom Moor 963475d2b0 fix: Queue retry behavior (#3359)
* fix: Queue retry behavior

* Add default options for task queue
2022-04-10 17:50:42 -07:00

48 lines
1.2 KiB
TypeScript

import { init, tracer, addTags, markAsError } from "@theo.gravity/datadog-apm";
export * as APM from "@theo.gravity/datadog-apm";
// If the DataDog agent is installed and the DD_API_KEY environment variable is
// in the environment then we can safely attempt to start the DD tracer
if (process.env.DD_API_KEY) {
init(
{
// SOURCE_COMMIT is used by Docker Hub
// SOURCE_VERSION is used by Heroku
version: process.env.SOURCE_COMMIT || process.env.SOURCE_VERSION,
service: "outline",
},
{
useMock: process.env.NODE_ENV === "test",
}
);
}
/**
* Change the resource of the active APM span. This method wraps addTags to allow
* safe use in environments where APM is disabled.
*
* @param name The name of the resource
*/
export function setResource(name: string) {
if (tracer) {
addTags({
"resource.name": `${name}`,
});
}
}
/**
* Mark the current active span as an error. This method wraps addTags to allow
* safe use in environments where APM is disabled.
*
* @param error The error to add
*/
export function setError(error: Error) {
if (tracer) {
markAsError(error);
}
}
export default tracer;