Skip to content

Commit 8dd3d64

Browse files
authored
Merge branch 'master' into sarahchen6/add-release-system-tests-workflow
2 parents dae2904 + 5d03203 commit 8dd3d64

43 files changed

Lines changed: 937 additions & 234 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitlab-ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,14 @@ default:
167167
before_script:
168168
- source .gitlab/gitlab-utils.sh
169169
# Akka token added to SSM from https://account.akka.io/token
170-
- export AKKA_REPO_TOKEN=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.akka_repo_token --with-decryption --query "Parameter.Value" --out text)
170+
- export ORG_GRADLE_PROJECT_akkaRepositoryToken=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.akka_repo_token --with-decryption --query "Parameter.Value" --out text)
171171
- mkdir -p .gradle
172172
- export GRADLE_USER_HOME=$(pwd)/.gradle
173173
- |
174174
# Don't put jvm args here as it will be picked up by child gradle processes used in tests
175175
cat << EOF > $GRADLE_USER_HOME/gradle.properties
176176
mavenRepositoryProxy=$MAVEN_REPOSITORY_PROXY
177177
gradlePluginProxy=$GRADLE_PLUGIN_PROXY
178-
akkaRepositoryToken=$AKKA_REPO_TOKEN
179178
EOF
180179
- |
181180
# replace maven central part by MAVEN_REPOSITORY_PROXY in .mvn/wrapper/maven-wrapper.properties

