-
Notifications
You must be signed in to change notification settings - Fork 20
feat(config): add DD_SERVERLESS_APM_ONLY traces-only mode #1293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3f4006a
feat(config): add DD_SERVERLESS_APM_ONLY traces-only mode
zarirhamza 7deb818
Merge branch 'main' into zarir.hamza/serverless-apm-only-v2
zarirhamza 1d11f21
test(config): add YAML test + drain logs aggregator in APM-only mode
zarirhamza a1b1b89
refactor(config): rename flag to DD_APM_STANDALONE_ENABLED + add inte…
zarirhamza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ test_suites: | |
| - name: lmi-oom | ||
| - name: payload-size | ||
| - name: durable-cold-start | ||
| - name: apm-standalone | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -259,6 +259,19 @@ impl LogsFlusher { | |
| &self, | ||
| retry_request: Option<reqwest::RequestBuilder>, | ||
| ) -> Vec<reqwest::RequestBuilder> { | ||
| // APM standalone ("traces only") mode: never send logs to intake. Logs are | ||
| // also dropped upstream (serverless_logs_enabled is forced off, so the | ||
| // processor never queues them), but this guard guarantees no log egress | ||
| // regardless of aggregator or redrive state. See DD_APM_STANDALONE_ENABLED. | ||
| if self.config.ext.apm_standalone_enabled { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't there like an "enabled" section where we'd just add this? |
||
| // Drain and discard any queued batches so the aggregator stays bounded, | ||
| // mirroring the metrics path (which drains its aggregator and discards | ||
| // the data because no flusher is wired up). No requests are ever | ||
| // produced here, so nothing reaches intake. | ||
| let _ = self.aggregator_handle.get_batches().await; | ||
| return Vec::new(); | ||
| } | ||
|
|
||
| let mut failed_requests = Vec::new(); | ||
|
|
||
| // If retry_request is provided, only process that request | ||
|
|
||
This file contains hidden or 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 hidden or 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,57 @@ | ||
| import * as cdk from "aws-cdk-lib"; | ||
| import * as lambda from "aws-cdk-lib/aws-lambda"; | ||
| import { Construct } from "constructs"; | ||
| import { | ||
| createLogGroup, | ||
| defaultDatadogEnvVariables, | ||
| defaultDatadogSecretPolicy, | ||
| getExtensionLayer, | ||
| getDefaultNodeLayer, | ||
| defaultNodeRuntime, | ||
| } from "../util"; | ||
|
|
||
| /** | ||
| * Two functions that emit the same telemetry (a trace, a custom DogStatsD | ||
| * metric, and logs). The baseline runs with the default config; the standalone | ||
| * function additionally sets DD_APM_STANDALONE_ENABLED=true. The test asserts | ||
| * that traces survive for both, while metrics and logs are suppressed for the | ||
| * standalone function — even though DD_SERVERLESS_LOGS_ENABLED=true is inherited | ||
| * from the default env, which APM standalone mode must override. | ||
| */ | ||
| export class ApmStandalone extends cdk.Stack { | ||
| constructor(scope: Construct, id: string, props: cdk.StackProps) { | ||
| super(scope, id, props); | ||
|
|
||
| const extensionLayer = getExtensionLayer(this); | ||
| const nodeLayer = getDefaultNodeLayer(this); | ||
|
|
||
| const makeFunction = (name: string, extraEnv: Record<string, string>) => { | ||
| const fn = new lambda.Function(this, name, { | ||
| runtime: defaultNodeRuntime, | ||
| architecture: lambda.Architecture.ARM_64, | ||
| handler: "/opt/nodejs/node_modules/datadog-lambda-js/handler.handler", | ||
| code: lambda.Code.fromAsset("./lambda/custom-metrics-node"), | ||
| functionName: name, | ||
| timeout: cdk.Duration.seconds(30), | ||
| memorySize: 256, | ||
| environment: { | ||
| ...defaultDatadogEnvVariables, | ||
| DD_SERVICE: name, | ||
| DD_TRACE_ENABLED: "true", | ||
| DD_LAMBDA_HANDLER: "index.handler", | ||
| ...extraEnv, | ||
| }, | ||
| logGroup: createLogGroup(this, name), | ||
| }); | ||
| fn.addToRolePolicy(defaultDatadogSecretPolicy); | ||
| fn.addLayers(extensionLayer); | ||
| fn.addLayers(nodeLayer); | ||
| return fn; | ||
| }; | ||
|
|
||
| makeFunction(`${id}-baseline-lambda`, {}); | ||
| makeFunction(`${id}-standalone-lambda`, { | ||
| DD_APM_STANDALONE_ENABLED: "true", | ||
| }); | ||
| } | ||
| } |
This file contains hidden or 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,131 @@ | ||
| import { | ||
| getInvocationTracesLogsByRequestId, | ||
| getMetricCount, | ||
| DatadogSpan, | ||
| DatadogTrace, | ||
| } from './utils/datadog'; | ||
| import { forceColdStart, invokeLambda } from './utils/lambda'; | ||
| import { IDENTIFIER, DEFAULT_DATADOG_INDEXING_WAIT_MS } from '../config'; | ||
|
|
||
| const stackName = `${IDENTIFIER}-apm-standalone`; | ||
|
|
||
| // Enhanced (billable) metric the extension emits per invocation in normal mode. | ||
| const ENHANCED_INVOCATIONS_METRIC = 'aws.lambda.enhanced.invocations'; | ||
| // Custom DogStatsD metric emitted by the custom-metrics-node handler. | ||
| const CUSTOM_METRIC = 'custom.exclude_tags_test'; | ||
|
|
||
| function sleep(ms: number): Promise<void> { | ||
| return new Promise(resolve => setTimeout(resolve, ms)); | ||
| } | ||
|
|
||
| function hasAwsLambdaSpan(traces: DatadogTrace[] | undefined): boolean { | ||
| return (traces ?? []) | ||
| .flatMap((t: DatadogTrace) => t.spans) | ||
| .some((s: DatadogSpan) => s.attributes?.operation_name === 'aws.lambda'); | ||
| } | ||
|
|
||
| describe('APM Standalone Integration Tests', () => { | ||
| const baselineFunctionName = `${stackName}-baseline-lambda`; | ||
| const standaloneFunctionName = `${stackName}-standalone-lambda`; | ||
|
|
||
| let invocationStartTime: number; | ||
| let metricsEndTime: number; | ||
| let baseline: Awaited<ReturnType<typeof getInvocationTracesLogsByRequestId>>; | ||
| let standalone: Awaited<ReturnType<typeof getInvocationTracesLogsByRequestId>>; | ||
|
|
||
| beforeAll(async () => { | ||
| const functionNames = [baselineFunctionName, standaloneFunctionName]; | ||
|
|
||
| await Promise.all(functionNames.map(fn => forceColdStart(fn))); | ||
|
|
||
| // Back up the metric query window so the rollup bucket (aligned to the | ||
| // interval boundary, often just before the invocation) falls in range. | ||
| invocationStartTime = Date.now() - 60_000; | ||
|
|
||
| const [baselineInv, standaloneInv] = await Promise.all( | ||
| functionNames.map(fn => invokeLambda(fn)), | ||
| ); | ||
|
|
||
| await sleep(DEFAULT_DATADOG_INDEXING_WAIT_MS); | ||
| metricsEndTime = Date.now(); | ||
|
|
||
| baseline = await getInvocationTracesLogsByRequestId( | ||
| baselineFunctionName, | ||
| baselineInv.requestId, | ||
| ); | ||
| standalone = await getInvocationTracesLogsByRequestId( | ||
| standaloneFunctionName, | ||
| standaloneInv.requestId, | ||
| ); | ||
|
|
||
| console.log('Invocation and telemetry collection complete'); | ||
| }, 1800000); | ||
|
|
||
| // Traces are unaffected by APM standalone mode — both functions should | ||
| // produce a full trace with the inferred aws.lambda root span. | ||
| describe('traces (preserved in both modes)', () => { | ||
| it('baseline should have the aws.lambda root span', () => { | ||
| expect(hasAwsLambdaSpan(baseline.traces)).toBe(true); | ||
| }); | ||
|
|
||
| it('standalone should still have the aws.lambda root span', () => { | ||
| expect(hasAwsLambdaSpan(standalone.traces)).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe('enhanced metrics', () => { | ||
| it('baseline should emit aws.lambda.enhanced.invocations', async () => { | ||
| const count = await getMetricCount( | ||
| ENHANCED_INVOCATIONS_METRIC, | ||
| baselineFunctionName, | ||
| invocationStartTime, | ||
| metricsEndTime, | ||
| ); | ||
| expect(count).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('standalone should NOT emit aws.lambda.enhanced.invocations', async () => { | ||
| const count = await getMetricCount( | ||
| ENHANCED_INVOCATIONS_METRIC, | ||
| standaloneFunctionName, | ||
| invocationStartTime, | ||
| metricsEndTime, | ||
| ); | ||
| expect(count).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('custom DogStatsD metrics', () => { | ||
| it('baseline should emit the custom metric', async () => { | ||
| const count = await getMetricCount( | ||
| CUSTOM_METRIC, | ||
| baselineFunctionName, | ||
| invocationStartTime, | ||
| metricsEndTime, | ||
| ); | ||
| expect(count).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('standalone should NOT emit the custom metric', async () => { | ||
| const count = await getMetricCount( | ||
| CUSTOM_METRIC, | ||
| standaloneFunctionName, | ||
| invocationStartTime, | ||
| metricsEndTime, | ||
| ); | ||
| expect(count).toBe(0); | ||
| }); | ||
| }); | ||
|
|
||
| // Logs must be suppressed even though DD_SERVERLESS_LOGS_ENABLED=true is | ||
| // inherited from the default env — APM standalone mode forces it off. | ||
| describe('logs', () => { | ||
| it('baseline should forward logs to Datadog', () => { | ||
| expect(baseline.logs?.length ?? 0).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it('standalone should NOT forward any logs to Datadog', () => { | ||
| expect(standalone.logs?.length ?? 0).toBe(0); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.