newrelic / newrelic-telemetry-sdk-java

Java library for sending telemetry data to New Relic
Apache License 2.0
41 stars 37 forks source link

Added EU endpoint support and Unit tests in SenderConfiguration and the BatchSenders for all data types. #276

Closed yamnihcg closed 3 years ago

yamnihcg commented 3 years ago

The following PR adds the .setRegion() method to the SenderConfigurationBuilder API. This method allows you to define a region (US or EU) so that the appropriate production endpoint (corresponding to that region) is used. The default endpoint is the US production endpoint.

If you want to use an endpoint other than the US / EU production endpoints, use the existing .endpoint() method in the SenderConfigurationBuilder API.

Below are some examples on how to use the new API. In these examples, we use the MetricBatchSender / MetricBatchSenderFactory.

US Production


String licenseKey = args[0];
MetricBatchSenderFactory factory = MetricBatchSenderFactory.fromHttpImplementation(OkHttpPoster::new);
MetricBatchSender sender = MetricBatchSender.create(factory.configureWith(licenseKey).useLicenseKey(true).build());

Note: Since the default endpoint is the US production endpoint, we did not use .setRegion() in this example. Also, a US license key is needed to send data to this endpoint.

EU Production


String licenseKey = args[0];
MetricBatchSenderFactory factory = MetricBatchSenderFactory.fromHttpImplementation(OkHttpPoster::new);
MetricBatchSender sender = MetricBatchSender.create(factory.configureWith(licenseKey).useLicenseKey(true).setRegion("EU").build());

Note: An EU license key is needed to send data to this endpoint.

Staging / Setting Your Own URL


URL endpointURL = new URL("http://localhost:1439/v1/accounts/events");
String licenseKey = args[0];
MetricBatchSenderFactory factory = MetricBatchSenderFactory.fromHttpImplementation(OkHttpPoster::new);
MetricBatchSender sender =
    MetricBatchSender.create(factory.configureWith(licenseKey).useLicenseKey(true).endpoint(endpointURL).build());
yamnihcg commented 3 years ago

EventBatchSender:

Default (to US Prod, US License Key): Successful Set Region (to US Prod, US License Key): Successful Set Region (to EU Prod, EU License Key): Successful User Provided Endpoint: Successful

MetricBatchSender:

Default (to US Prod, US License Key): Successful Set Region (to US Prod, US License Key): Successful Set Region (to EU Prod, EU License Key): Successful User Provided Endpoint: Successful

LogBatchSender:

Default (to US Prod, US License Key): Successful Set Region (to US Prod, US License Key): Successful Set Region (to EU Prod, EU License Key): Successful User Provided Endpoint: Successful

SpanBatchSender:

Default (to US Prod, US License Key): Successful Set Region (to US Prod, US License Key): Successful Set Region (to EU Prod, EU License Key): Successful User Provided Endpoint: Successful

XiXiaPdx commented 3 years ago

This looks great @yamnihcg and thank you for persistently chipping away at this! 🚀 🚀