Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag profiles for serverless #8279

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
implementation libs.slf4j
implementation project(':communication')
implementation project(':internal-api')
implementation project(':utils:container-utils')
implementation project(':utils:socket-utils')
implementation project(':utils:version-utils')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.JsonReader;
import com.squareup.moshi.JsonWriter;
import datadog.common.container.ServerlessInfo;
import datadog.common.version.VersionInfo;
import datadog.communication.http.OkHttpUtils;
import datadog.trace.api.Config;
Expand Down Expand Up @@ -110,6 +111,8 @@ public final class ProfileUploader {
+ V4_ATTACHMENT_FILENAME
+ "\"");

static final String SERVELESS_TAG = "functionname";

private final Config config;
private final ConfigProvider configProvider;

Expand Down Expand Up @@ -173,6 +176,9 @@ public ProfileUploader(final Config config, final ConfigProvider configProvider)
if (Platform.isNativeImage()) {
tagsMap.put(DDTags.RUNTIME_VERSION_TAG, tagsMap.get(DDTags.RUNTIME_VERSION_TAG) + "-aot");
}
if (ServerlessInfo.get().isRunningInServerlessEnvironment()) {
tagsMap.put(SERVELESS_TAG, ServerlessInfo.get().getFunctionName());
}

// Comma separated tags string for V2.4 format
Pattern quotes = Pattern.compile("\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
package com.datadog.profiling.uploader;

import static com.datadog.profiling.uploader.ProfileUploader.V4_PROFILE_END_PARAM;
import static com.datadog.profiling.uploader.ProfileUploader.V4_PROFILE_START_PARAM;
import static com.datadog.profiling.uploader.ProfileUploader.*;
PerfectSlayer marked this conversation as resolved.
Show resolved Hide resolved
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -81,6 +80,7 @@
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -104,6 +104,8 @@ public class ProfileUploaderTest {

private static final Map<String, String> TAGS;

private static final String FUNCTION_NAME = "my_function";

static {
// Not using Guava's ImmutableMap because we want to test null value
final Map<String, String> tags = new HashMap<>();
Expand All @@ -120,6 +122,7 @@ public class ProfileUploaderTest {
new ImmutableMap.Builder<String, String>()
.put("baz", "123")
.put("foo", "bar")
.put(SERVELESS_TAG, FUNCTION_NAME)
.put("quoted", "quoted")
.put(DDTags.PID_TAG, PidHelper.getPid())
.put(VersionInfo.PROFILER_VERSION_TAG, VersionInfo.VERSION)
Expand Down Expand Up @@ -149,6 +152,20 @@ public class ProfileUploaderTest {

private ProfileUploader uploader;

@BeforeAll
static void setUpAll() throws Exception {
Map<String, String> env = System.getenv();

Field field = env.getClass().getDeclaredField("m");
field.setAccessible(true);

@SuppressWarnings("unchecked")
Map<String, String> modifiableEnv = (Map<String, String>) field.get(env);
// hard-coding the env variable here; we could theoretically make the field from ServerlessInfo
// public instead
modifiableEnv.put("AWS_LAMBDA_FUNCTION_NAME", FUNCTION_NAME);
}

@BeforeEach
public void setup() throws IOException {
server.start();
Expand Down
3 changes: 1 addition & 2 deletions internal-api/src/main/java/datadog/trace/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static datadog.trace.api.ConfigDefaults.*;
import static datadog.trace.api.DDTags.*;
import static datadog.trace.api.DDTags.PROFILING_ENABLED;
import static datadog.trace.api.config.AppSecConfig.*;
import static datadog.trace.api.config.CiVisibilityConfig.*;
import static datadog.trace.api.config.CrashTrackingConfig.*;
Expand Down Expand Up @@ -3410,7 +3409,7 @@ public Map<String, Object> getLocalRootSpanTags() {
result.putAll(runtimeTags);
result.put(LANGUAGE_TAG_KEY, LANGUAGE_TAG_VALUE);
result.put(SCHEMA_VERSION_TAG_KEY, SpanNaming.instance().version());
result.put(PROFILING_ENABLED, isProfilingEnabled() ? 1 : 0);
result.put(DDTags.PROFILING_ENABLED, isProfilingEnabled() ? 1 : 0);
PerfectSlayer marked this conversation as resolved.
Show resolved Hide resolved
if (isAppSecStandaloneEnabled()) {
result.put(APM_ENABLED, 0);
}
Expand Down
Loading