-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
New Relic Exporter #229
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
c04ba9c
Initial tracing
MrAlias 4f6d447
Config tests and refactor
MrAlias d7e75e1
Factory tests
MrAlias 669c2bc
Split transformer into own file
MrAlias 6f7b6ab
Add integration test of exporting spans
MrAlias 6a08b0f
Add transform tests
MrAlias 06543b7
Initial metrics
MrAlias a016a7d
Add integration test for metric export
MrAlias cf4aa6e
Add transform tests
MrAlias d6c4583
Update version and include in project go.mod
MrAlias 85388b1
Add README
MrAlias 29f5966
Lint fixes
MrAlias 92d7d62
Add to main components
MrAlias 1015971
Merge branch 'master' into newrelic-exporter
MrAlias e2aecb3
Fix lint
MrAlias 584a970
Add units to default in README
MrAlias ceccfed
Remove sync.Pool
MrAlias 548dc25
Merge remote-tracking branch 'upstream/master' into newrelic-exporter
MrAlias 66ad419
Merge branch 'master' into newrelic-exporter
MrAlias faf2fd2
Update collector package
MrAlias 1c68a89
Fix lint
MrAlias ab141ec
Merge remote-tracking branch 'upstream/master' into newrelic-exporter
MrAlias 66369e7
Update go.mod
MrAlias 237624a
Update top level go.mod and go.sum
MrAlias f1390d4
Clean go.sum for newrelicexporter
MrAlias 645da29
Update go.mod
MrAlias 42c2cf8
Manually prune go.sum
MrAlias 5a8c663
Try to fix loadtest
MrAlias ee2a516
go mod tidy
MrAlias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
MrAlias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
go.uber.org/zap v1.10.0 | ||
google.golang.org/protobuf v1.24.0 | ||
MrAlias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.