Code Monkey home page Code Monkey logo

newrelic-telemetry-sdk-java's Introduction

New Relic Open Source community project banner.

New Relic Java Telemetry SDK

The New Relic Java Telemetry SDK is an easy way to send data to New Relic. The SDK currently supports sending the MELT telemetry data types (Metrics, Events, Logs, and Traces) via the following APIs:

Why is this cool?

Send data to New Relic! No agent required.

Our Telemetry SDK tries to be helpful, so your job of sending telemetry data to New Relic can be done in the right way, easily. We've covered all of the basics for you so you can focus on writing feature code directly related to your business need or interest.

Why would you want to use the telemetry SDK?

We imagine you (or your customers) are interested in the telemetry data, generated by your tool, framework, or code, in New Relic. You can write an exporter to do so! Check out the telemetry_examples module to get started.

For the most recently published version, see Releases

Installation

In order to send metrics or spans to New Relic, you will need a New Relic license key for the account to which you want to send data.

Maven dependencies:

    <dependency>
      <groupId>com.newrelic.telemetry</groupId>
      <artifactId>telemetry-core</artifactId>
      <version>0.16.0</version>
    </dependency>
    <dependency>
      <groupId>com.newrelic.telemetry</groupId>
      <artifactId>telemetry-http-okhttp</artifactId>
      <version>0.16.0</version>
    </dependency>

Gradle dependencies:

implementation("com.newrelic.telemetry:telemetry-core:0.16.0")
implementation("com.newrelic.telemetry:telemetry-http-okhttp:0.16.0")

Take a look at the example code in the telemetry_examples module. We recommend looking at the TelemetryClientExample first.

Note: If you do not want to include okhttp as a transitive dependency, you will need to provide a custom implementation of the com.newrelic.telemetry.http.HttpPoster interface, rather than using the com.newrelic.telemetry:telemetry-http-okhttp library.

Usage

Logging

The Telemetry SDK uses slf4j for all logging. Having a slf4j implementation in your application is required in order to see log information. See the slf4j documentation for details.

Enabling audit logging

The various builders for the Telemetry SDK components include an option to enableAuditLogging. Enabling this option will cause the SDK to product additional logging at DEBUG level. This logging includes the details of every payload sent to the New Relic APIs, and the responses from those APIs.

WARNING: If you enable audit logging, all the data in your spans and metrics will be sent to your logging system. It is recommended that you only enable audit logging when absolutely necessary.

Use license key

The various builders for the Telemetry SDK components include an option to useLicenseKey. Enabling this option will cause the SDK to inform the API endpoints the key you provided is a New Relic license key.

For developers:

Requirements

  • Java 11 or greater
  • For IDEA:
  • Docker & docker-compose must be installed for integration testing

Find and use your data

Tips on how to find and query your data in New Relic:

For general querying information, see:

Building

CI builds are run on Github Actions: build badge

The project uses Java 11 and gradle 6 for building, and the gradle wrapper is provided.

To compile, run the tests and build the jars:

$ ./gradlew build

Testing

End-to-end integration tests are included. They are implemented with the testcontainers library; mock-server provides the backend.

There are two modes to run the integration tests.

  • Run with gradle: $ ./gradlew integration_test:test
  • Run the integration test classes in IDEA directly. It should "just work".

Code style

This project uses the google-java-format code style, and it is easily applied via an included gradle plugin:

$ ./gradlew googleJavaFormat verifyGoogleJavaFormat

Please be sure to run the formatter before committing any changes. There is a pre-commit-hook.sh which can be applied automatically before commits by moving it into .git/hooks/pre-commit.

Module structure:

telemetry_core

This is the core module for sending dimensional metrics and spans to New Relic. It contains low level APIs as well as higher level "best practice" implementations that compose interactions with the lower level modules. The library is published under maven coordinates:

com.newrelic.telemetry:telemetry-core

In order to send metrics and spans to New Relic, you will also need a New Relic license key for the account to which you want to send data.

telemetry-http-java11

