File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ export const decodeAuthorizerContextEnvVar = "DD_DECODE_AUTHORIZER_CONTEXT";
4444export const coldStartTracingEnvVar = "DD_COLD_START_TRACING" ;
4545export const minColdStartTraceDurationEnvVar = "DD_MIN_COLD_START_DURATION" ;
4646export const coldStartTraceSkipLibEnvVar = "DD_COLD_START_TRACE_SKIP_LIB" ;
47+ export const localTestingEnvVar = "DD_LOCAL_TESTING" ;
4748
4849interface GlobalConfig {
4950 /**
@@ -86,6 +87,7 @@ export const defaultConfig: Config = {
8687 siteURL : "" ,
8788 minColdStartTraceDuration : 3 ,
8889 coldStartTraceSkipLib : "" ,
90+ localTesting : false ,
8991} as const ;
9092
9193let currentMetricsListener : MetricsListener | undefined ;
@@ -365,6 +367,14 @@ function getConfig(userConfig?: Partial<Config>): Config {
365367 config . captureLambdaPayloadMaxDepth = Number ( getEnvValue ( captureLambdaPayloadMaxDepthEnvVar , "10" ) ) ;
366368 }
367369
370+ if ( userConfig === undefined || userConfig . localTesting === undefined ) {
371+ const result = getEnvValue ( localTestingEnvVar , "false" ) . toLowerCase ( ) ;
372+ // TODO deprecate 1 for truthy, this shouldn't have been allowed
373+ // but the extension allows it, so we must as well
374+ // @ts -ignore-next-line
375+ config . localTesting = result === "true" || result === "1" ;
376+ }
377+
368378 return config ;
369379}
370380
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ describe("MetricsListener", () => {
3737 enhancedMetrics : false ,
3838 logForwarding : false ,
3939 shouldRetryMetrics : false ,
40+ localTesting : false ,
4041 siteURL,
4142 } ) ;
4243
@@ -56,6 +57,7 @@ describe("MetricsListener", () => {
5657 enhancedMetrics : false ,
5758 logForwarding : false ,
5859 shouldRetryMetrics : false ,
60+ localTesting : false ,
5961 siteURL,
6062 } ) ;
6163
@@ -73,6 +75,7 @@ describe("MetricsListener", () => {
7375 enhancedMetrics : false ,
7476 logForwarding : false ,
7577 shouldRetryMetrics : false ,
78+ localTesting : false ,
7679 siteURL,
7780 } ) ;
7881
@@ -91,6 +94,7 @@ describe("MetricsListener", () => {
9194 enhancedMetrics : false ,
9295 logForwarding : true ,
9396 shouldRetryMetrics : false ,
97+ localTesting : false ,
9498 siteURL,
9599 } ) ;
96100 jest . useFakeTimers ( "legacy" ) ;
@@ -124,6 +128,7 @@ describe("MetricsListener", () => {
124128 enhancedMetrics : false ,
125129 logForwarding : true ,
126130 shouldRetryMetrics : false ,
131+ localTesting : true ,
127132 siteURL,
128133 } ) ;
129134 jest . useFakeTimers ( "legacy" ) ;
@@ -146,6 +151,7 @@ describe("MetricsListener", () => {
146151 enhancedMetrics : false ,
147152 logForwarding : true ,
148153 shouldRetryMetrics : false ,
154+ localTesting : false ,
149155 siteURL,
150156 } ) ;
151157 // jest.useFakeTimers();
Original file line number Diff line number Diff line change @@ -46,6 +46,13 @@ export interface MetricsConfig {
4646 * @default false
4747 */
4848 enhancedMetrics : boolean ;
49+
50+ /**
51+ * Whether to call the extension's Flush endpoint in a local test
52+ * Only needed locally, as the extension knows about the end of the invocation
53+ * from the runtime
54+ */
55+ localTesting : boolean ;
4956}
5057
5158export class MetricsListener {
@@ -114,8 +121,8 @@ export class MetricsListener {
114121 }
115122 }
116123 try {
117- if ( this . isAgentRunning ) {
118- logDebug ( `Flushing Extension` ) ;
124+ if ( this . isAgentRunning && this . config . localTesting ) {
125+ logDebug ( `Flushing Extension for local test ` ) ;
119126 await flushExtension ( ) ;
120127 }
121128 } catch ( error ) {
You can’t perform that action at this time.
0 commit comments