Coder Social home page Coder Social logo

dengliming / opentelemetry-exporter-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from newrelic/opentelemetry-exporter-java

0.0 1.0 0.0 355 KB

An OpenTelemetry exporter that sends telemetry to New Relic

License: Apache License 2.0

Kotlin 7.75% Java 91.94% Shell 0.31%

opentelemetry-exporter-java's Introduction

Community Project header

New Relic OpenTelemetry exporter

An OpenTelemetry reporter for sending spans and metrics to New Relic using the New Relic Java Telemetry SDK.

For the details on how OpenTelemetry data is mapped to New Relic data, see documentation in Our exporter specifications documentation

How to use

To send spans or metrics to New Relic, you will need an Insights Insert API Key.

Note: There is an example BasicExample.java
in the test source code hierarchy that matches this example code. It should be considered as the canonical code for this example, since OpenTelemetry internal SDK APIs are still a work in progress.

Installation

If you need more flexibility, you can set up the individual exporters and the SDK by hand:

For spans:

Important: If you are using auto-instrumentation, or you have used the quickstart you should skip the configuration of the SDK, and go right to the next section.

  1. Create a NewRelicSpanExporter
    NewRelicSpanExporter exporter = NewRelicSpanExporter.newBuilder()
        .apiKey(System.getenv("INSIGHTS_INSERT_KEY"))
        .commonAttributes(new Attributes().put(SERVICE_NAME, "best service ever")).build();
  1. Build the OpenTelemetry BatchSpansProcessor with the NewRelicSpanExporter
    BatchSpanProcessor spanProcessor = BatchSpanProcessor.newBuilder(exporter).build();
  1. Add the span processor to the default TracerSdkManagement:
   TracerSdkManagement tracerManagement = OpenTelemetrySdk.getTracerManagement();
   tracerManagement.addSpanProcessor(spanProcessor);

Use the APIs to record some spans

  1. Create the OpenTelemetry Tracer and use it for recording spans.
    Tracer tracer = OpenTelemetry.getTracerProvider().get("sample-app", "1.0");
    
    Span span = tracer.spanBuilder("testSpan").setSpanKind(Kind.INTERNAL).startSpan();
    try (Scope scope = tracer.withSpan(span)) {
      //do some work
      Thread.sleep(1000);
      span.end();
    }
  1. Find your spans in New Relic One: go to https://one.newrelic.com/ and select Distributed Tracing.

For metrics:

Important: If you are using auto-instrumentation, or you have used the quickstart you should skip the configuration of the SDK, and go right to the next section.

  1. Create a NewRelicMetricExporter
    MetricExporter metricExporter =
        NewRelicMetricExporter.newBuilder()
          .apiKey(System.getenv("INSIGHTS_INSERT_KEY"))
          .commonAttributes(new Attributes().put(SERVICE_NAME, "best service ever"))
          .build();
  1. Create an IntervalMetricReader that will batch up metrics every 5 seconds:
    IntervalMetricReader intervalMetricReader =
        IntervalMetricReader.builder()
            .setMetricProducers(
                Collections.singleton(OpenTelemetrySdk.getMeterProvider().getMetricProducer()))
            .setExportIntervalMillis(5000)
            .setMetricExporter(metricExporter)
            .build();

Use the APIs to record some metrics

  1. Create a sample Meter:
    Meter meter = OpenTelemetry.getMeterProvider().get("sample-app", "1.0");
  1. Here is an example of a counter:
    LongCounter spanCounter =
        meter
            .longCounterBuilder("spanCounter")
            .setUnit("one")
            .setDescription("Counting all the spans")
            .setMonotonic(true)
            .build();
  1. Here is an example of a measure:
    LongMeasure spanTimer =
        meter
            .longMeasureBuilder("spanTimer")
            .setUnit("ms")
            .setDescription("How long the spans take")
            .setAbsolute(true)
            .build();
  1. Use these instruments for recording some metrics:
   spanCounter.add(1, "spanName", "testSpan", "isItAnError", "true");
   spanTimer.record(1000, "spanName", "testSpan")
  1. Find your metrics in New Relic One: go to https://one.newrelic.com/ and locate your service in the Entity explorer (based on the "service.name" attributes you've used).

