Skip to content

Replace/extend resource dest. with service target.{name.type} #2578

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

Merged
merged 51 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ba7ea3f
add Service context
SylvainJuge Apr 6, 2022
4ab9461
simpler and less generic design
SylvainJuge Apr 6, 2022
3dec136
fix resource dest tests
SylvainJuge Apr 6, 2022
9c83b8d
use new API in jdbc plugin
SylvainJuge Apr 6, 2022
810f9ee
add custom assertions for service target
SylvainJuge Apr 7, 2022
d7d89d5
add service target+tests
SylvainJuge Apr 7, 2022
4b3cbd4
migrate to new API + tests with new API/assert
SylvainJuge Apr 7, 2022
bd1e343
simplify & cleanup WIP
SylvainJuge Apr 7, 2022
4acf9a0
fix small json serialization
SylvainJuge Apr 7, 2022
5deb571
migrate compressed spans
SylvainJuge Apr 7, 2022
90b76c3
migrate dropped spans stats
SylvainJuge Apr 11, 2022
329e486
remove Destination.Service
SylvainJuge Apr 11, 2022
26b088b
add assert for http exit spans
SylvainJuge Apr 11, 2022
c408a8a
Merge branch 'main' of github.com:elastic/apm-agent-java into add-ser…
SylvainJuge Apr 11, 2022
50f6093
update json test
SylvainJuge Apr 11, 2022
fd9b9c9
add assertions on destination + update API tests
SylvainJuge Apr 12, 2022
3c3ab1b
add few tests+only use resource as fallback
SylvainJuge Apr 12, 2022
0c34e50
fix service name json serialization
SylvainJuge Apr 13, 2022
88a11b3
fix http host for OTel bridge
SylvainJuge Apr 13, 2022
842be57
align otel gherkin spec
SylvainJuge Apr 13, 2022
b455962
simplify otel mapping for service target
SylvainJuge Apr 13, 2022
4e6b650
slightly enhance ServiceTarget API + grpc
SylvainJuge May 4, 2022
ad5599d
small javadoc update
SylvainJuge May 4, 2022
9c5ed3c
add entry point to API + user override
SylvainJuge May 11, 2022
5d9b813
fix javadoc
SylvainJuge May 11, 2022
3f648ab
Merge branch 'main' of github.com:elastic/apm-agent-java into add-ser…
SylvainJuge May 11, 2022
6b9e469
fix merge issues + cleanup
SylvainJuge May 11, 2022
31b6f8b
simplify OTel spec mapping for corner case
SylvainJuge May 12, 2022
1727b1d
document new API
SylvainJuge May 12, 2022
9fae279
fix mongo db name
SylvainJuge May 16, 2022
619822b
fix json serialization
SylvainJuge May 16, 2022
cd84271
fix few other corner cases
SylvainJuge May 16, 2022
b94aeef
slightly better deprecated API compat.
SylvainJuge May 17, 2022
ce43e78
post-review changes
SylvainJuge May 18, 2022
756bd73
use stringbuilder copy in dropped stats
SylvainJuge May 18, 2022
5ca78c6
fix missing copyright notice
SylvainJuge May 18, 2022
eb66ff3
fix NPE in tests
SylvainJuge May 18, 2022
cba3dd5
deprecate old API + remove it from docs
SylvainJuge May 18, 2022
354aa55
fix doc links
SylvainJuge May 18, 2022
a03f23d
keep check on legacy resource for consistency
SylvainJuge May 18, 2022
3485a24
improve test assertions
SylvainJuge May 18, 2022
af2566e
test expected resource
SylvainJuge May 19, 2022
7f618f6
Merge branch 'main' of github.com:elastic/apm-agent-java into add-ser…
SylvainJuge May 19, 2022
83725fe
fix typo
SylvainJuge May 20, 2022
32bbc4b
Merge branch 'main' of github.com:elastic/apm-agent-java into add-ser…
SylvainJuge May 31, 2022
ddb905b
update changelog
SylvainJuge May 31, 2022
9a77e39
post-review perf improvement
SylvainJuge Jun 1, 2022
3673446
fix minor post-review
SylvainJuge Jun 1, 2022
8416d34
enhance and split test for clarity
SylvainJuge Jun 1, 2022
8f91b09
improve dropped spans tests
SylvainJuge Jun 1, 2022
0faf80c
remove todo
SylvainJuge Jun 1, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ endif::[]
* Struts action invocations via an action chain result start a new span - {pull}2513[#2513]
* Added official support for Elasticsearch Java API client - {pull}2211[#2211]
* Added the ability to make spans non-discardable through the public API and the OpenTelemetry bridge - {pull}2632[#2632]
* Added support for the new service target fields - {pull}2578[#2578]

[float]
===== Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ protected void doSetDestinationService(@Nullable String resource) {
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.SetDestinationServiceInstrumentation
}

protected void doSetServiceTarget(@Nullable String type, @Nullable String name) {
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.SetServiceTargetInstrumentation
}

protected void doSetNonDiscardable() {
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.SetNonDiscardableInstrumentation
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ public Span setDestinationService(@Nullable String resource) {
return this;
}

@Nonnull
@Override
public Span setServiceTarget(@Nullable String type, @Nullable String name) {
return this;
}

@Override
@Nonnull
public Span setNonDiscardable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public Span setDestinationService(@Nullable String resource) {

@Nonnull
@Override
public Span setServiceTarget(@Nullable String type, @Nullable String name) {
return this;
}

@Nonnull
public Span setNonDiscardable() {
return this;
}
Expand Down
15 changes: 15 additions & 0 deletions apm-agent-api/src/main/java/co/elastic/apm/api/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,24 @@ public interface Span {
* @param resource the string representation of the downstream service. Will be used to override automatically
* inferred value, even if {@code null}.
* @return this span
*
* @deprecated use {@link #setServiceTarget(String, String)} instead
*/
@Deprecated
@Nonnull
Span setDestinationService(@Nullable String resource);

/**
* Provides a way to manually set the {@code service.target.type} and {@code service.target.name} fields that are used
* for service maps and the identification of downstream services. Those fields are ignored for apm-server before 8.3.
*
* @param type service target type, usually same value as {@code span.subtype}
* @param name service target name: value depends on backend type, for databases it's usually the database name
* @return this span
*/
@Nonnull
Span setServiceTarget(@Nullable String type, @Nullable String name);

/**
* Makes this span non-discardable.
* In some cases, spans may be discarded, for example if {@code span_min_duration} config option is set and the span does not exceed
Expand All @@ -479,4 +493,5 @@ public interface Span {
*/
@Nonnull
Span setNonDiscardable();

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ public Span setDestinationService(@Nullable String resource) {
return this;
}

@Nonnull
@Override
public Span setServiceTarget(@Nullable String type, @Nullable String name) {
doSetServiceTarget(type, name);
return this;
}

@Nonnull
@Override
public Span setNonDiscardable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ public Transaction setDestinationService(@Nullable String resource) {
throw new UnsupportedOperationException();
}


/**
* @deprecated - used only for {@link co.elastic.apm.api.Span}
*/
@Nonnull
@Override
public Span setServiceTarget(@Nullable String type, @Nullable String name) {
throw new UnsupportedOperationException();
}

@Nonnull
@Override
public Span setNonDiscardable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,8 @@ private void withAddress(CharSequence address, int start, int end) {
}
}

/**
* Information about the service related to this destination.
*/
private final Service service = new Service();

public Service getService() {
return service;
}

public boolean hasContent() {
return address.length() > 0 || port > 0 || service.hasContent();
return address.length() > 0 || port > 0;
}

@Override
Expand All @@ -160,7 +151,6 @@ public void resetState() {
addressSetByUser = false;
port = 0;
portSetByUser = false;
service.resetState();
}

public Destination withSocketAddress(SocketAddress socketAddress) {
Expand All @@ -186,101 +176,4 @@ public Destination withInetAddress(InetAddress inetAddress) {
return this;
}

/**
* Context information required for service maps.
*/
public static class Service implements Recyclable {
/**
* Used for detecting unique destinations from each service.
* For HTTP, this is the address, with the port (even when it's the default port), without any scheme.
* For other types of connections, it's just the {@code span.subtype} (kafka, elasticsearch etc.).
* For messaging, we additionally add the queue name (eg jms/myQueue).
*/
private final StringBuilder resource = new StringBuilder();

private boolean resourceSetByUser;

/**
* Used for detecting “sameness” of services and then the display name of a service in the Service Map.
* In other words, the {@link Service#resource} is used to query data for ALL destinations. However,
* some `resources` may be nodes of the same cluster, in which case we also want to be aware.
* Eventually, we may decide to actively fetch a cluster name or similar and we could use that to detect "sameness".
* For now, for HTTP we use scheme, host, and non-default port. For anything else, we use {@code span.subtype}
* (for example- postgresql, elasticsearch).
*
* @deprecated will be removed
*/
private final StringBuilder name = new StringBuilder();

/**
* For displaying icons or similar. Currently, this should be equal to the {@code span.type}.
*
* @deprecated will be removed
*/
@Nullable
private String type;

public Service withUserResource(@Nullable String resource) {
if (resource == null || resource.isEmpty()) {
this.resource.setLength(0);
} else {
setResourceValue(resource);
}
resourceSetByUser = true;
return this;
}

public Service withResource(String resource) {
if (!resourceSetByUser) {
setResourceValue(resource);
}
return this;
}

private void setResourceValue(String newValue) {
resource.setLength(0);
resource.append(newValue);
}

public boolean isResourceSetByUser() {
return resourceSetByUser;
}

public StringBuilder getResource() {
return resource;
}

@Deprecated
public Service withName(String name) {
return this;
}

@Deprecated
public StringBuilder getName() {
return name;
}

@Deprecated
public Service withType(@Nullable String type) {
return this;
}

@Nullable
@Deprecated
public String getType() {
return type;
}

public boolean hasContent() {
return resource.length() > 0;
}

@Override
public void resetState() {
resource.setLength(0);
resourceSetByUser = false;
name.setLength(0);
type = null;
}
}
}
Loading