This is an implementation of the required http client interface using Java 11 JDK classes as the underlying library. The telemetry-http-java11 library is published under the maven coordinates:

com.newrelic.telemetry:telemetry-http-java11

telemetry-http-okhttp

This is an implementation of the required http client interface using okhttp as the underlying library. The telemetry-http-okhttp library is published under the maven coordinates:

com.newrelic.telemetry:telemetry-http-okhttp

telemetry_examples

Example code for using the metrics and telemetry APIs.

integration_test

Integration test module. Uses docker-compose based tests to test the SDK end-to-end.

Retries

As described here, the TelemetryClient makes use of a default backoff strategy when it encounters data ingest errors. Specifically, this strategy tries again after 1 second, then doubles the wait after each attempt until a max wait of 15 seconds is reached. After 10 failed attempts, data is dropped and a message is logged.

The backoff strategy is not currently pluggable. Please file an issue or submit a pull request if you need greater control over this behavior.

Support

New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub: Java Agent Forum Topics.

Contribute

We encourage your contributions to improve New Relic Java Telemetry SDK! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.

If you have any questions, or to execute our corporate CLA (which is required if your contribution is on behalf of a company), drop us an email at [email protected].

A note about vulnerabilities

As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.

If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.

If you would like to contribute to this project, review these guidelines.

To all contributors, we thank you! Without your contribution, this project would not be what it is today. We also host a community project page dedicated to New Relic Telemetry SDK (Java).

Limitations

The New Relic Telemetry APIs are rate limited. Please reference the documentation for New Relic Metric API and New Relic Trace API requirements and limits on the specifics of the rate limits.

License

The New Relic Java Telemetry SDK is licensed under the Apache 2.0 License.

The New Relic Java Telemetry SDK also uses source code from third party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the third party notices document.

newrelic-telemetry-sdk-java's People

Contributors

a-feld avatar breedx-nr avatar deleonenriqueta avatar gfuller1 avatar hannes-angst avatar jack-berg avatar jasonjkeller avatar jasonrclark avatar jeemar avatar jeffalder avatar jkwatson avatar juholgado avatar kanderson250 avatar kscaldef avatar meiao avatar mjarvie avatar obenkenobi avatar paperclypse avatar tbradellis avatar tmancill avatar tspring avatar uaihebert avatar wpoch avatar xixiapdx avatar yamnihcg avatar yogendra0sharma avatar ysb33r avatar zuluecho9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

newrelic-telemetry-sdk-java's Issues

Make examples jar runnable with a main method

Some users might expect the examples jar to be runnable (eg. it has a main class defined in the manifest). The use case is that a new user clones the repo, looks at some docs, reads some code, and then wants to try it out. They build the jar with gradle and then try to run it via java -jar <jar> <insights_key>.

Right now this doesn't work. We should make that better, and include docs.

Restructure `metrics` to allow traces

At present, most of the functionality is within a module called metrics. There is non-metric-specific code in this module (HttpPoster and Attributes, for example). So, in order to better accommodate support for Traces, we should do some project restructuring and decide how to proceed (not yet sure which would be best).

Idea 1: Rename metrics to telemetry-core

Pros: Simple change, no code has to move. Traces can sit next to Metrics in the same source module.

Cons: Docs/deps change. Published artifact names change.

Idea 2: Add modules telemetry-core and traces

Common/core code that can be shared between telemetry types would be moved into this new "core" module. Establishes a pattern in which each telemetry type has its own module, and these modules depend on the core,

Pros: Simple. Metrics artifact doesn't need to change.

Cons: Increased number of modules. Increased dependency tree complexity.

Idea 3: Put Traces into the metrics module

Pros: Least amount of work

Cons: Naming will be wrong. Starts a pattern which will be harder to break when other telemetry types come into play.

Flesh out the TelemetryClient

  1. Add method to be able to send data without retry logic, returning the Response object to the user with no validation.
  2. Add a method to be able to send data without retry logic, but throw the appropriate ResponseException.
  3. Consider making the creation of the ResponseException, given a Response, a public API.

