Skip to content

New Relic Exporter #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c04ba9c
Initial tracing
MrAlias May 6, 2020
4f6d447
Config tests and refactor
MrAlias May 6, 2020
d7e75e1
Factory tests
MrAlias May 6, 2020
669c2bc
Split transformer into own file
MrAlias May 6, 2020
6f7b6ab
Add integration test of exporting spans
MrAlias May 6, 2020
6a08b0f
Add transform tests
MrAlias May 6, 2020
06543b7
Initial metrics
MrAlias May 7, 2020
a016a7d
Add integration test for metric export
MrAlias May 8, 2020
cf4aa6e
Add transform tests
MrAlias May 8, 2020
d6c4583
Update version and include in project go.mod
MrAlias May 11, 2020
85388b1
Add README
MrAlias May 11, 2020
29f5966
Lint fixes
MrAlias May 11, 2020
92d7d62
Add to main components
MrAlias May 11, 2020
1015971
Merge branch 'master' into newrelic-exporter
MrAlias May 12, 2020
e2aecb3
Fix lint
MrAlias May 12, 2020
584a970
Add units to default in README
MrAlias May 12, 2020
ceccfed
Remove sync.Pool
MrAlias May 12, 2020
548dc25
Merge remote-tracking branch 'upstream/master' into newrelic-exporter
MrAlias May 18, 2020
66ad419
Merge branch 'master' into newrelic-exporter
MrAlias Jun 2, 2020
faf2fd2
Update collector package
MrAlias Jun 2, 2020
1c68a89
Fix lint
MrAlias Jun 2, 2020
ab141ec
Merge remote-tracking branch 'upstream/master' into newrelic-exporter
MrAlias Jun 2, 2020
66369e7
Update go.mod
MrAlias Jun 2, 2020
237624a
Update top level go.mod and go.sum
MrAlias Jun 2, 2020
f1390d4
Clean go.sum for newrelicexporter
MrAlias Jun 2, 2020
645da29
Update go.mod
MrAlias Jun 3, 2020
42c2cf8
Manually prune go.sum
MrAlias Jun 3, 2020
5a8c663
Try to fix loadtest
MrAlias Jun 3, 2020
ee2a516
go mod tidy
MrAlias Jun 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/jaegerthrifthttpexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/kinesisexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/lightstepexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/newrelicexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sapmexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/signalfxexporter"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/splunkhecexporter"
Expand Down Expand Up @@ -101,6 +102,7 @@ func components() (config.Factories, error) {
&honeycombexporter.Factory{},
&jaegerthrifthttpexporter.Factory{},
&lightstepexporter.Factory{},
&newrelicexporter.Factory{},
&splunkhecexporter.Factory{},
&elasticexporter.Factory{},
}
Expand Down
1 change: 1 addition & 0 deletions exporter/newrelicexporter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
39 changes: 39 additions & 0 deletions exporter/newrelicexporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# New Relic Exporter

