import "github.com/newrelic/opentelemetry-exporter-go/newrelic"
Package newrelic provides an OpenTelemetry exporter for New Relic.
func InstallNewPipeline(service string) (*controller.Controller, error)
InstallNewPipeline installs a New Relic exporter with default settings in the global OpenTelemetry telemetry pipeline. It is the callers responsibility to stop the returned push 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
Code:
// 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())
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 callers 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
Code:
// Include environment in resource. r := resource.NewWithAttributes( label.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{ trace.WithConfig(trace.Config{ // Conservative sampler. DefaultSampler: trace.ParentBased(trace.NeverSample()), // Reduce span events. MaxEventsPerSpan: 10, Resource: 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) otel.SetMeterProvider(controller.MeterProvider())
type Exporter struct {
// contains filtered or unexported fields
}
Exporter exports OpenTelemetry data to New Relic.
NewExporter creates a new Exporter that exports telemetry to New Relic.
Code:
// 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)),
)
func (e *Exporter) Export(_ context.Context, cps exportmetric.CheckpointSet) error
Export exports metrics to New Relic.
func (e *Exporter) ExportKindFor(_ *metric.Descriptor, _ aggregation.Kind) exportmetric.ExportKind
func (e *Exporter) ExportSpans(ctx context.Context, spans []*exporttrace.SpanSnapshot) error
ExportSpans exports span data to New Relic.
Path | Synopsis |
---|---|
internal/transform |
Package newrelic imports 19 packages (graph). Updated 2021-01-27. Refresh now. Tools for package owners.