Auto-Instrumentation

To instrument tracers and meters using the opentelemetry-javaagent, opentelemetry-exporter-newrelic-auto-<version>.jar can be used to provide opentelemetry exporters. Here is an example.

java -javaagent:path/to/opentelemetry-javaagent-<version>-all.jar \
     -Dotel.exporter.jar=path/to/opentelemetry-exporter-newrelic-auto-<version>.jar \
     -Dotel.exporter.newrelic.api.key=${INSIGHTS_INSERT_KEY} \
     -Dotel.exporter.newrelic.service.name=best-service-ever \
     -jar myapp.jar

⚠️ If you encounter an error like this:

[main] WARN io.opentelemetry.auto.tooling.TracerInstaller - No span exporter found in opentelemetry-exporters-newrelic-auto-0.8.1.jar

Check our release notes and verify the version of your opentelemetry-exporter-newrelic-auto-<version>.jar supports the version of opentelemetry-javaagent-all.jar.

If you wish to turn on debug logging for the exporter running in the auto-instrumentation agent, use the following system property:

-Dio.opentelemetry.javaagent.slf4j.simpleLogger.log.com.newrelic.telemetry=debug

And, if you wish to enable audit logging for the exporter running in the auto-instrumentaiotn agent, use this system property:

-Dotel.exporter.newrelic.enable.audit.logging=true

Javadoc for this project can be found here: Javadocs

Find and use your data

For tips on how to find and query your data in New Relic, see Find trace/span data.

For general querying information, see:

Gradle

build.gradle:

repositories {
    maven {
        url = "https://oss.sonatype.org/content/repositories/snapshots"
    }
}
implementation("com.newrelic.telemetry:opentelemetry-exporters-newrelic:0.9.0")
implementation("io.opentelemetry:opentelemetry-sdk:0.9.1")
implementation("com.newrelic.telemetry:telemetry-core:0.9.0")
implementation("com.newrelic.telemetry:telemetry-http-okhttp:0.9.0")

Getting Started

If you want to get started quickly, the easiest way is to configure the OpenTelemetry SDK and the New Relic exporters like this:

    NewRelicExporters.Configuration configuration =
      new NewRelicExporters.Configuration(apiKey, "My Service Name")
        .enableAuditLogging()
        .collectionIntervalSeconds(10);
    NewRelicExporters.start(configuration);

Be sure to shut down the exporters when your application finishes:

   NewRelicExporters.shutdown();

Building

CI builds are run on Github Actions:

PR build

Here are the current and past runs of the PR build action.

The project uses gradle 5 for building, and the gradle wrapper is provided.

To compile, run the tests and build the jar:

$ ./gradlew build

Support

Should you need assistance with New Relic products, you are in good hands with several support channels.

If the issue has been confirmed as a bug or is a feature request, file a GitHub issue.

Support Channels

Privacy

At New Relic we take your privacy and the security of your information seriously, and are committed to protecting your information. We must emphasize the importance of not sharing personal data in public forums, and ask all users to scrub logs and diagnostic information for sensitive information, whether personal, proprietary, or otherwise.

We define “Personal Data” as any information relating to an identified or identifiable individual, including, for example, your name, phone number, post code or zip code, Device ID, IP address, and email address.

For more information, review New Relic’s General Data Privacy Notice.

Contribute

We encourage your contributions to improve opentelemetry-exporter-java! 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 OpenTelemetry Exporter (Java).

License

opentelemetry-exporter-java is licensed under the Apache 2.0 License.

opentelemetry-exporter-java's People

Contributors

a-feld avatar alexandermann avatar breedx-nr avatar cmouli84 avatar dengliming avatar gfuller1 avatar jasonjkeller avatar jeffalder avatar jkwatson avatar mjarvie avatar paperclypse avatar xixiapdx avatar zuluecho9 avatar

Watchers

 avatar

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.