This exporter supports sending trace and metric data to [New Relic](https://newrelic.com/)

## Configuration

The following configuration options are supported:

* `apikey` (Required): Your New Relic [Insights Insert API Key](https://docs.newrelic.com/docs/insights/insights-data-sources/custom-data/send-custom-events-event-api#register).
* `timeout` (Optional): Amount of time spent attempting a request before abandoning and dropping data. Default is 15 seconds.
* `common_attributes` (Optional): Attributes to apply to all metrics sent.
* `metrics_url_override` (Optional): Overrides the endpoint to send metrics.
* `spans_url_override` (Optional): Overrides the endpoint to send spans.

Example:

```yaml
exporters:
newrelic:
apikey: super-secret-api-key
timeout: 30s
common_attributes:
server: prod-server-01
ready_to_rock: true
volume: 11
```


## Find and use your data

Once the exporter is sending data you can start to explore your data in New Relic:

- Metric data: see [Metric API docs](https://docs.newrelic.com/docs/data-ingest-apis/get-data-new-relic/metric-api/introduction-metric-api#find-data).
- Trace/span data: see [Trace API docs](https://docs.newrelic.com/docs/understand-dependencies/distributed-tracing/trace-api/introduction-trace-api#view-data).

For general querying information, see:

- [Query New Relic data](https://docs.newrelic.com/docs/using-new-relic/data/understand-data/query-new-relic-data)
- [Intro to NRQL](https://docs.newrelic.com/docs/query-data/nrql-new-relic-query-language/getting-started/nrql-syntax-clauses-functions)
58 changes: 58 additions & 0 deletions exporter/newrelicexporter/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package newrelicexporter

import (
"time"

"github.com/newrelic/newrelic-telemetry-sdk-go/telemetry"
"go.opentelemetry.io/collector/config/configmodels"
)

// Config defines configuration options for the New Relic exporter.
type Config struct {
configmodels.ExporterSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.

// APIKey is the required authentication credentials for New Relic APIs.
APIKey string `mapstructure:"apikey"`

// Timeout is the total amount of time spent attempting a request,
// including retries, before abandoning and dropping data. Default is 15
// seconds.
Timeout time.Duration `mapstructure:"timeout"`

// CommonAttributes are the attributes to be applied to all telemetry
// sent to New Relic.
CommonAttributes map[string]interface{} `mapstructure:"common_attributes"`

// MetricsURLOverride overrides the metrics endpoint.
MetricsURLOverride string `mapstructure:"metrics_url_override"`

// SpansURLOverride overrides the spans endpoint.
SpansURLOverride string `mapstructure:"spans_url_override"`
}

// HarvestOption sets all relevant Config values when instantiating a New
// Relic Harvester.
func (c Config) HarvestOption(cfg *telemetry.Config) {
cfg.APIKey = c.APIKey
cfg.HarvestPeriod = 0 // use collector harvest period.
cfg.HarvestTimeout = c.Timeout
cfg.CommonAttributes = c.CommonAttributes
cfg.Product = product
cfg.ProductVersion = version
cfg.MetricsURLOverride = c.MetricsURLOverride
cfg.SpansURLOverride = c.SpansURLOverride
}
80 changes: 80 additions & 0 deletions exporter/newrelicexporter/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package newrelicexporter

import (
"path"
"testing"
"time"

"github.com/newrelic/newrelic-telemetry-sdk-go/telemetry"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configmodels"
)

func TestLoadConfig(t *testing.T) {
factories, err := config.ExampleComponents()
assert.Nil(t, err)

factory := &Factory{}
factories.Exporters[configmodels.Type(typeStr)] = factory
cfg, err := config.LoadConfigFile(
t, path.Join(".", "testdata", "config.yaml"), factories,
)

require.NoError(t, err)
require.NotNil(t, cfg)

assert.Equal(t, len(cfg.Exporters), 2)

r0 := cfg.Exporters["newrelic"]
assert.Equal(t, r0, factory.CreateDefaultConfig())

r1 := cfg.Exporters["newrelic/alt"].(*Config)
assert.Equal(t, r1, &Config{
ExporterSettings: configmodels.ExporterSettings{
TypeVal: configmodels.Type(typeStr),
NameVal: "newrelic/alt",
},
APIKey: "a1b2c3d4",
Timeout: time.Second * 30,
CommonAttributes: map[string]interface{}{
"server": "test-server",
"prod": true,
"weight": 3,
},
MetricsURLOverride: "http://alt.metrics.newrelic.com",
SpansURLOverride: "http://alt.spans.newrelic.com",
})

nrConfig := new(telemetry.Config)
r1.HarvestOption(nrConfig)

assert.Equal(t, nrConfig, &telemetry.Config{
APIKey: "a1b2c3d4",
HarvestTimeout: time.Second * 30,
CommonAttributes: map[string]interface{}{
"server": "test-server",
"prod": true,
"weight": 3,
},
MetricsURLOverride: "http://alt.metrics.newrelic.com",
SpansURLOverride: "http://alt.spans.newrelic.com",
Product: product,
ProductVersion: version,
})
}
65 changes: 65 additions & 0 deletions exporter/newrelicexporter/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package newrelicexporter

import (
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.uber.org/zap"
)

const typeStr = "newrelic"

// Factory is the factory for the New Relic exporter.
type Factory struct{}

// Type gets the type of the exporter configuration created by this factory.
func (f *Factory) Type() configmodels.Type {
return configmodels.Type(typeStr)
}

// CreateDefaultConfig creates a default configuration for this exporter.
func (f *Factory) CreateDefaultConfig() configmodels.Exporter {
return &Config{
ExporterSettings: configmodels.ExporterSettings{
TypeVal: configmodels.Type(typeStr),
NameVal: typeStr,
},
Timeout: time.Second * 15,
}
}

// CreateTraceExporter creates a New Relic trace exporter for this configuration.
func (f *Factory) CreateTraceExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.TraceExporterOld, error) {
exp, err := newExporter(logger, cfg)
if err != nil {
return nil, err
}

return exporterhelper.NewTraceExporterOld(cfg, exp.pushTraceData, exporterhelper.WithShutdown(exp.Shutdown))
}

// CreateMetricsExporter creates a New Relic metrics exporter for this configuration.
func (f *Factory) CreateMetricsExporter(logger *zap.Logger, cfg configmodels.Exporter) (component.MetricsExporterOld, error) {
exp, err := newExporter(logger, cfg)
if err != nil {
return nil, err
}

return exporterhelper.NewMetricsExporterOld(cfg, exp.pushMetricData, exporterhelper.WithShutdown(exp.Shutdown))
}
51 changes: 51 additions & 0 deletions exporter/newrelicexporter/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package newrelicexporter

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/config/configcheck"
"go.uber.org/zap"
)

func TestCreateDefaultConfig(t *testing.T) {
factory := Factory{}
cfg := factory.CreateDefaultConfig()
assert.NotNil(t, cfg, "failed to create default config")
require.NoError(t, configcheck.ValidateConfig(cfg))

nrCfg, ok := cfg.(*Config)
require.True(t, ok, "invalid Config: %#v", cfg)
assert.Equal(t, nrCfg.Timeout, time.Second*15)
}

func TestCreateExporter(t *testing.T) {
factory := Factory{}
cfg := factory.CreateDefaultConfig()
nrConfig := cfg.(*Config)
nrConfig.APIKey = "a1b2c3d4"

te, err := factory.CreateTraceExporter(zap.NewNop(), nrConfig)
assert.Nil(t, err)
assert.NotNil(t, te, "failed to create trace exporter")

me, err := factory.CreateMetricsExporter(zap.NewNop(), nrConfig)
assert.Nil(t, err)
assert.NotNil(t, me, "failed to create metrics exporter")
}
14 changes: 14 additions & 0 deletions exporter/newrelicexporter/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/exporter/newrelicexporter

go 1.14

require (
github.com/census-instrumentation/opencensus-proto v0.2.1
github.com/golang/protobuf v1.4.1
github.com/newrelic/newrelic-telemetry-sdk-go v0.2.0
github.com/stretchr/testify v1.5.1
go.opencensus.io v0.22.3
go.opentelemetry.io/collector v0.3.1-0.20200526215338-87af38a24676
go.uber.org/zap v1.10.0
google.golang.org/protobuf v1.24.0
)
Loading