Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Datadog library for Java to enable tracing and custom metric submission from [Azure Functions](https://azure.microsoft.com/en-us/products/functions) and [Google Cloud Run Functions (1st gen)](https://cloud.google.com/functions/1stgendocs/concepts/overview).

## Inventory version metadata

With `DD_SERVERLESS_COMPAT_METADATA_ENABLED=true`, inventory reports the wrapper package as
`serverless_compat_runtime_version`, the embedded binary release as
`serverless_compat_binary_version`, and the language engine in `runtime`.
`DD_SERVERLESS_COMPAT_PATH` selects a custom binary but does not change the wrapper package version.
The binary must supply its own embedded version; an unversioned binary must not inherit the wrapper version.

# Getting Started

- [Install Serverless Monitoring for Azure Functions](https://docs.datadoghq.com/serverless/azure_functions/?code-lang=java)
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/datadog/ServerlessCompatAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,22 @@ public static void premain(String agentArgs, Instrumentation instrumentation) {
String packageVersion = getPackageVersion();
log.debug("Found package version {}", packageVersion);

ProcessBuilder processBuilder = new ProcessBuilder(executableFile.getAbsolutePath());
processBuilder.environment().put("DD_SERVERLESS_COMPAT_VERSION", packageVersion);
ProcessBuilder processBuilder = createProcessBuilder(executableFile, packageVersion, environment);
processBuilder.inheritIO();
processBuilder.start();
} catch (Exception e) {
log.error("Exception when starting {}", fileName, e);
}
}

static ProcessBuilder createProcessBuilder(File executable, String packageVersion, CloudEnvironment environment) {
ProcessBuilder processBuilder = new ProcessBuilder(executable.getAbsolutePath());
Map<String, String> childEnvironment = processBuilder.environment();
childEnvironment.put("DD_SERVERLESS_COMPAT_VERSION", packageVersion);
childEnvironment.put("JAVA_VERSION", System.getProperty("java.version"));
if (environment == CloudEnvironment.AZURE_FUNCTION) {
childEnvironment.put("FUNCTIONS_WORKER_RUNTIME_VERSION", System.getProperty("java.version"));
}
return processBuilder;
}
}
13 changes: 13 additions & 0 deletions src/test/java/com/datadog/ServerlessCompatAgentTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.datadog;

import java.lang.reflect.Method;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
Expand All @@ -13,6 +14,18 @@

class ServerlessCompatAgentTest {

@Test
void childReceivesWrapperAndEngineVersionsForCustomBinary() {
File executable = new File("/custom/compat");
ProcessBuilder child = ServerlessCompatAgent.createProcessBuilder(
executable, "0.25.0", CloudEnvironment.AZURE_FUNCTION);
assertEquals(executable.getAbsolutePath(), child.command().get(0));
assertEquals("0.25.0", child.environment().get("DD_SERVERLESS_COMPAT_VERSION"));
assertEquals(System.getProperty("java.version"), child.environment().get("JAVA_VERSION"));
assertEquals(System.getProperty("java.version"), child.environment().get("FUNCTIONS_WORKER_RUNTIME_VERSION"));
assertEquals(System.getenv("DD_SERVICE"), child.environment().get("DD_SERVICE"));
}

@ParameterizedTest
@CsvSource({
"TRACE, TRACE",
Expand Down