Skip to content

Commit

Permalink
Merge pull request #65 from newrelic/update_telemetry_sdk
Browse files Browse the repository at this point in the history
update to telemetry sdk 0.6.1
  • Loading branch information
breedx-nr authored Jun 30, 2020
2 parents 6351cc5 + 7ab0144 commit 889f34c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.0] - TBD
- Upgrade to Telemetry SDK 0.6.1
- Allow URI override to include or omit the full endpoint path component.

## [0.4.0] - 2020-04-01
- Contributed: `NewRelicReporterFactory` by [Steven Schwell](https://github.com/sschwell)
- Changed: update dropwizard-core version to 4.1.5
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ googleJavaFormat {

dependencies {
api("io.dropwizard.metrics:metrics-core:4.1.5")
api("com.newrelic.telemetry:telemetry:0.4.0")
api("com.newrelic.telemetry:telemetry:0.6.1")
implementation("io.dropwizard:dropwizard-metrics:2.0.5")
implementation("com.newrelic.telemetry:telemetry-http-okhttp:0.4.0")
implementation("com.newrelic.telemetry:telemetry-http-okhttp:0.6.1")

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.4.2")
testRuntimeOnly("org.slf4j:slf4j-simple:1.7.26")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
releaseVersion = 0.4.1-SNAPSHOT
releaseVersion = 0.5.0-SNAPSHOT

# set this to true to enable using a local sonatype (for debugging publishing issues)
# (start a local sonatype in docker with this command: $ docker run -d -p 8081:8081 --name nexus sonatype/nexus3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public NewRelicReporter build() {
filter,
rateUnit,
durationUnit,
new TelemetryClient(metricBatchSender, null),
new TelemetryClient(metricBatchSender, null, null, null),
commonAttributes,
histogramTransformer,
gaugeTransformer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.newrelic.telemetry.Attributes;
import com.newrelic.telemetry.SimpleMetricBatchSender;
import com.newrelic.telemetry.metrics.MetricBatchSenderBuilder;
import com.newrelic.telemetry.MetricBatchSenderFactory;
import com.newrelic.telemetry.OkHttpPoster;
import com.newrelic.telemetry.SenderConfiguration;
import com.newrelic.telemetry.metrics.MetricBatchSender;
import io.dropwizard.metrics.BaseReporterFactory;
import java.net.MalformedURLException;
import java.net.URI;
Expand All @@ -30,15 +32,12 @@ public class NewRelicReporterFactory extends BaseReporterFactory {
@Override
@NotNull
public ScheduledReporter build(final MetricRegistry registry) {
final MetricBatchSenderBuilder metricBatchSender = SimpleMetricBatchSender.builder(apiKey);
if (overrideUri != null) {
final URI uri = URI.create(overrideUri);
try {
metricBatchSender.uriOverride(uri);
} catch (MalformedURLException t) {
throw new IllegalArgumentException(t.getMessage(), t);
}
}
MetricBatchSenderFactory factory =
MetricBatchSenderFactory.fromHttpImplementation(OkHttpPoster::new);

SenderConfiguration.SenderConfigurationBuilder config = factory.configureWith(apiKey);
config = configureEndpoint(config);

final Attributes attributes = new Attributes();
if (commonAttributes != null) {
for (final Map.Entry<String, Object> entry : commonAttributes.entrySet()) {
Expand All @@ -50,12 +49,30 @@ else if (entry.getValue() instanceof Boolean)
attributes.put(entry.getKey(), (Boolean) entry.getValue());
}
}
return NewRelicReporterBuilder.forRegistry(registry, metricBatchSender.build())
MetricBatchSender metricBatchSender = MetricBatchSender.create(config.build());
return NewRelicReporterBuilder.forRegistry(registry, metricBatchSender)
.durationUnit(getDurationUnit())
.rateUnit(getRateUnit())
.filter(getFilter())
.commonAttributes(attributes)
.disabledMetricAttributes(disabledMetricAttributes)
.build();
}

private SenderConfiguration.SenderConfigurationBuilder configureEndpoint(
SenderConfiguration.SenderConfigurationBuilder config) {
if (overrideUri == null) {
return config;
}
final URI uri = URI.create(overrideUri);
try {
String path = uri.getPath();
if (path == null || path.isEmpty()) {
return config.endpoint(uri.getScheme(), uri.getHost(), uri.getPort());
}
return config.endpointWithPath(uri.toURL());
} catch (MalformedURLException t) {
throw new IllegalArgumentException(t.getMessage(), t);
}
}
}

0 comments on commit 889f34c

Please sign in to comment.