Skip to content

Commit a878d96

Browse files
committed
add back fileExists method
1 parent aabccdf commit a878d96

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
setLogger,
1414
setLogLevel,
1515
} from "./utils";
16-
import { extensionEnabled } from "./utils/extension-enabled";
16+
import { getExtensionPath } from "./utils/extension-path";
17+
import { existsSync } from "fs";
1718

1819
export { TraceHeaders } from "./trace";
1920

@@ -301,6 +302,8 @@ function isExtensionEnabled(): boolean {
301302
if (isExtension !== undefined) {
302303
return isExtension;
303304
}
304-
isExtension = extensionEnabled();
305+
306+
const extensionPath = getExtensionPath();
307+
isExtension = existsSync(extensionPath);
305308
return isExtension;
306309
}

src/metrics/extension.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { URL } from "url";
22
import { get, post, logDebug, logError } from "../utils";
3-
import { extensionEnabled } from "../utils/extension-enabled";
3+
import { getExtensionPath } from "../utils/extension-path";
4+
import fs from "fs";
45

56
export const AGENT_URL = "http://127.0.0.1:8124";
67
const HELLO_PATH = "/lambda/hello";
78
const FLUSH_PATH = "/lambda/flush";
89
const AGENT_TIMEOUT_MS = 100;
910

1011
export async function isAgentRunning() {
11-
const extensionExists = extensionEnabled();
12+
const extensionPath = getExtensionPath();
13+
const extensionExists = await fileExists(extensionPath);
1214
if (!extensionExists) {
1315
logDebug(`Agent isn't present in sandbox`);
1416
return false;
@@ -32,3 +34,10 @@ export async function flushExtension(): Promise<boolean> {
3234
}
3335
return true;
3436
}
37+
38+
function fileExists(filename: string): Promise<boolean> {
39+
return fs.promises
40+
.access(filename, fs.constants.F_OK)
41+
.then(() => true)
42+
.catch(() => false);
43+
}

src/utils/extension-enabled.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/utils/extension-path.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const EXTENSION_PATH = "/opt/extensions/datadog-agent";
2+
3+
export function getExtensionPath() {
4+
return EXTENSION_PATH;
5+
}

0 commit comments

Comments
 (0)