diff --git a/docs/integrations/datadog-apm.md b/docs/integrations/datadog-apm.md index e388cc24..e54c176b 100644 --- a/docs/integrations/datadog-apm.md +++ b/docs/integrations/datadog-apm.md @@ -9,79 +9,44 @@ DevCycle's clientside Javascript SDKs - including JS and React, can be easily in ## Configuration -The DevCycle APM integration provides Traces with more depth by passing in DevCycle variable data during its time of execution, allowing Developers to get a better understanding of the performance impact of each Feature. +The DevCycle APM integration provides Traces with more depth by passing in DevCycle Feature and/or Variable data during its time of execution, allowing Developers to get a better understanding of the performance impact of each Feature. -To add variable data to Traces, we'll retrieve variable data from a DevCycle SDK and add that data as metadata to the active Trace. See the example below. +### Sending Feature Data -#### JavaScript +To add Feature data to Traces, we'll retrieve all of our Feature and Variation data using a DevCycle SDK and add that data as metadata to the active Trace. In our example, we send the Feature key and Variation name to DataDog. This can be customized to your liking. -Fetch the DevCycle variable and format it to our liking: ``` javascript -class DevCycleTracingPatchService { - constructor(devcycleClient) { - this.devcycleClient = devcycleClient; - - const originalVariable = this.devcycleClient.variable.bind(this.devcycleClient); - - this.devcycleClient.variable = (user, key, defaultValue) => { - const variable = originalVariable(user, key, defaultValue); - addTraceMetadata({ - [`devcycle.${key}`]: JSON.stringify(variable.value), - }); - return variable; - }; - } +const features = devcycleClient.allFeatures() + +const span = tracer.scope().active(); +if (span) { + const rootSpan = span.context()._trace.started[0]; + Object.entries(features).forEach(([key, metadata]) => { + rootSpan?.setTag(key, metadata['variationName']); + }); } ``` -Add the variable to the Trace as Metadata: +### Sending Variable Data + +To add DevCycle Variables to Traces, we'll retrieve Variable data from a DevCycle SDK and add that data as metadata to the active Trace. A simple way to pass along multiple Variables and its values to DataDog is shown below. ``` javascript -function addTraceMetadata(metadata) { - const span = tracer.scope().active(); - if (span) { - const rootSpan = span.context()._trace.started[0]; // Assumes specific tracer structure - Object.entries(metadata).forEach(([key, value]) => { - rootSpan?.setTag(key, value); - }); - } -} -``` +const variableA = dvcClient.variable('new-homepage-hero', 'defaultValue'); +const variableB = dvcClient.variable('new-homepage-layout', 'defaultValue'); -#### React - -Fetch the DevCycle variable and format it to our liking: - -``` jsx -@Injectable() -export class DevCycleTracingPatchService { - constructor(private devcycleClient: DevCycleClient) { - const originalVariable = this.devcycleClient.variable.bind( - this.devcycleClient, - ) - this.devcycleClient.variable = (user, key, defaultValue) => { - const variable = originalVariable(user, key, defaultValue) - addTraceMetadata({ - [`devcycle.${key}`]: JSON.stringify(variable.value), - }) - return variable - } - } +const variables = { + variableA: variableA.value, + variableB: variableB.value, } -``` -Add the variable to the Trace as Metadata: - -``` jsx -export function addTraceMetadata(metadata: Record) { - const span = tracer.scope().active() - if (span) { - const rootSpan = (span.context() as any)._trace.started[0] - Object.entries(metadata).forEach(([key, value]) => { - rootSpan?.setTag(key, value) - }) - } +const span = tracer.scope().active(); +if (span) { + const rootSpan = span.context()._trace.started[0]; + Object.entries(variables).forEach(([key, value]) => { + rootSpan?.setTag(key, value); + }); } ```