-
Notifications
You must be signed in to change notification settings - Fork 325
Adding Destination fields #976
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
56d3d2e
Add destination to HTTP spans context
eyalkoren 32f0f7e
Fix IPv6 handling for OkHttp clients
eyalkoren d161c46
Add file headers
eyalkoren a997b1c
Implement for DBs, Elasticsearch and JMS
eyalkoren 2acd203
Add destination.address and destination.port to HTTP client spans
eyalkoren 51b924a
Separate Destination serialization test from HTTP serialization test
eyalkoren e163e85
Implement destination address for JDBC and Elasticsearch
eyalkoren a1240fd
Disable the Oracle test
eyalkoren ffe50aa
Implement for MongoDB client
eyalkoren 75a1e5a
Implement for Redis Jedis
eyalkoren 3bee6b8
Applying review comments
eyalkoren e5fa66d
Merge remote-tracking branch 'upstream/master' into destination-fields
eyalkoren 8c6821b
Add missing file header
eyalkoren 338a358
Adding to changelog
eyalkoren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
apm-agent-core/src/main/java/co/elastic/apm/agent/impl/context/Destination.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /*- | ||
| * #%L | ||
| * Elastic APM Java agent | ||
| * %% | ||
| * Copyright (C) 2018 - 2019 Elastic and contributors | ||
| * %% | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| * #L% | ||
| */ | ||
| package co.elastic.apm.agent.impl.context; | ||
|
|
||
| import co.elastic.apm.agent.objectpool.Recyclable; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Context information about a destination of outgoing calls. | ||
| */ | ||
| public class Destination implements Recyclable { | ||
|
|
||
| /** | ||
| * An IP (v4 or v6) or a host/domain name. | ||
| */ | ||
| private final StringBuilder address = new StringBuilder(); | ||
|
|
||
| /** | ||
| * The destination's port used within this context. | ||
| */ | ||
| private int port; | ||
|
|
||
| public Destination withAddress(@Nullable CharSequence address) { | ||
| if (address != null && address.length() > 0) { | ||
| // remove square brackets for IPv6 addresses | ||
| int startIndex = 0; | ||
| if (address.charAt(0) == '[') { | ||
| startIndex = 1; | ||
| } | ||
| int endIndex = address.length(); | ||
| if (address.charAt(endIndex - 1) == ']') { | ||
| endIndex--; | ||
| } | ||
| this.address.append(address, startIndex, endIndex); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public StringBuilder getAddress() { | ||
| return address; | ||
| } | ||
|
|
||
| public Destination withPort(int port) { | ||
| this.port = port; | ||
| return this; | ||
| } | ||
|
|
||
| public int getPort() { | ||
| return port; | ||
| } | ||
|
|
||
| /** | ||
| * 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(); | ||
| } | ||
|
|
||
| @Override | ||
| public void resetState() { | ||
| address.setLength(0); | ||
| port = -1; | ||
| service.resetState(); | ||
| } | ||
|
|
||
| /** | ||
| * 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(); | ||
|
|
||
| /** | ||
| * 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). | ||
| */ | ||
| private final StringBuilder name = new StringBuilder(); | ||
|
|
||
| /** | ||
| * For displaying icons or similar. Currently, this should be equal to the {@code span.type}. | ||
| */ | ||
| @Nullable | ||
| private String type; | ||
|
|
||
| public Service withResource(String resource) { | ||
| this.resource.append(resource); | ||
| return this; | ||
| } | ||
|
|
||
| public StringBuilder getResource() { | ||
| return resource; | ||
| } | ||
|
|
||
| public Service withName(String name) { | ||
| this.name.append(name); | ||
| return this; | ||
| } | ||
|
|
||
| public StringBuilder getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public Service withType(String type) { | ||
| this.type = type; | ||
| return this; | ||
| } | ||
|
|
||
| @Nullable | ||
| public String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public boolean hasContent() { | ||
| return resource.length() > 0 || name.length() > 0 || type != null; | ||
| } | ||
|
|
||
| @Override | ||
| public void resetState() { | ||
| resource.setLength(0); | ||
| name.setLength(0); | ||
| type = null; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.