BUILDING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This documentation provides information for developers to set up their environme
88
* [Install the required JDKs](#install-the-required-jdks)
99
* [Install git](#install-git)
1010
* [Install Docker Desktop](#install-docker-desktop)
11+
* [Configure Akka Token](#configure-akka-token)
1112
* [Clone the repository and set up git](#clone-the-repository-and-set-up-git)
1213
* [Building the project](#building-the-project)
1314

@@ -248,6 +249,18 @@ winget install --id Docker.DockerDesktop
248249
> [!NOTE]
249250
> Both git configurations (hooks and submodule) will only be applied to this project and won't apply globally in your setup.
250251

252+
### Configure Akka Token
253+
> [!NOTE]
254+
> You can skip this step if you don’t need instrumentation for the **akka-http-10.6** module.
255+
> For background on why Akka now requires authentication, see this [article](https://akka.io/blog/why-we-are-changing-the-license-for-akka).
256+
257+
To enable access to Akka artifacts hosted on Lightbend’s private repository, you’ll need to configure an authentication token.
258+
1. Obtain a repository token. Visit the Akka account [page](https://account.akka.io/token) to generate a secure repository token.
259+
2. Set up the environment variable. Create an environment variable named:
260+
```shell
261+
ORG_GRADLE_PROJECT_akkaRepositoryToken=<your_token>
262+
```
263+
251264
## Building the project
252265

253266
After everything is properly set up, you can move on to the next section to start a build or check [the contribution guidelines](CONTRIBUTING.md).

communication/src/main/java/datadog/communication/monitor/DDAgentStatsDConnection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ private void doConnect() {
162162
log.debug("StatsD connected to {}", statsDAddress());
163163
}
164164
} catch (final Exception e) {
165-
log.error("Unable to create StatsD client - {}", statsDAddress(), e);
166165
if (retries.getAndIncrement() < MAX_RETRIES) {
167166
if (log.isDebugEnabled()) {
168167
log.debug(
@@ -173,6 +172,8 @@ private void doConnect() {
173172
} else {
174173
log.debug("Max retries have been reached. Will not attempt again.");
175174
}
175+
} catch (Throwable t) {
176+
log.error("Unable to create StatsD client - {} - Will not retry", statsDAddress(), t);
176177
}
177178
}
178179
}
@@ -186,7 +187,7 @@ private void discoverConnectionSettings() {
186187

187188
if (null == host) {
188189
if (!OperatingSystem.isWindows() && new File(DEFAULT_DOGSTATSD_SOCKET_PATH).exists()) {
189-
log.info("Detected {}. Using it to send StatsD data.", DEFAULT_DOGSTATSD_SOCKET_PATH);
190+
log.info("Detected {}. Using it to send StatsD data.", DEFAULT_DOGSTATSD_SOCKET_PATH);
190191
host = DEFAULT_DOGSTATSD_SOCKET_PATH;
191192
port = 0; // tells dogstatsd client to treat host as a socket path
192193
} else {

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/HttpClientDecorator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,13 @@ public AgentSpan onRequest(final AgentSpan span, final REQUEST request) {
104104
} else if (shouldSetResourceName()) {
105105
span.setResourceName(DEFAULT_RESOURCE_NAME);
106106
}
107+
} catch (final BlockingException e) {
108+
throw e;
107109
} catch (final Exception e) {
108110
log.debug("Error tagging url", e);
111+
} finally {
112+
ssrfIastCheck(request);
109113
}
110-
ssrfIastCheck(request);
111114
}
112115
return span;
113116
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/jms/MessageConsumerState.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ public final class MessageConsumerState {
99
private final SessionState sessionState;
1010
private final CharSequence brokerResourceName;
1111
private final String brokerServiceName;
12+
private final CharSequence consumerBaseResourceName;
1213
private final CharSequence consumerResourceName;
1314
private final boolean propagationDisabled;
1415

1516
public MessageConsumerState(
1617
SessionState sessionState,
1718
CharSequence brokerResourceName,
19+
CharSequence consumerBaseResourceName,
1820
CharSequence consumerResourceName,
1921
boolean propagationDisabled) {
2022
this.sessionState = sessionState;
2123
this.brokerResourceName = brokerResourceName;
24+
this.consumerBaseResourceName = consumerBaseResourceName;
2225
this.consumerResourceName = consumerResourceName;
2326
this.propagationDisabled = propagationDisabled;
2427

@@ -47,6 +50,10 @@ public String getBrokerServiceName() {
4750
return brokerServiceName;
4851
}
4952

53+
public CharSequence getConsumerBaseResourceName() {
54+
return consumerBaseResourceName;
55+
}
56+
5057
public CharSequence getConsumerResourceName() {
5158
return consumerResourceName;
5259
}

dd-java-agent/agent-bootstrap/src/main/java11/datadog/trace/bootstrap/instrumentation/jfr/exceptions/ExceptionProfiling.java

Lines changed: 73 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,41 @@
22

33
import datadog.trace.api.Config;
44
import datadog.trace.bootstrap.CallDepthThreadLocalMap;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
57

68
/**
79
* JVM-wide singleton exception profiling service. Uses {@linkplain Config} class to configure
810
* itself using either system properties, environment or properties override.
911
*/
10-
public final class ExceptionProfiling {
12+
public interface ExceptionProfiling {
13+
14+
void start();
15+
16+
ExceptionSampleEvent process(final Throwable t);
17+
18+
boolean recordExceptionMessage();
1119

1220
/** Lazy initialization-on-demand. */
13-
private static final class Holder {
14-
static final ExceptionProfiling INSTANCE = new ExceptionProfiling(Config.get());
21+
final class Holder {
22+
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionProfiling.class);
23+
static final ExceptionProfiling INSTANCE = create();
24+
25+
private static ExceptionProfiling create() {
26+
try {
27+
return new ExceptionProfilingImpl(Config.get());
28+
} catch (Throwable t) {
29+
LOGGER.debug("Unable to create ExceptionProfiling", t);
30+
return new NoOpExceptionProfiling();
31+
}
32+
}
1533
}
1634

1735
/**
1836
* Support for excluding certain exception types because they are used for control flow or leak
1937
* detection.
2038
*/
21-
public static final class Exclusion {
39+
final class Exclusion {
2240
public static void enter() {
2341
CallDepthThreadLocalMap.incrementCallDepth(Exclusion.class);
2442
}
@@ -37,46 +55,67 @@ public static boolean isEffective() {
3755
*
3856
* @return the shared instance
3957
*/
40-
public static ExceptionProfiling getInstance() {
58+
static ExceptionProfiling getInstance() {
4159
return Holder.INSTANCE;
4260
}
4361

44-
private final ExceptionHistogram histogram;
45-
private final ExceptionSampler sampler;
46-
private final boolean recordExceptionMessage;
62+
final class NoOpExceptionProfiling implements ExceptionProfiling {
63+
@Override
64+
public void start() {}
4765

48-
private ExceptionProfiling(final Config config) {
49-
this(
50-
new ExceptionSampler(config),
51-
new ExceptionHistogram(config),
52-
config.isProfilingRecordExceptionMessage());
53-
}
66+
@Override
67+
public ExceptionSampleEvent process(Throwable t) {
68+
return null;
69+
}
5470

55-
ExceptionProfiling(
56-
final ExceptionSampler sampler,
57-
final ExceptionHistogram histogram,
58-
boolean recordExceptionMessage) {
59-
this.sampler = sampler;
60-
this.histogram = histogram;
61-
this.recordExceptionMessage = recordExceptionMessage;
71+
@Override
72+
public boolean recordExceptionMessage() {
73+
return false;
74+
}
6275
}
6376

64-
public void start() {
65-
sampler.start();
66-
}
77+
final class ExceptionProfilingImpl implements ExceptionProfiling {
6778

68-
public ExceptionSampleEvent process(final Throwable t) {
69-
// always record the exception in histogram
70-
final boolean firstHit = histogram.record(t);
79+
private final ExceptionHistogram histogram;
80+
private final ExceptionSampler sampler;
81+
private final boolean recordExceptionMessage;
7182

72-
final boolean sampled = sampler.sample();
73-
if (firstHit || sampled) {
74-
return new ExceptionSampleEvent(t, sampled, firstHit);
83+
ExceptionProfilingImpl(final Config config) {
84+
this(
85+
new ExceptionSampler(config),
86+
new ExceptionHistogram(config),
87+
config.isProfilingRecordExceptionMessage());
88+
}
89+
90+
ExceptionProfilingImpl(
91+
final ExceptionSampler sampler,
92+
final ExceptionHistogram histogram,
93+
boolean recordExceptionMessage) {
94+
this.sampler = sampler;
95+
this.histogram = histogram;
96+
this.recordExceptionMessage = recordExceptionMessage;
97+
}
98+
99+
@Override
100+
public void start() {
101+
sampler.start();
75102
}
76-
return null;
77-
}
78103

79-
boolean recordExceptionMessage() {
80-
return recordExceptionMessage;
104+
@Override
105+
public ExceptionSampleEvent process(final Throwable t) {
106+
// always record the exception in histogram
107+
final boolean firstHit = histogram.record(t);
108+
109+
final boolean sampled = sampler.sample();
110+
if (firstHit || sampled) {
111+
return new ExceptionSampleEvent(t, sampled, firstHit);
112+
}
113+
return null;
114+
}
115+
116+
@Override
117+
public boolean recordExceptionMessage() {
118+
return recordExceptionMessage;
119+
}
81120
}
82121
}

dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/CiVisibilityServices.java

Lines changed: 15 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
package datadog.trace.civisibility;
22

3-
import com.squareup.moshi.JsonAdapter;
4-
import com.squareup.moshi.Moshi;
5-
import com.squareup.moshi.Types;
63
import datadog.communication.BackendApi;
74
import datadog.communication.BackendApiFactory;
85
import datadog.communication.ddagent.SharedCommunicationObjects;
9-
import datadog.communication.http.HttpRetryPolicy;
10-
import datadog.communication.http.OkHttpUtils;
116
import datadog.communication.util.IOUtils;
127
import datadog.trace.api.Config;
138
import datadog.trace.api.civisibility.telemetry.CiVisibilityCountMetric;
149
import datadog.trace.api.civisibility.telemetry.CiVisibilityMetricCollector;
1510
import datadog.trace.api.civisibility.telemetry.tag.Command;
1611
import datadog.trace.api.git.GitInfoProvider;
1712
import datadog.trace.api.intake.Intake;
13+
import datadog.trace.bootstrap.config.provider.civisibility.CiEnvironmentVariables;
1814
import datadog.trace.civisibility.ci.CIProviderInfoFactory;
1915
import datadog.trace.civisibility.ci.env.CiEnvironment;
2016
import datadog.trace.civisibility.ci.env.CiEnvironmentImpl;
@@ -33,21 +29,22 @@
3329
import datadog.trace.civisibility.source.ByteCodeLinesResolver;
3430
import datadog.trace.civisibility.source.CompilerAidedLinesResolver;
3531
import datadog.trace.civisibility.source.LinesResolver;
36-
import datadog.trace.civisibility.source.index.*;
32+
import datadog.trace.civisibility.source.index.CachingRepoIndexBuilderFactory;
33+
import datadog.trace.civisibility.source.index.ConventionBasedResourceResolver;
34+
import datadog.trace.civisibility.source.index.PackageResolver;
35+
import datadog.trace.civisibility.source.index.PackageResolverImpl;
36+
import datadog.trace.civisibility.source.index.RepoIndexFetcher;
37+
import datadog.trace.civisibility.source.index.RepoIndexProvider;
38+
import datadog.trace.civisibility.source.index.ResourceResolver;
3739
import datadog.trace.civisibility.utils.ShellCommandExecutor;
3840
import java.io.File;
39-
import java.lang.reflect.Type;
4041
import java.net.InetSocketAddress;
4142
import java.nio.file.FileSystem;
4243
import java.nio.file.FileSystems;
4344
import java.nio.file.Path;
44-
import java.util.Collections;
4545
import java.util.Map;
4646
import javax.annotation.Nonnull;
4747
import javax.annotation.Nullable;
48-
import okhttp3.HttpUrl;
49-
import okhttp3.OkHttpClient;
50-
import okhttp3.Request;
5148
import org.slf4j.Logger;
5249
import org.slf4j.LoggerFactory;
5350

@@ -61,8 +58,6 @@ public class CiVisibilityServices {
6158

6259
private static final String GIT_FOLDER_NAME = ".git";
6360

64-
static final String DD_ENV_VARS_PROVIDER_KEY_HEADER = "DD-Env-Vars-Provider-Key";
65-
6661
final ProcessHierarchy processHierarchy;
6762
final Config config;
6863
final CiVisibilityMetricCollector metricCollector;
@@ -90,7 +85,7 @@ public class CiVisibilityServices {
9085
this.jvmInfoFactory = new CachingJvmInfoFactory(config, new JvmInfoFactoryImpl());
9186
this.gitClientFactory = buildGitClientFactory(config, metricCollector);
9287

93-
this.environment = buildCiEnvironment(config, sco);
88+
this.environment = buildCiEnvironment();
9489
this.ciProviderInfoFactory = new CIProviderInfoFactory(config, environment);
9590
this.linesResolver =
9691
new BestEffortLinesResolver(new CompilerAidedLinesResolver(), new ByteCodeLinesResolver());
@@ -145,50 +140,13 @@ private static GitClient.Factory buildGitClientFactory(
145140
}
146141

147142
@Nonnull
148-
private static CiEnvironment buildCiEnvironment(Config config, SharedCommunicationObjects sco) {
149-
CiEnvironment localEnvironment = CiEnvironmentImpl.local();
150-
String remoteEnvVarsProviderUrl = config.getCiVisibilityRemoteEnvVarsProviderUrl();
151-
if (remoteEnvVarsProviderUrl != null) {
152-
String remoteEnvVarsProviderKey = config.getCiVisibilityRemoteEnvVarsProviderKey();
153-
CiEnvironment remoteEnvironment =
154-
new CiEnvironmentImpl(
155-
getRemoteEnvironment(
156-
remoteEnvVarsProviderUrl, remoteEnvVarsProviderKey, sco.agentHttpClient));
157-
return new CompositeCiEnvironment(remoteEnvironment, localEnvironment);
143+
private static CiEnvironment buildCiEnvironment() {
144+
Map<String, String> remoteEnvironment = CiEnvironmentVariables.getAll();
145+
if (remoteEnvironment != null) {
146+
return new CompositeCiEnvironment(
147+
new CiEnvironmentImpl(remoteEnvironment), CiEnvironmentImpl.local());
158148
} else {
159-
return localEnvironment;
160-
}
161-
}
162-
163-
static Map<String, String> getRemoteEnvironment(String url, String key, OkHttpClient httpClient) {
164-
HttpRetryPolicy.Factory retryPolicyFactory = new HttpRetryPolicy.Factory(5, 100, 2.0, true);
165-
166-
HttpUrl httpUrl = HttpUrl.get(url);
167-
Request request =
168-
new Request.Builder()
169-
.url(httpUrl)
170-
.header(DD_ENV_VARS_PROVIDER_KEY_HEADER, key)
171-
.get()
172-
.build();
173-
try (okhttp3.Response response =
174-
OkHttpUtils.sendWithRetries(httpClient, retryPolicyFactory, request)) {
175-
176-
if (response.isSuccessful()) {
177-
Moshi moshi = new Moshi.Builder().build();
178-
Type type = Types.newParameterizedType(Map.class, String.class, String.class);
179-
JsonAdapter<Map<String, String>> adapter = moshi.adapter(type);
180-
return adapter.fromJson(response.body().source());
181-
} else {
182-
logger.warn(
183-
"Could not get remote CI environment (HTTP code {}) {}",
184-
response.code(),
185-
response.body() != null ? ": " + response.body().string() : "");
186-
return Collections.emptyMap();
187-
}
188-
189-
} catch (Exception e) {
190-
logger.warn("Could not get remote CI environment", e);
191-
return Collections.emptyMap();
149+
return CiEnvironmentImpl.local();
192150
}
193151
}
194152

0 commit comments

Comments
 (0)