Skip to content

Commit 601469c

Browse files
committed
Tag profiles for serverless
1 parent 56d4919 commit 601469c

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

dd-java-agent/agent-profiling/profiling-uploader/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies {
2323
implementation libs.slf4j
2424
implementation project(':communication')
2525
implementation project(':internal-api')
26+
implementation project(':utils:container-utils')
2627
implementation project(':utils:socket-utils')
2728
implementation project(':utils:version-utils')
2829

dd-java-agent/agent-profiling/profiling-uploader/src/main/java/com/datadog/profiling/uploader/ProfileUploader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.squareup.moshi.JsonAdapter;
2222
import com.squareup.moshi.JsonReader;
2323
import com.squareup.moshi.JsonWriter;
24+
import datadog.common.container.ServerlessInfo;
2425
import datadog.common.version.VersionInfo;
2526
import datadog.communication.http.OkHttpUtils;
2627
import datadog.trace.api.Config;
@@ -110,6 +111,8 @@ public final class ProfileUploader {
110111
+ V4_ATTACHMENT_FILENAME
111112
+ "\"");
112113

114+
static final String SERVELESS_TAG = "functionname";
115+
113116
private final Config config;
114117
private final ConfigProvider configProvider;
115118

@@ -173,6 +176,9 @@ public ProfileUploader(final Config config, final ConfigProvider configProvider)
173176
if (Platform.isNativeImage()) {
174177
tagsMap.put(DDTags.RUNTIME_VERSION_TAG, tagsMap.get(DDTags.RUNTIME_VERSION_TAG) + "-aot");
175178
}
179+
if (ServerlessInfo.get().isRunningInServerlessEnvironment()) {
180+
tagsMap.put(SERVELESS_TAG, ServerlessInfo.get().getFunctionName());
181+
}
176182

177183
// Comma separated tags string for V2.4 format
178184
Pattern quotes = Pattern.compile("\"");

dd-java-agent/agent-profiling/profiling-uploader/src/test/java/com/datadog/profiling/uploader/ProfileUploaderTest.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616
package com.datadog.profiling.uploader;
1717

18-
import static com.datadog.profiling.uploader.ProfileUploader.V4_PROFILE_END_PARAM;
19-
import static com.datadog.profiling.uploader.ProfileUploader.V4_PROFILE_START_PARAM;
18+
import static com.datadog.profiling.uploader.ProfileUploader.*;
2019
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2120
import static org.junit.jupiter.api.Assertions.assertEquals;
2221
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -81,6 +80,7 @@
8180
import org.apache.commons.fileupload.FileItem;
8281
import org.apache.commons.io.IOUtils;
8382
import org.junit.jupiter.api.AfterEach;
83+
import org.junit.jupiter.api.BeforeAll;
8484
import org.junit.jupiter.api.BeforeEach;
8585
import org.junit.jupiter.api.Test;
8686
import org.junit.jupiter.api.extension.ExtendWith;
@@ -104,6 +104,8 @@ public class ProfileUploaderTest {
104104

105105
private static final Map<String, String> TAGS;
106106

107+
private static final String FUNCTION_NAME = "my_function";
108+
107109
static {
108110
// Not using Guava's ImmutableMap because we want to test null value
109111
final Map<String, String> tags = new HashMap<>();
@@ -120,6 +122,7 @@ public class ProfileUploaderTest {
120122
new ImmutableMap.Builder<String, String>()
121123
.put("baz", "123")
122124
.put("foo", "bar")
125+
.put(SERVELESS_TAG, FUNCTION_NAME)
123126
.put("quoted", "quoted")
124127
.put(DDTags.PID_TAG, PidHelper.getPid())
125128
.put(VersionInfo.PROFILER_VERSION_TAG, VersionInfo.VERSION)
@@ -149,6 +152,20 @@ public class ProfileUploaderTest {
149152

150153
private ProfileUploader uploader;
151154

155+
@BeforeAll
156+
static void setUpAll() throws Exception {
157+
Map<String, String> env = System.getenv();
158+
159+
Field field = env.getClass().getDeclaredField("m");
160+
field.setAccessible(true);
161+
162+
@SuppressWarnings("unchecked")
163+
Map<String, String> modifiableEnv = (Map<String, String>) field.get(env);
164+
// hard-coding the env variable here; we could theoretically make the field from ServerlessInfo
165+
// public instead
166+
modifiableEnv.put("AWS_LAMBDA_FUNCTION_NAME", FUNCTION_NAME);
167+
}
168+
152169
@BeforeEach
153170
public void setup() throws IOException {
154171
server.start();

internal-api/src/main/java/datadog/trace/api/Config.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static datadog.trace.api.ConfigDefaults.*;
44
import static datadog.trace.api.DDTags.*;
5-
import static datadog.trace.api.DDTags.PROFILING_ENABLED;
65
import static datadog.trace.api.config.AppSecConfig.*;
76
import static datadog.trace.api.config.CiVisibilityConfig.*;
87
import static datadog.trace.api.config.CrashTrackingConfig.*;
@@ -3410,7 +3409,7 @@ public Map<String, Object> getLocalRootSpanTags() {
34103409
result.putAll(runtimeTags);
34113410
result.put(LANGUAGE_TAG_KEY, LANGUAGE_TAG_VALUE);
34123411
result.put(SCHEMA_VERSION_TAG_KEY, SpanNaming.instance().version());
3413-
result.put(PROFILING_ENABLED, isProfilingEnabled() ? 1 : 0);
3412+
result.put(DDTags.PROFILING_ENABLED, isProfilingEnabled() ? 1 : 0);
34143413
if (isAppSecStandaloneEnabled()) {
34153414
result.put(APM_ENABLED, 0);
34163415
}

0 commit comments

Comments
 (0)