newrelic

package
Version: v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2021 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Overview

Package newrelic provides an OpenTelemetry exporter for New Relic.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstallNewPipeline added in v0.13.0

func InstallNewPipeline(service string) (*controller.Controller, error)
Example
package main

import (
	"context"
	"log"

	"github.com/newrelic/opentelemetry-exporter-go/newrelic"
)

func main() {
	// Assumes the NEW_RELIC_API_KEY environment variable contains your New
	// Relic Event API key. This will error if it does not.
	controller, err := newrelic.InstallNewPipeline("My Service")
	if err != nil {
		log.Fatal(err)
	}
	defer controller.Stop(context.Background())
}
Output:

func NewExportPipeline added in v0.13.0

func NewExportPipeline(service string, traceOpt []sdktrace.TracerProviderOption, cOpt []controller.Option) (trace.TracerProvider, *controller.Controller, error)

NewExportPipeline creates a new OpenTelemetry telemetry pipeline using a New Relic Exporter configured with default setting. It is the caller's responsibility to stop the returned OTel Controller. This function uses the following environment variables to configure the exporter installed in the pipeline:

  • `NEW_RELIC_API_KEY`: New Relic Event API key.
  • `NEW_RELIC_METRIC_URL`: Override URL to New Relic metric endpoint.
  • `NEW_RELIC_TRACE_URL`: Override URL to New Relic trace endpoint.

More information about the New Relic Event API key can be found here: https://docs.newrelic.com/docs/apis/get-started/intro-apis/types-new-relic-api-keys#event-insert-key.

The exporter will send telemetry to the default New Relic metric and trace API endpoints in the United States. These can be overwritten with the above environment variables. These are useful if you wish to send to our EU endpoints:

  • EU metric API endpoint: metric-api.eu.newrelic.com/metric/v1
  • EU trace API endpoint: trace-api.eu.newrelic.com/trace/v1
Example
package main

import (
	"context"
	"log"
	"time"

	"github.com/newrelic/opentelemetry-exporter-go/newrelic"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/metric/global"

	controller "go.opentelemetry.io/otel/sdk/metric/controller/basic"
	"go.opentelemetry.io/otel/sdk/resource"
	"go.opentelemetry.io/otel/sdk/trace"
	"go.opentelemetry.io/otel/semconv"
)

func main() {
	// Include environment in resource.
	r := resource.NewWithAttributes(
		attribute.String("environment", "production"),
		semconv.ServiceNameKey.String("My Service"),
	)

	// Assumes the NEW_RELIC_API_KEY environment variable contains your New
	// Relic Event API key. This will error if it does not.
	traceProvider, controller, err := newrelic.NewExportPipeline(
		"My Service",
		[]trace.TracerProviderOption{
			// Conservative sampler.
			trace.WithSampler(trace.NeverSample()),
			// Reduce span events.
			trace.WithSpanLimits(trace.SpanLimits{
				EventCountLimit: 10,
			}),
			trace.WithResource(r),
		},
		[]controller.Option{
			// Increase push frequency.
			controller.WithCollectPeriod(time.Second),
			controller.WithResource(r),
		},
	)
	if err != nil {
		log.Fatal(err)
	}
	defer controller.Stop(context.Background())

	otel.SetTracerProvider(traceProvider)
	global.SetMeterProvider(controller.MeterProvider())
}
Output:

Types

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter exports OpenTelemetry data to New Relic.

func NewExporter

func NewExporter(service, apiKey string, options ...func(*telemetry.Config)) (*Exporter, error)

NewExporter creates a new Exporter that exports telemetry to New Relic.

Example
package main

import (
	"log"
	"os"

	"github.com/newrelic/newrelic-telemetry-sdk-go/telemetry"
	"github.com/newrelic/opentelemetry-exporter-go/newrelic"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/sdk/trace"
)

func main() {
	// To enable Infinite Tracing on the New Relic Edge, use the
	// telemetry.ConfigSpansURLOverride along with the URL for your Trace
	// Observer, including scheme and path.  See
	// https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/enable-configure/enable-distributed-tracing
	exporter, err := newrelic.NewExporter(
		"My Service", os.Getenv("NEW_RELIC_API_KEY"),
		telemetry.ConfigSpansURLOverride("https://nr-internal.aws-us-east-1.tracing.edge.nr-data.net/trace/v1"),
	)
	if err != nil {
		log.Fatal(err)
	}
	otel.SetTracerProvider(
		trace.NewTracerProvider(trace.WithSyncer(exporter)),
	)
}
Output:

func (*Exporter) Export added in v0.13.0

Export exports metrics to New Relic.

func (*Exporter) ExportKindFor added in v0.13.0

func (*Exporter) ExportSpans

func (e *Exporter) ExportSpans(ctx context.Context, spans []*sdktrace.SpanSnapshot) error

ExportSpans exports span data to New Relic.

func (*Exporter) Shutdown added in v0.13.0

func (e *Exporter) Shutdown(ctx context.Context) error

Source Files

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL