-
Notifications
You must be signed in to change notification settings - Fork 299
Add to dd_tags before send traces to agent #8653
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
base: master
Are you sure you want to change the base?
Changes from all commits
dbabe9a
a358fb3
28e0568
4635bef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.Proxy; | ||
import java.net.URL; | ||
import java.nio.ByteBuffer; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
@@ -209,13 +210,92 @@ public static Request.Builder prepareRequest(final HttpUrl url, Map<String, Stri | |
builder.addHeader(DATADOG_ENTITY_ID, entityId); | ||
} | ||
|
||
if (Config.get().isExperimentalProcessTagsEnabled()) { | ||
// custom X-Datadog-Process-Tags | ||
String customTags = getCustomTags(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
String existingProcessTags = headers.getOrDefault("X-Datadog-Process-Tags", ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have chances to already have a value for this? In this case should we just override what we calculated? |
||
if (!existingProcessTags.isEmpty() && !existingProcessTags.endsWith(",")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the second condition |
||
existingProcessTags += ","; | ||
} | ||
if (customTags.length() > 0) { | ||
headers.put("X-Datadog-Process-Tags", existingProcessTags + customTags); | ||
} | ||
} | ||
|
||
for (Map.Entry<String, String> e : headers.entrySet()) { | ||
builder.addHeader(e.getKey(), e.getValue()); | ||
} | ||
|
||
return builder; | ||
} | ||
|
||
private static String getCustomTags() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method heavily uses |
||
String javaCommand = System.getProperty("sun.java.command", "unknown"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need to have a |
||
String[] parts = javaCommand.split(" "); | ||
String mainTarget = parts.length > 0 ? parts[0] : "unknown"; | ||
System.out.println("javacommand is: " + javaCommand); | ||
boolean isJar = mainTarget.endsWith(".jar"); | ||
String javaMainClass = isJar ? "unknown" : mainTarget; | ||
String javaJarFile = "unknown"; | ||
String javaJarPath = "unknown"; | ||
|
||
if (isJar) { | ||
javaJarFile = mainTarget; | ||
try { | ||
// Load it as a resource | ||
URL jarUrl = new File(javaJarFile).toURI().toURL(); // Assumes relative path | ||
File jarFile = new File(jarUrl.toURI()); | ||
|
||
if (jarFile.exists()) { | ||
javaJarPath = jarFile.getAbsolutePath(); | ||
} | ||
} catch (Exception e) { | ||
System.out.println("Unable to get JAR file: " + e.getMessage()); | ||
} | ||
} else { | ||
try { | ||
Class<?> mainClass = Class.forName(javaMainClass); | ||
javaJarPath = | ||
mainClass.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); | ||
} catch (Exception e) { | ||
System.out.println("Unable to load main class or get JAR file: " + e.getMessage()); | ||
} | ||
} | ||
|
||
String jbossHome = System.getProperty("jboss.home.dir", "unknown"); | ||
String jbossMode = System.getProperty("jboss.server.mode", "unknown"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which jboss edition or version is setting this system property? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm testing with this sample app which is running quay.io/wildfly/wildfly:26.1.2.Final-jdk17 Is there a reason you ask this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually it sets |
||
String jbossServerName = System.getProperty("jboss.server.name", "unknown"); | ||
|
||
StringBuilder customTags = new StringBuilder(); | ||
if (!"unknown".equals(javaMainClass)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (customTags.length() > 0) customTags.append(","); | ||
customTags.append("java_main_class:").append(javaMainClass); | ||
} | ||
if (!"unknown".equals(javaJarFile)) { | ||
if (customTags.length() > 0) customTags.append(","); | ||
customTags.append("java_jar_file:").append(javaJarFile); | ||
} | ||
if (!"unknown".equals(javaJarPath)) { | ||
if (customTags.length() > 0) customTags.append(","); | ||
customTags.append("java_jar_path:").append(javaJarPath); | ||
} | ||
if (!"unknown".equals(jbossHome)) { | ||
if (customTags.length() > 0) customTags.append(","); | ||
customTags.append("jboss_home:").append(jbossHome); | ||
} | ||
if (!"unknown".equals(jbossMode)) { | ||
if (customTags.length() > 0) customTags.append(","); | ||
customTags.append("jboss_mode:").append(jbossMode); | ||
} | ||
if (!"unknown".equals(jbossServerName)) { | ||
if (customTags.length() > 0) customTags.append(","); | ||
customTags.append("jboss_server_name:").append(jbossServerName); | ||
} | ||
|
||
System.out.println(customTags); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. those println sounds like leftover debug messages. If there is the need to keep diagnostic, they should be logged as debug otherwise they could be removed |
||
return customTags.toString(); | ||
} | ||
|
||
public static Request.Builder prepareRequest( | ||
final HttpUrl url, | ||
final Map<String, String> headers, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,8 @@ public final class GeneralConfig { | |
public static final String AGENTLESS_LOG_SUBMISSION_URL = "agentless.log.submission.url"; | ||
public static final String APM_TRACING_ENABLED = "apm.tracing.enabled"; | ||
public static final String JDK_SOCKET_ENABLED = "jdk.socket.enabled"; | ||
public static final String EXPERIMENTAL_PROCESS_TAGS_ENABLED = | ||
"experimental.process.tags.enabled"; | ||
Comment on lines
+98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a case where we could take advantage of @amarziali WDYT? We had a conversation of how this might be useful a while back. Wanted to see if you agree in this use case. |
||
|
||
private GeneralConfig() {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a feature flag as requested @raphaelgavache