Skip to content

Commit 562f72c

Browse files
authored
Merge branch 'main' into log-correlation-remake
2 parents 6e2ae2b + 84e8f8b commit 562f72c

File tree

53 files changed

+804
-123
lines changed

Some content is hidden

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

53 files changed

+804
-123
lines changed

CHANGELOG.asciidoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ endif::[]
3232
* When the `MANIFEST.MF` of the main jar contains the `Implementation-Title` attribute, it is used as the default service name - {pull}1921[#1921]
3333
Note: this may change your service names if you relied on the auto-discovery that uses the name of the jar file. If that jar file also contains an `Implementation-Title` attribute in the `MANIFEST.MF` file, the latter will take precedence.
3434
* When the `MANIFEST.MF` of the main jar contains the `Implementation-Version` attribute, it is used as the default service version (except for application servers) - {pull}1922[#1922]
35+
* Added support for overwritting the service version per classloader - {pull}1726[#1726]
36+
* Support for the Java LDAP client - {pull}2355[#2355]
3537
3638
[float]
3739
===== Bug fixes
@@ -44,6 +46,7 @@ paths. The BCI warmup is on by default and may be disabled through the internal
4446
** Dubbo transaction will should be created at the provider side
4547
** APM headers conversion issue within dubbo transaction
4648
* Fix External plugins automatic setting of span outcome - {pull}2376[#2376]
49+
* Avoid early initialization of JMX on Weblogic - {pull}2420[#2420]
4750
4851
[[release-notes-1.x]]
4952
=== Java Agent version 1.x

Jenkinsfile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ pipeline {
177177
expression { return env.GITHUB_COMMENT?.contains('integration tests') }
178178
expression { matchesPrLabel(label: 'ci:agent-integration') }
179179
expression { return env.CHANGE_ID != null && !pullRequest.draft }
180+
not { changeRequest() }
180181
}
181182
}
182183
steps {
@@ -206,6 +207,7 @@ pipeline {
206207
expression { return env.GITHUB_COMMENT?.contains('integration tests') }
207208
expression { matchesPrLabel(label: 'ci:agent-integration') }
208209
expression { return env.CHANGE_ID != null && !pullRequest.draft }
210+
not { changeRequest() }
209211
}
210212
}
211213
steps {
@@ -237,11 +239,9 @@ pipeline {
237239
}
238240
when {
239241
beforeAgent true
240-
allOf {
241-
anyOf {
242-
branch 'main'
243-
expression { return env.GITHUB_COMMENT?.contains('benchmark tests') }
244-
}
242+
anyOf {
243+
branch 'main'
244+
expression { return env.GITHUB_COMMENT?.contains('benchmark tests') }
245245
expression { return params.bench_ci }
246246
}
247247
}
@@ -271,10 +271,6 @@ pipeline {
271271
stage('Javadoc') {
272272
agent { label 'linux && immutable' }
273273
options { skipDefaultCheckout() }
274-
when {
275-
beforeAgent true
276-
expression { return env.ONLY_DOCS == "false" }
277-
}
278274
steps {
279275
withGithubNotify(context: 'Javadoc') {
280276
deleteDir()
@@ -302,6 +298,7 @@ pipeline {
302298
expression { return env.GITHUB_COMMENT?.contains('end-to-end tests') }
303299
expression { matchesPrLabel(label: 'ci:end-to-end') }
304300
expression { return env.CHANGE_ID != null && !pullRequest.draft }
301+
not { changeRequest() }
305302
}
306303
}
307304
}

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/ElasticApmTracer.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
public class ElasticApmTracer implements Tracer {
7373
private static final Logger logger = LoggerFactory.getLogger(ElasticApmTracer.class);
7474

75-
private static final WeakMap<ClassLoader, String> serviceNameByClassLoader = WeakConcurrent.buildMap();
75+
private static final WeakMap<ClassLoader, ServiceInfo> serviceInfoByClassLoader = WeakConcurrent.buildMap();
7676

7777
private final ConfigurationRegistry configurationRegistry;
7878
private final StacktraceConfiguration stacktraceConfiguration;
@@ -230,9 +230,10 @@ private void afterTransactionStart(@Nullable ClassLoader initiatingClassLoader,
230230
new RuntimeException("this exception is just used to record where the transaction has been started from"));
231231
}
232232
}
233-
final String serviceName = getServiceName(initiatingClassLoader);
234-
if (serviceName != null) {
235-
transaction.getTraceContext().setServiceName(serviceName);
233+
final ServiceInfo serviceInfo = getServiceInfo(initiatingClassLoader);
234+
if (serviceInfo != null) {
235+
transaction.getTraceContext().setServiceName(serviceInfo.getServiceName());
236+
transaction.getTraceContext().setServiceVersion(serviceInfo.getServiceVersion());
236237
}
237238
}
238239

@@ -342,7 +343,11 @@ private ErrorCapture captureException(long epochMicros, @Nullable Throwable e, @
342343
parent.setNonDiscardable();
343344
} else {
344345
error.getTraceContext().getId().setToRandomValue();
345-
error.getTraceContext().setServiceName(getServiceName(initiatingClassLoader));
346+
ServiceInfo serviceInfo = getServiceInfo(initiatingClassLoader);
347+
if (serviceInfo != null) {
348+
error.getTraceContext().setServiceName(serviceInfo.getServiceName());
349+
error.getTraceContext().setServiceVersion(serviceInfo.getServiceVersion());
350+
}
346351
}
347352
return error;
348353
}
@@ -734,17 +739,22 @@ public MetricRegistry getMetricRegistry() {
734739
return metricRegistry;
735740
}
736741

737-
public List<String> getServiceNameOverrides() {
738-
List<String> serviceNames = new ArrayList<>(serviceNameByClassLoader.approximateSize());
739-
for (Map.Entry<ClassLoader, String> entry : serviceNameByClassLoader) {
740-
serviceNames.add(entry.getValue());
742+
public List<ServiceInfo> getServiceInfoOverrides() {
743+
List<ServiceInfo> serviceInfos = new ArrayList<>(serviceInfoByClassLoader.approximateSize());
744+
for (Map.Entry<ClassLoader, ServiceInfo> entry : serviceInfoByClassLoader) {
745+
serviceInfos.add(entry.getValue());
741746
}
742-
return serviceNames;
747+
return serviceInfos;
748+
}
749+
750+
@Override
751+
public void overrideServiceInfoForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName) {
752+
overrideServiceInfoForClassLoader(classLoader, serviceName, null);
743753
}
744754

745755
@Override
746-
public void overrideServiceNameForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName) {
747-
// overriding the service name for the bootstrap class loader is not an actual use-case
756+
public void overrideServiceInfoForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName, @Nullable String serviceVersion) {
757+
// overriding the service name/version for the bootstrap class loader is not an actual use-case
748758
// null may also mean we don't know about the initiating class loader
749759
if (classLoader == null
750760
|| serviceName == null || serviceName.isEmpty()
@@ -753,23 +763,23 @@ public void overrideServiceNameForClassLoader(@Nullable ClassLoader classLoader,
753763
return;
754764
}
755765

756-
String sanitizedServiceName = ServiceInfo.replaceDisallowedServiceNameChars(serviceName);
757-
logger.debug("Using `{}` as the service name for class loader [{}]", sanitizedServiceName, classLoader);
758-
if (!serviceNameByClassLoader.containsKey(classLoader)) {
759-
serviceNameByClassLoader.putIfAbsent(classLoader, sanitizedServiceName);
766+
ServiceInfo serviceInfo = new ServiceInfo(serviceName, serviceVersion);
767+
logger.debug("Using `{}` as the service name and `{}` as the service version for class loader [{}]", serviceInfo.getServiceName(), serviceInfo.getServiceVersion(), classLoader);
768+
if (!serviceInfoByClassLoader.containsKey(classLoader)) {
769+
serviceInfoByClassLoader.putIfAbsent(classLoader, new ServiceInfo(serviceName, serviceVersion));
760770
}
761771
}
762772

763773
@Nullable
764-
private String getServiceName(@Nullable ClassLoader initiatingClassLoader) {
774+
private ServiceInfo getServiceInfo(@Nullable ClassLoader initiatingClassLoader) {
765775
if (initiatingClassLoader == null) {
766776
return null;
767777
}
768-
return serviceNameByClassLoader.get(initiatingClassLoader);
778+
return serviceInfoByClassLoader.get(initiatingClassLoader);
769779
}
770780

771-
public void resetServiceNameOverrides() {
772-
serviceNameByClassLoader.clear();
781+
public void resetServiceInfoOverrides() {
782+
serviceInfoByClassLoader.clear();
773783
}
774784

775785
public ApmServerClient getApmServerClient() {

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/GlobalTracer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,13 @@ public TracerState getState() {
204204
}
205205

206206
@Override
207-
public void overrideServiceNameForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName) {
208-
tracer.overrideServiceNameForClassLoader(classLoader, serviceName);
207+
public void overrideServiceInfoForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName) {
208+
tracer.overrideServiceInfoForClassLoader(classLoader, serviceName);
209+
}
210+
211+
@Override
212+
public void overrideServiceInfoForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName, @Nullable String serviceVersion) {
213+
tracer.overrideServiceInfoForClassLoader(classLoader, serviceName, serviceVersion);
209214
}
210215

211216
@Override

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/NoopTracer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ public TracerState getState() {
130130
}
131131

132132
@Override
133-
public void overrideServiceNameForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName) {
133+
public void overrideServiceInfoForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName) {
134+
}
135+
136+
@Override
137+
public void overrideServiceInfoForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName, @Nullable String serviceVersion) {
134138
}
135139

136140
@Override

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/Tracer.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,20 @@ <C> Transaction startChildTransaction(@Nullable C headerCarrier, BinaryHeaderGet
162162
* @param classLoader the class loader which corresponds to a particular service
163163
* @param serviceName the service name for this class loader
164164
*/
165-
void overrideServiceNameForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName);
165+
void overrideServiceInfoForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName);
166+
167+
/**
168+
* Overrides the service name and version for all {@link Transaction}s,
169+
* {@link Span}s and {@link ErrorCapture}s which are created by the service which corresponds to the provided {@link ClassLoader}.
170+
* <p>
171+
* The main use case is being able to differentiate between multiple services deployed to the same application server.
172+
* </p>
173+
*
174+
* @param classLoader the class loader which corresponds to a particular service
175+
* @param serviceName the service name for this class loader
176+
* @param serviceVersion the service version for this class loader
177+
*/
178+
void overrideServiceInfoForClassLoader(@Nullable ClassLoader classLoader, @Nullable String serviceName, @Nullable String serviceVersion);
166179

167180
/**
168181
* Called when the container shuts down.

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/TraceContext.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ public static <S, D> void copyTraceContextTextHeaders(S source, TextHeaderGetter
241241
@Nullable
242242
private String serviceName;
243243

244+
@Nullable
245+
private String serviceVersion;
246+
244247
private TraceContext(ElasticApmTracer tracer, Id id) {
245248
coreConfiguration = tracer.getConfig(CoreConfiguration.class);
246249
traceState = new TraceState();
@@ -436,6 +439,7 @@ public void asChildOf(TraceContext parent) {
436439
id.setToRandomValue();
437440
clock.init(parent.clock);
438441
serviceName = parent.serviceName;
442+
serviceVersion = parent.serviceVersion;
439443
applicationClassLoader = parent.applicationClassLoader;
440444
traceState.copyFrom(parent.traceState);
441445
onMutation();
@@ -452,6 +456,7 @@ public void resetState() {
452456
discardable = true;
453457
clock.resetState();
454458
serviceName = null;
459+
serviceVersion = null;
455460
applicationClassLoader = null;
456461
traceState.resetState();
457462
traceState.setSizeLimit(coreConfiguration.getTracestateSizeLimit());
@@ -652,6 +657,7 @@ public void copyFrom(TraceContext other) {
652657
discardable = other.discardable;
653658
clock.init(other.clock);
654659
serviceName = other.serviceName;
660+
serviceVersion = other.serviceVersion;
655661
applicationClassLoader = other.applicationClassLoader;
656662
traceState.copyFrom(other.traceState);
657663
onMutation();
@@ -684,6 +690,20 @@ public void setServiceName(@Nullable String serviceName) {
684690
this.serviceName = serviceName;
685691
}
686692

693+
@Nullable
694+
public String getServiceVersion() {
695+
return serviceVersion;
696+
}
697+
698+
/**
699+
* Overrides the {@code co.elastic.apm.agent.impl.payload.Service#version} property sent via the meta data Intake V2 event.
700+
*
701+
* @param serviceVersion the service version for this event
702+
*/
703+
public void setServiceVersion(@Nullable String serviceVersion) {
704+
this.serviceVersion = serviceVersion;
705+
}
706+
687707
public Span createSpan() {
688708
return tracer.startSpan(fromParentContext(), this);
689709
}
@@ -753,7 +773,7 @@ public void serialize(byte[] buffer) {
753773
ByteUtils.putLong(buffer, offset, clock.getOffset());
754774
}
755775

756-
private void asChildOf(byte[] buffer, @Nullable String serviceName) {
776+
private void asChildOf(byte[] buffer, @Nullable String serviceName, @Nullable String serviceVersion) {
757777
int offset = 0;
758778
offset += traceId.fromBytes(buffer, offset);
759779
offset += parentId.fromBytes(buffer, offset);
@@ -763,10 +783,11 @@ private void asChildOf(byte[] buffer, @Nullable String serviceName) {
763783
discardable = buffer[offset++] == (byte) 1;
764784
clock.init(ByteUtils.getLong(buffer, offset));
765785
this.serviceName = serviceName;
786+
this.serviceVersion = serviceVersion;
766787
onMutation();
767788
}
768789

769-
public void deserialize(byte[] buffer, @Nullable String serviceName) {
790+
public void deserialize(byte[] buffer, @Nullable String serviceName, @Nullable String serviceVersion) {
770791
int offset = 0;
771792
offset += traceId.fromBytes(buffer, offset);
772793
offset += id.fromBytes(buffer, offset);
@@ -775,6 +796,7 @@ public void deserialize(byte[] buffer, @Nullable String serviceName) {
775796
discardable = buffer[offset++] == (byte) 1;
776797
clock.init(ByteUtils.getLong(buffer, offset));
777798
this.serviceName = serviceName;
799+
this.serviceVersion = serviceVersion;
778800
onMutation();
779801
}
780802

apm-agent-core/src/main/java/co/elastic/apm/agent/impl/transaction/Transaction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ private void trackMetrics() {
420420
}
421421
final Labels.Mutable labels = labelsThreadLocal.get();
422422
labels.resetState();
423-
labels.serviceName(getTraceContext().getServiceName()).transactionName(name).transactionType(type);
423+
labels.serviceName(getTraceContext().getServiceName())
424+
.serviceVersion(getTraceContext().getServiceVersion())
425+
.transactionName(name)
426+
.transactionType(type);
424427
final MetricRegistry metricRegistry = tracer.getMetricRegistry();
425428
long criticalValueAtEnter = metricRegistry.writerCriticalSectionEnter();
426429
try {

0 commit comments

Comments
 (0)