-
Notifications
You must be signed in to change notification settings - Fork 49
Provide Dynatrace Exporter #170
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
5 commits
Select commit
Hold shift + click to select a range
a7513dd
Provide Dynatrace Exporter
KarstenSchnitter dac9215
Add Documentation for Dynatrace Exporter
KarstenSchnitter 970c1cc
Use HTTP for Dynatrace Export
KarstenSchnitter 8c1e834
Update cf-java-logging-support-opentelemetry-agent-extension/README.md
KarstenSchnitter 4abcc9d
Remove unused imports
KarstenSchnitter 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
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
39 changes: 39 additions & 0 deletions
39
...a/com/sap/hcf/cf/logging/opentelemetry/agent/ext/binding/CloudFoundryServicesAdapter.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,39 @@ | ||
package com.sap.hcf.cf.logging.opentelemetry.agent.ext.binding; | ||
|
||
import io.pivotal.cfenv.core.CfEnv; | ||
import io.pivotal.cfenv.core.CfService; | ||
|
||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
class CloudFoundryServicesAdapter { | ||
|
||
private final CfEnv cfEnv; | ||
|
||
CloudFoundryServicesAdapter(CfEnv cfEnv) { | ||
this.cfEnv = cfEnv; | ||
} | ||
|
||
/** | ||
* Stream CfServices, that match the provided properties. Empty or null values are interpreted as not applicable. No | ||
* check will be performed during search. User-provided service instances will be preferred unless the | ||
* {@code userProvidedLabel is null or empty. Provided only null values will return all service instances. | ||
* | ||
* @param serviceLabels the labels of services | ||
* @param serviceTags the tags of services | ||
* @return a stream of service instances present in the CloudFoundry environment variable VCAP_SERVICES | ||
*/ | ||
Stream<CfService> stream(List<String> serviceLabels, List<String> serviceTags) { | ||
Stream<CfService> services; | ||
if (serviceLabels == null || serviceLabels.isEmpty()) | ||
services = cfEnv.findAllServices().stream(); | ||
else { | ||
services = serviceLabels.stream().flatMap(l -> cfEnv.findServicesByLabel(l).stream()); | ||
} | ||
if (serviceTags == null || serviceTags.isEmpty()) { | ||
return services; | ||
} | ||
return services.filter(svc -> svc.existsByTagIgnoreCase(serviceTags.toArray(new String[0]))); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,12 @@ | |
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.singletonList; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
public class CloudLoggingServicesProvider implements Supplier<Stream<CfService>> { | ||
|
||
private static final String DEFAULT_USER_PROVIDED_LABEL = "user-provided"; | ||
|
@@ -17,15 +20,14 @@ public class CloudLoggingServicesProvider implements Supplier<Stream<CfService>> | |
|
||
private final List<CfService> services; | ||
|
||
public CloudLoggingServicesProvider(ConfigProperties config, CfEnv cfEnv) { | ||
String userProvidedLabel = getUserProvidedLabel(config); | ||
String cloudLoggingLabel = getCloudLoggingLabel(config); | ||
String cloudLoggingTag = getCloudLoggingTag(config); | ||
List<CfService> userProvided = cfEnv.findServicesByLabel(userProvidedLabel); | ||
List<CfService> managed = cfEnv.findServicesByLabel(cloudLoggingLabel); | ||
this.services = Stream.concat(userProvided.stream(), managed.stream()) | ||
.filter(svc -> svc.existsByTagIgnoreCase(cloudLoggingTag)) | ||
.collect(Collectors.toList()); | ||
public CloudLoggingServicesProvider(ConfigProperties config) { | ||
this(config, new CloudFoundryServicesAdapter(new CfEnv())); | ||
} | ||
Comment on lines
+23
to
+25
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. Like the simplification that comes from the refactoring |
||
|
||
CloudLoggingServicesProvider(ConfigProperties config, CloudFoundryServicesAdapter adapter) { | ||
List<String> serviceLabels = asList(getUserProvidedLabel(config), getCloudLoggingLabel(config)); | ||
List<String> serviceTags = singletonList(getCloudLoggingTag(config)); | ||
this.services = adapter.stream(serviceLabels, serviceTags).collect(toList()); | ||
} | ||
|
||
private String getUserProvidedLabel(ConfigProperties config) { | ||
|
47 changes: 47 additions & 0 deletions
47
...java/com/sap/hcf/cf/logging/opentelemetry/agent/ext/binding/DynatraceServiceProvider.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,47 @@ | ||
package com.sap.hcf.cf.logging.opentelemetry.agent.ext.binding; | ||
|
||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.pivotal.cfenv.core.CfEnv; | ||
import io.pivotal.cfenv.core.CfService; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.singletonList; | ||
|
||
public class DynatraceServiceProvider implements Supplier<CfService> { | ||
|
||
private static final String DEFAULT_USER_PROVIDED_LABEL = "user-provided"; | ||
private static final String DEFAULT_DYNATRACE_LABEL = "dynatrace"; | ||
private static final String DEFAULT_DYNATRACE_TAG = "dynatrace"; | ||
|
||
private final CfService service; | ||
|
||
public DynatraceServiceProvider(ConfigProperties config) { | ||
this(config, new CloudFoundryServicesAdapter(new CfEnv())); | ||
} | ||
|
||
DynatraceServiceProvider(ConfigProperties config, CloudFoundryServicesAdapter adapter) { | ||
List<String> serviceLabels = asList(getUserProvidedLabel(config), getDynatraceLabel(config)); | ||
List<String> serviceTags = singletonList(getDynatraceTag(config)); | ||
this.service = adapter.stream(serviceLabels, serviceTags).findFirst().orElse(null); | ||
} | ||
|
||
private String getUserProvidedLabel(ConfigProperties config) { | ||
return config.getString("otel.javaagent.extension.sap.cf.binding.user-provided.label", DEFAULT_USER_PROVIDED_LABEL); | ||
} | ||
|
||
private String getDynatraceLabel(ConfigProperties config) { | ||
return config.getString("otel.javaagent.extension.sap.cf.binding.dynatrace.label", DEFAULT_DYNATRACE_LABEL); | ||
} | ||
|
||
private String getDynatraceTag(ConfigProperties config) { | ||
return config.getString("otel.javaagent.extension.sap.cf.binding.dynatrace.tag", DEFAULT_DYNATRACE_TAG); | ||
} | ||
|
||
@Override | ||
public CfService get() { | ||
return service; | ||
} | ||
} |
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.
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.
I would assume this also applies for Dynatrace, right?
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.
No, there is no default configuration for the
otlp
exporter and Dynatrace. You need to use thedynatrace
exporter explicitly. Note, thatotlp
is considered to be a legacy/fallback approach. Since Cloud Logging is always available, it is used as the default.