Documentation ¶
Overview ¶
Package newrelic provides an OpenTelemetry exporter for New Relic.
Index ¶
- func InstallNewPipeline(service string) (*controller.Controller, error)
- func NewExportPipeline(service string, traceOpt []sdktrace.TracerProviderOption, ...) (trace.TracerProvider, *controller.Controller, error)
- type Exporter
- func (e *Exporter) Export(_ context.Context, cps exportmetric.CheckpointSet) error
- func (e *Exporter) ExportKindFor(_ *metric.Descriptor, _ aggregation.Kind) exportmetric.ExportKind
- func (e *Exporter) ExportSpans(ctx context.Context, spans []*exporttrace.SpanSnapshot) error
- func (e *Exporter) Shutdown(ctx context.Context) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InstallNewPipeline ¶
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
Example ¶
package main import ( "context" "log" "github.com/banked/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 ¶
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
Example ¶
package main import ( "context" "log" "time" "github.com/banked/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{ trace.WithSampler(trace.ParentBased(trace.NeverSample())), 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 ¶
NewExporter creates a new Exporter that exports telemetry to New Relic.
Example ¶
package main import ( "log" "os" "github.com/banked/opentelemetry-exporter-go/newrelic" "github.com/newrelic/newrelic-telemetry-sdk-go/telemetry" "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 ¶
func (e *Exporter) Export(_ context.Context, cps exportmetric.CheckpointSet) error
Export exports metrics to New Relic.
func (*Exporter) ExportKindFor ¶
func (e *Exporter) ExportKindFor(_ *metric.Descriptor, _ aggregation.Kind) exportmetric.ExportKind
func (*Exporter) ExportSpans ¶
func (e *Exporter) ExportSpans(ctx context.Context, spans []*exporttrace.SpanSnapshot) error
ExportSpans exports span data to New Relic.