Add the ability to copy Attributes

There are a few cases in the sdk (and by the exporter) where having the ability to copy an Attributes instance would be helpful. We should add a method like Attributes.copy() that returns a new instance backed by a new map. Mutations to the resulting copied instance should not mutate the original instance.

Make the version-detection logic more robust

From looking at user-agent metadata, it looks as though the SDK is being pulled into a fat jar, and we're reading the manifest of the fat jar, rather than the original SDK jar.

We're ending up with user-agent strings that look like: "NewRelic-Java-TelemetrySDK/20.6.7029", which is definitely not a version that we've released.

This issue will also apply to all of our java-based exporters that are reading versions from the jar manifest.

Automate release process

Take the manual process and automate it.

The manual process will be documented <Xia has notes, convert to doc. insert link to google doc>

Marshal spans to JSON

We don't yet have the ability to generate a json payload for the traces (spans) ingest API. We should make a data model and appropriate marshalers that can create this JSON.

Add traces example to `telemetry_examples`

Similar to the existing examples, an example that reports traces should be created (perhaps com.newrelic.telemetry.TracesExample.

This should also include a blurb in the README.md for the telemetry_examples and some clear description/instructions/documentation.

@@TRACES: MetricBatchJsonGenerator refactor to loosen Metric coupling

The MetricBatchJsonGenerator should be refactored so that it is less dependent on metrics alone. At the end of this refactoring, we should have a class that can marshal any telemetry type (of which there are just metrics right now) to json.

When marshaling metrics, the resulting json should still confirm to the current format.

Get the poms fully filled out

In order to publish to maven central, we have to make sure the poms contain:

  • project name
  • project description
  • project url
  • license information
  • scm url
  • developer information

This is the message we got when trying to close the sonatype staging thing:

Invalid POM: /com/newrelic/telemetry/telemetry-components/0.2.0/telemetry-components-0.2.0.pom: Project name missing, Project description missing, Project URL missing, License information missing, SCM URL missing, Developer information missing

Information does not appear on API despite using URIoverride and api key.

We have managed to create Opentelemetry Spans without much issue and through debugging, it looks like the spans are using New Relic format.
We have tested the API key and the URI successfully with the curl command: https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/trace-api/report-new-relic-format-traces-trace-api
We are not receiving any errors whether or not we use the URIoverride. We have forced errors by using the wrong keys. Is there a way to troubleshoot this?

Revisit / Remove the Abstract base builder

The AbstractSenderBuilder in com.newrelic.telemetry use a parameterized builder, but due to the way the current code is written, defines build() to return Object.

This should be cleaned up and refactored to fix this ugliness, but without reintroducing a mass of cut-and-paste code.

Add an audit logging option

Audit logging would be a configuration option, off by default, that, when enabled would log json payloads sent to the API endpoints, at DEBUG level.

Include very clear documentation that if the payloads contain sensitive information that that information would be sent to wherever logs are configured to go.

Add service.name as a first class metric attribute

service.name is a very useful, and almost-always-desired attribute for both metrics and spans. We should make it easy for users to set the service.name attribute on metric batches.

This could be a first-class field on the MetricBatchSender, the MetricBatch itself, or somehow on the metrics. A developer-friendly API should be the first consideration on figuring out the right way to implement this.

Verify HTTP connection keep-alive behavior

We need to verify that the default behavior of our TelemetryClient with the OkHttpPoster. Specifically, we should look to confirm that connections are held open (keep alives) to prevent recurring connection setup overhead.

Change license headers

There is an internal doc that suggests we change the license header in all source from:

/*
 * ---------------------------------------------------------------------------------------------
 *  Copyright (c) 2019 New Relic Corporation. All rights reserved.
 *  Licensed under the Apache 2.0 License. See LICENSE in the project root directory for license information.
 * --------------------------------------------------------------------------------------------
 */

to this new format:

/*
 * Copyright 2019 New Relic Corporation. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

We should just do this all in one go.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.