{"id":15137818,"url":"https://github.com/newrelic/opentelemetry-exporter-java","last_synced_at":"2025-09-29T06:31:09.163Z","repository":{"id":44718905,"uuid":"211926805","full_name":"newrelic/opentelemetry-exporter-java","owner":"newrelic","description":"An OpenTelemetry exporter that sends telemetry to New Relic","archived":true,"fork":false,"pushed_at":"2022-01-28T18:15:50.000Z","size":519,"stargazers_count":15,"open_issues_count":0,"forks_count":18,"subscribers_count":23,"default_branch":"main","last_synced_at":"2025-01-11T13:01:35.085Z","etag":null,"topics":["java","monitoring","newrelic","open-source","open-telemetry","telemetry-java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/newrelic.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-30T18:25:37.000Z","updated_at":"2023-03-22T03:03:28.000Z","dependencies_parsed_at":"2022-09-05T16:41:29.716Z","dependency_job_id":null,"html_url":"https://github.com/newrelic/opentelemetry-exporter-java","commit_stats":null,"previous_names":["newrelic/opentelemetry-exporters-newrelic"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newrelic%2Fopentelemetry-exporter-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newrelic%2Fopentelemetry-exporter-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newrelic%2Fopentelemetry-exporter-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/newrelic%2Fopentelemetry-exporter-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/newrelic","download_url":"https://codeload.github.com/newrelic/opentelemetry-exporter-java/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234470337,"owners_count":18838635,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","monitoring","newrelic","open-source","open-telemetry","telemetry-java"],"created_at":"2024-09-26T07:02:15.786Z","updated_at":"2025-09-29T06:31:08.764Z","avatar_url":"https://github.com/newrelic.png","language":"Java","readme":"[![Archived header](https://github.com/newrelic/open-source-office/raw/master/examples/categories/images/Archived.png)](https://github.com/newrelic/open-source-office/blob/master/examples/categories/index.md#archived)\n\n# Archival Notice\n\n❗Notice: This project has been archived _as is_ and is no longer actively maintained.\n\nRather than developing a Java specific OpenTelemetry exporter New Relic has adopted a language agnostic approach that facilitates data collection from all OpenTelemetry data sources.\n\nThe current recommended approaches for sending OpenTelemetry data to the New Relic platform are as follows:\n* Configure your OpenTelemetry data source to send data to the [OpenTelemetry Collector](https://docs.newrelic.com/docs/integrations/open-source-telemetry-integrations/opentelemetry/introduction-opentelemetry-new-relic/#collector) using the OpenTelemetry Protocol (OTLP) and configure the collector to forward the data using the [New Relic collector exporter](https://github.com/newrelic-forks/opentelemetry-collector-contrib/tree/newrelic-main/exporter/newrelicexporter).\n* Configure your OpenTelemetry data source to send data to the native OpenTelemetry Protocol (OTLP) data ingestion endpoint. [OTLP](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/otlp.md) is an open source gRPC based protocol for sending telemetry data. The protocol is vendor agnostic and open source.\n\nFor more details please see:\n* [OpenTelemetry quick start](https://docs.newrelic.com/docs/integrations/open-source-telemetry-integrations/opentelemetry/opentelemetry-quick-start/)\n* [Introduction to OpenTelemetry with New Relic](https://docs.newrelic.com/docs/integrations/open-source-telemetry-integrations/opentelemetry/introduction-opentelemetry-new-relic/)\n* [Native OpenTelemetry Protocol (OTLP) support](https://docs.newrelic.com/whats-new/2021/04/native-support-opentelemetry/)\n\n---\n\n\n# New Relic OpenTelemetry exporter\nAn [OpenTelemetry](https://github.com/open-telemetry/opentelemetry-java) exporter for sending spans and metrics\nto New Relic using the New Relic Java Telemetry SDK.\n\nFor the details on how OpenTelemetry data is mapped to New Relic data, see documentation in\n[Our exporter specifications documentation](https://github.com/newrelic/newrelic-exporter-specs)\n\n## How to use\n\nThe New Relic OpenTelemetry exporter can be used in two capacities: \n\n1. [Programmatically](#Programmatic-Usage) - an application takes a dependency on the exporter library, and manually invokes its APIs to report OpenTelemetry data to New Relic.\n2. [Auto Instrumentation](#Auto-Instrumentation-Usage) - configure an application to use the OpenTelemetry Java Agent for automatic instrumentation, and report the data to New Relic via the exporter.\n\nIn either case, to send the resulting spans and metrics to New Relic, you will need an \n[Insights Insert API Key](https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/introduction-event-api#).\n\n### Programmatic Usage\n\nThe New Relic OpenTelemetry exporter can be used programmatically, allowing an application to invoke its APIs as needed to report OpenTelemetry data to New Relic.\n\nThe workflow for programmatic use is as follows:\n- Create exporters for the data types to be reported. The exporter currently supports spans and metrics.\n- Register the exporters using OpenTelemetry APIs.\n- Use the OpenTelemetry APIs to record data, which will be exported to New Relic.\n- At the end of the application's lifecycle, call shutdown APIs to stop OpenTelemetry and exporter activity.\n\n[BasicExample.java](opentelemetry-exporters-newrelic/src/test/java/com/newrelic/telemetry/opentelemetry/examples/BasicExample.java) gives a good end to end\ndemonstration of this workflow. It should be considered the canonical code for this type of workflow since OpenTelemetry internal SDK APIs are still a work in \nprogress.\n\nThe easiest way to get started using the OpenTelemetry SDK with the New Relic exporters is as follows:\n\nAdd required dependencies in `build.gradle` (see [Published Artifacts](#Published-Artifacts) for versions):\n\n```\nrepositories {\n    maven {\n        url = \"https://oss.sonatype.org/content/repositories/snapshots\"\n    }\n}\n\ndependencies {\n    implementation(\"com.newrelic.telemetry:opentelemetry-exporters-newrelic:{version}\")\n    implementation(\"io.opentelemetry:opentelemetry-sdk:{version}\")\n    implementation(\"com.newrelic.telemetry:telemetry-core:{version\")\n    implementation(\"com.newrelic.telemetry:telemetry-http-okhttp:{version}\")\n}\n```\n\nUse the provided APIs in your application to set up exporters to record and send OpenTelemetry trace and metric data:\n\n```java\n    // Configure the New Relic exporters.\n    NewRelicExporters.Configuration configuration =\n        new NewRelicExporters.Configuration(apiKey, \"My Service Name\")\n            .enableAuditLogging() // Optionally enable audit logging\n            .collectionIntervalSeconds(\n                10); // Set the reporting interval for metrics/spans to 10 seconds\n\n    // Start the exporters with the supplied configuration. This starts both a NewRelicSpanExporter\n    // and a NewRelicMetricExporter as well as a BatchSpanProcessor and an IntervalMetricReader, the\n    // latter of which manage the batching and sending of their respective telemetry data types.\n    NewRelicExporters.start(configuration);\n\n    // Now that we've got the SDK configured and the exporters started, let's write some very simple\n    // instrumentation to demonstrate how it all works.\n\n    // Call the OpenTelemetry SDK to obtain tracers and meters to record data.\n    // A Tracer is used to create Spans that form traces.\n    Tracer tracer = OpenTelemetry.getGlobalTracerProvider().get(\"sample-app\", \"1.0\");\n    // A Meter is used to create different instruments to record metrics.\n    Meter meter = OpenTelemetry.getGlobalMeterProvider().get(\"sample-app\", \"1.0\");\n\n    // Use the tracer and meter to record telemetry data for your application. See the sections \n    // in the README on Recording Spans and Recording Metrics for specific usage examples. \n\n    // When the application is complete, be sure to call shutdown to stop the exporters.\n    // This will flush any data from the exporters before they exit.\n    NewRelicExporters.shutdown();\n```\n\nThe previous example hides some boilerplate code that can be further customized if more flexibility is required. Specifically the call to \n`NewRelicExporters.start(configuration)` automatically starts both a `NewRelicSpanExporter` and a `NewRelicMetricExporter` for you using the same configuration \nfor both. If you wish to configure each exporter separately, or simply don't need to export both spans and metrics, then [Recording Spans](#Recording-Spans) \nand [Recording Metrics](#Recording-Metrics) sections describe how to do this as well as how to use the Tracer and Meter APIs to record telemetry data.\n\n#### Recording Spans\n \n[BasicExample.java](opentelemetry-exporters-newrelic/src/test/java/com/newrelic/telemetry/opentelemetry/examples/BasicExample.java) demonstrates the easiest way\nto configure the span exporter. If your application needs more flexibility, it can be further configured as follows (see the `NewRelicSpanExporter` \nand `BatchSpanProcessor` APIs for all configuration options):\n\n```java\n    // Explicitly create and configure a NewRelicSpanExporter.\n    NewRelicSpanExporter exporter =\n        NewRelicSpanExporter.newBuilder()\n            .apiKey(System.getenv(\"INSIGHTS_INSERT_KEY\"))\n            .commonAttributes(new Attributes().put(SERVICE_NAME, \"best service ever\"))\n            .build();\n\n    // Use the NewRelicSpanExporter to create and configure a BatchSpansProcessor.\n    BatchSpanProcessor spanProcessor =\n        BatchSpanProcessor.builder(exporter)\n            .setScheduleDelayMillis(10_000) // Optionally override the default schedule delay\n            .build();\n\n    // Register the span processor with the default TracerSdkManagement of the OpenTelemetrySdk.\n    OpenTelemetrySdk.getGlobalTracerManagement().addSpanProcessor(spanProcessor);\n```\n\nOnce the span exporter has been registered with the `OpenTelemetrySdk`, spans can be recorded as follows:\n\n```java\n    // Create an OpenTelemetry Tracer and use it to record spans.\n    Tracer tracer = OpenTelemetry.getGlobalTracerProvider().get(\"sample-app\", \"1.0\");\n\n    Span span = tracer.spanBuilder(\"testSpan\").setSpanKind(Span.Kind.INTERNAL).startSpan();\n    try (Scope scope = span.makeCurrent()) {\n        // do some work\n    } catch (Throwable t) {\n        span.setStatus(StatusCode.ERROR, \"error description\"); // record error details.\n    } finally {\n        span.end(); // closing the scope does not end the span, this has to be done manually.\n    }\n```\n\nFind your spans in New Relic One: go to [New Relic One](https://one.newrelic.com/) and select **Distributed Tracing**.\n\n#### Recording Metrics\n\n[BasicExample.java](opentelemetry-exporters-newrelic/src/test/java/com/newrelic/telemetry/opentelemetry/examples/BasicExample.java) demonstrates the easiest way\nto configure the metric exporter. If your application needs more flexibility, it can be further configured as follows (see the `NewRelicMetricExporter` \nand `IntervalMetricReader` APIs for all configuration options):\n\n```java\n    // Explicitly create and configure a NewRelicMetricExporter.\n    MetricExporter metricExporter =\n        NewRelicMetricExporter.newBuilder()\n          .apiKey(System.getenv(\"INSIGHTS_INSERT_KEY\"))\n          .commonAttributes(new Attributes().put(SERVICE_NAME, \"best service ever\"))\n          .build();\n\n    // Use the NewRelicMetricExporter to create and configure an IntervalMetricReader.\n    IntervalMetricReader intervalMetricReader =\n        IntervalMetricReader.builder()\n            .setMetricProducers(\n                Collections.singleton(OpenTelemetrySdk.getGlobalMeterProvider().getMetricProducer()))\n            .setExportIntervalMillis(5000) // Batch up metrics every 5 seconds, or on whatever schedule the application requires\n            .setMetricExporter(metricExporter)\n            .build();\n```\n\nOnce the `IntervalMetricReader` has been setup with the metric exporter, metrics can be recorded as follows:\n\n```java\n    // A Meter is used to create different instruments to record metrics.\n    Meter meter = OpenTelemetry.getGlobalMeterProvider().get(\"sample-app\", \"1.0\");\n\n    // Use the meter to create a LongCounter instrument to record metrics.\n    LongCounter spanCounter =\n        meter\n            .longCounterBuilder(\"spanCounter\")\n            .setUnit(\"one\")\n            .setDescription(\"Counting all the spans\")\n            .build();\n\n    // Use the meter to create a LongValueRecorder instrument to record metrics.\n    LongValueRecorder spanTimer =\n        meter\n            .longValueRecorderBuilder(\"spanTimer\")\n            .setUnit(\"ms\")\n            .setDescription(\"How long the spans take\")\n            .build();\n    \n    // Use the meter to create a LongUpDownCounter instrument to record metrics.\n    LongUpDownCounter upDownCounter =\n        meter\n            .longUpDownCounterBuilder(\"jim\")\n            .setDescription(\"some good testing\")\n            .setUnit(\"1\")\n            .build();\n\n    // Use the instruments to record metric measurements.\n    spanCounter.add(1, Labels.of(\"spanName\", \"testSpan\", \"isItAnError\", \"\" + markAsError));\n    upDownCounter.add(random.nextInt(100) - 50);\n\n    // Optionally, you can pre-bind a set of labels, rather than passing them in every time.\n    LongValueRecorder.BoundLongValueRecorder boundTimer = spanTimer.bind(Labels.of(\"spanName\", \"testSpan\"));\n    boundTimer.record(System.currentTimeMillis() - startTime);\n```\n\nTo find your metrics in New Relic One, go to [New Relic One](https://one.newrelic.com/) and locate your service in the **Entity explorer** \n(based on the `\"service.name\"` attributes you've used).\n\n### Auto Instrumentation Usage\n\nIn order to automatically instrument an application, it must be configured to use the OpenTelemetry Java Agent and to use the New Relic OpenTelemetry exporter \nby passing several `options` to the `java [options] -jar \u003cmainclass\u003e\u003e [args..]` command.\n\nThe OpenTelemetry Java Agent must be downloaded (various versions available [here](https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases)),\n and specified via: \n\n`-javaagent:path/to/opentelemetry-javaagent-\u003cversion\u003e-all.jar`\n\nThe New Relic OpenTelemetry Exporter must be downloaded \n(various versions available [here](https://repo1.maven.org/maven2/com/newrelic/telemetry/opentelemetry-exporters-newrelic-auto/)), and specified via:\n\n`-Dotel.exporter.jar=path/to/opentelemetry-exporter-newrelic-auto-\u003cversion\u003e.jar`\n\nA New Relic Insights Insert API key must be specified via:\n\n`-Dnewrelic.api.key=${INSIGHTS_INSERT_KEY}`\n\nThe application's service name _should_ be specified via:\n\n`-Dnewrelic.service.name=best-service-ever`\n\nThe configuration can be optionally further customized using the available [system properties](#Configuration-System-Properties).\n\nBringing it all together, the command to run the application will look something like:\n\n```bash\njava -javaagent:path/to/opentelemetry-javaagent-\u003cversion\u003e-all.jar \\\n     -Dotel.exporter.jar=path/to/opentelemetry-exporter-newrelic-auto-\u003cversion\u003e.jar \\\n     -Dnewrelic.api.key=${INSIGHTS_INSERT_KEY} \\\n     -Dnewrelic.service.name=best-service-ever \\\n     -jar myapp.jar\n```\n\n:warning: If you encounter an error like this:\n\n```\n[main] WARN io.opentelemetry.auto.tooling.TracerInstaller - No span exporter found in opentelemetry-exporters-newrelic-auto-0.8.1.jar\n```\n\nCheck our [release notes](https://github.com/newrelic/opentelemetry-exporter-java/releases) and verify the version of your \n`opentelemetry-exporter-newrelic-auto-\u003cversion\u003e.jar` supports the version of `opentelemetry-javaagent-all.jar`.\n\n#### Configuration System Properties\n\nCurrently, the New Relic OpenTelemetry exporter supports the following configuration via system properties. \n\n| System property                                                                  | Purpose                                                                                                                                                                                                            |\n|----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `newrelic.api.key`                                                               | **[Required]** The [Insights insert key](https://docs.newrelic.com/docs/telemetry-data-platform/ingest-manage-data/ingest-apis/use-event-api-report-custom-events#register) to report telemetry data to New Relic. |\n| `newrelic.service.name`                                                          | **[Recommended]** The service name of this JVM instance, default is `(unknown service)`.                                                                                                                           |\n| `newrelic.trace.uri.override`                                                    | The New Relic endpoint to connect to for reporting Spans, default is US Prod. For the EU region use: https://trace-api.eu.newrelic.com/trace/v1                                                                    |\n| `newrelic.metric.uri.override`                                                   | The New Relic endpoint to connect to for reporting metrics, default is US Prod. For the EU region use: https://metric-api.eu.newrelic.com/metric/v1                                                                |\n| `newrelic.enable.audit.logging`                                                  | Enable verbose audit logging to display the JSON batches sent each harvest.                                                                                                                                        |\n| `io.opentelemetry.javaagent.slf4j.simpleLogger.log.com.newrelic.telemetry=debug` | Enable `debug` logging for the exporter when running in the auto-instrumentation agent.                                                                                                                            |\n\n## Published Artifacts\n\nThis project publishes two artifacts in alignment with the two workflows for using the exporter described in [How to use](#How-to-use):\n\n|Group                 |Name                                 |Link                                                                                                   |Description                                                  |\n|----------------------|-------------------------------------|-------------------------------------------------------------------------------------------------------|-------------------------------------------------------------|\n|com.newrelic.telemetry|opentelemetry-exporters-newrelic     |[Maven](https://search.maven.org/artifact/com.newrelic.telemetry/opentelemetry-exporters-newrelic)     |For [Programmatic Usage](#Programmatic-Usage)                |\n|com.newrelic.telemetry|opentelemetry-exporters-newrelic-auto|[Maven](https://search.maven.org/artifact/com.newrelic.telemetry/opentelemetry-exporters-newrelic-auto)|For [Auto Instrumentation Usage](#Auto-Instrumentation-Usage)|\n\nRelease notes are available [here](https://github.com/newrelic/opentelemetry-exporter-java/releases).\n\nJavadoc for this project can be found here: [![Javadocs][javadoc-image]][javadoc-url]\n\n## Find and use your data\n\nFor tips on how to find and query your data in New Relic, see \n[Find trace/span data](https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/trace-api/introduction-trace-api#view-data). \n\nFor general querying information, see:\n- [Query New Relic data](https://docs.newrelic.com/docs/using-new-relic/data/understand-data/query-new-relic-data)\n- [Intro to NRQL](https://docs.newrelic.com/docs/query-data/nrql-new-relic-query-language/getting-started/introduction-nrql)\n\n## Building\n\nRequires Java 8+ to build.\n\nCI builds are run on Github Actions:\n\n![PR build](https://github.com/newrelic/opentelemetry-exporter-java/workflows/Java%20PR%20build%20(gradle)/badge.svg?branch=main)\n\nHere are the current and past runs of [the PR build action.](https://github.com/newrelic/opentelemetry-exporter-java/actions?query=workflow%3A%22Java+PR+build+%28gradle%29%22)\n\nThe project uses gradle 5 for building, and the gradle wrapper is provided.\n\nTo compile, run the tests and build the jar:\n\n`$ ./gradlew build`\n\n## Support\n\nShould you need assistance with New Relic products, you are in good hands with several support channels.\n\nIf the issue has been confirmed as a bug or is a feature request, file a GitHub issue.\n\n**Support Channels**\n\n* [New Relic Documentation](https://docs.newrelic.com/docs/integrations/open-source-telemetry-integrations/open-source-telemetry-integration-list/new-relics-opentelemetry-integration): Comprehensive guidance for using our platform\n* [New Relic Community](https://discuss.newrelic.com/tags/javaagent): The best place to engage in troubleshooting questions\n* [New Relic Developer](https://developer.newrelic.com/): Resources for building a custom observability applications\n* [New Relic University](https://learn.newrelic.com/): A range of online training for New Relic users of every level\n\n## Privacy\nAt 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.\n\nWe 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.\n\nFor more information, review [New Relic’s General Data Privacy Notice](https://newrelic.com/termsandconditions/privacy).\n\n## Contribute\n\nWe 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.\n\nIf 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 opensource@newrelic.com.\n\n**A note about vulnerabilities**\n\nAs noted in our [security policy](../../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.\n\nIf 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](https://hackerone.com/newrelic).\n\nIf you would like to contribute to this project, review [these guidelines](./CONTRIBUTING.md).\n\nTo [all contributors](https://github.com/newrelic/opentelemetry-exporter-java/graphs/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)](https://opensource.newrelic.com/projects/newrelic/opentelemetry-exporter-java).\n\n## License\nopentelemetry-exporter-java is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.\n\n[javadoc-image]: https://www.javadoc.io/badge/com.newrelic.telemetry/opentelemetry-exporters-newrelic.svg\n[javadoc-url]: https://www.javadoc.io/doc/com.newrelic.telemetry/opentelemetry-exporters-newrelic\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewrelic%2Fopentelemetry-exporter-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnewrelic%2Fopentelemetry-exporter-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnewrelic%2Fopentelemetry-exporter-java/lists"}