A Datadog wrapper library to enable DD APM and tag API traces
npm install --save-exact @bufferapp/bufftracer
This should be the first import in your index.ts
file.
import '@bufferapp/bufftracer'
// core-api.yaml
- name: DD_TRACING_ENABLED
value: 'true'
- name: DD_SERVICE_NAME
value: 'core-api'
- name: DD_TRACE_AGENT_HOSTNAME
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: DD_TRACE_AGENT_PORT
value: '8126'
- name: NODE_ENV # or APP_STAGE
value: production
The library parses the incoming request, generates metadata, sets DD resource name to be the edge/endpoint and tags the DD span with the metadata.
type APIRequestMetadata = {
name: 'core-api' | string
type: 'graphql' | 'rpc' | 'rest'
client: 'buffertools-graphql-playground' | string
edge: string
fields: Array<string>
deprecatedFields: Array<string>
args: Array<string>
}
The DD APM tags are then used to generate DD custom metrics named api.request
, which we can use to build dashboard and know who is consuming which parts of our API.
The version 1.0.0 contains breaking changes. In order to upgrade you need to make the following changes in your application:
- Requires Node.js version v18 or greater
- Change the environment variable
DD_ENABLE_TRACING
toDD_TRACING_ENABLED