11'use strict'
22
3- const log = require ( './log' )
4-
5- function maybeStartServerlessMiniAgent ( config ) {
6- if ( process . platform !== 'win32' && process . platform !== 'linux' ) {
7- log . error ( 'Serverless Mini Agent is only supported on Windows and Linux.' )
8- return
9- }
10-
11- const rustBinaryPath = getRustBinaryPath ( config )
12-
13- const fs = require ( 'fs' )
14-
15- log . debug ( `Trying to spawn the Serverless Mini Agent at path: ${ rustBinaryPath } ` )
16-
17- // trying to spawn with an invalid path will return a non-descriptive error, so we want to catch
18- // invalid paths and log our own error.
19- if ( ! fs . existsSync ( rustBinaryPath ) ) {
20- log . error ( 'Serverless Mini Agent did not start. Could not find mini agent binary.' )
21- return
22- }
23- try {
24- require ( 'child_process' ) . spawn ( rustBinaryPath , { stdio : 'inherit' } )
25- } catch ( err ) {
26- log . error ( 'Error spawning mini agent process: %s' , err . message )
27- }
28- }
29-
30- function getRustBinaryPath ( config ) {
31- if ( process . env . DD_MINI_AGENT_PATH !== undefined ) {
32- return process . env . DD_MINI_AGENT_PATH
33- }
34-
35- const rustBinaryPathRoot = config . isGCPFunction ? '/workspace' : '/home/site/wwwroot'
36- const rustBinaryPathOsFolder = process . platform === 'win32'
37- ? 'datadog-serverless-agent-windows-amd64'
38- : 'datadog-serverless-agent-linux-amd64'
39-
40- const rustBinaryExtension = process . platform === 'win32' ? '.exe' : ''
41-
42- const rustBinaryPath =
43- `${ rustBinaryPathRoot } /node_modules/@datadog/sma/${ rustBinaryPathOsFolder } /\
44- datadog-serverless-trace-mini-agent${ rustBinaryExtension } `
45-
46- return rustBinaryPath
47- }
48-
493function getIsGCPFunction ( ) {
504 const isDeprecatedGCPFunction = process . env . FUNCTION_NAME !== undefined && process . env . GCP_PROJECT !== undefined
515 const isNewerGCPFunction = process . env . K_SERVICE !== undefined && process . env . FUNCTION_TARGET !== undefined
@@ -69,9 +23,7 @@ function isInServerlessEnvironment () {
6923}
7024
7125module . exports = {
72- maybeStartServerlessMiniAgent,
7326 getIsGCPFunction,
7427 getIsAzureFunction,
75- getRustBinaryPath,
7628 isInServerlessEnvironment
7729}
0 commit comments