Skip to content

Commit

Permalink
Use the agent license for self instrumentation. Added APM collector u…
Browse files Browse the repository at this point in the history
…rl logic
  • Loading branch information
rubenruizdegauna committed Mar 1, 2022
1 parent 5b2f3f7 commit e2748d0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
5 changes: 4 additions & 1 deletion internal/agent/instrumentation/agent_instrumentation_apm.go
Expand Up @@ -10,7 +10,10 @@ import (

const transactionInContextKey = iota

const appName = "New Relic Infrastructure Agent"
const (
appName = "New Relic Infrastructure Agent"
apmInstrumentationName = "newrelic"
)

type agentInstrumentationApm struct {
nrApp *newrelic.Application
Expand Down
Expand Up @@ -7,11 +7,11 @@ import (
)

func InitSelfInstrumentation(c *config.Config, resolver hostname.Resolver) {
if strings.ToLower(c.SelfInstrumentation) == "apm" && c.SelfInstrumentationLicenseKey != "" {
if strings.ToLower(c.SelfInstrumentation) == apmInstrumentationName {
apmSelfInstrumentation, err := NewAgentInstrumentationApm(
c.SelfInstrumentationLicenseKey,
c.SelfInstrumentationApmEndpoint,
c.SelfInstrumentationTelemetryEndpoint,
c.License,
c.SelfInstrumentationApmHost,
c.MetricURL,
resolver,
)
if err == nil {
Expand Down
33 changes: 25 additions & 8 deletions pkg/config/config.go
Expand Up @@ -1065,15 +1065,10 @@ type Config struct {
// Public: No
SelfInstrumentation string `yaml:"self_instrumentation" envconfig:"self_instrumentation"`

// SelfInstrumentationLicenseKey license key for apm self instrumentation
// Default: empty
// SelfInstrumentationApmHost defines the url for APM collector host
// Default: collector.newrelic.com
// Public: No
SelfInstrumentationLicenseKey string `yaml:"self_instrumentation_license_key" envconfig:"self_instrumentation_license_key"`

// SelfInstrumentationApmEndpoint OpenTelemetry endpoint for self instrumentation
// Default: empty
// Public: No
SelfInstrumentationApmEndpoint string `yaml:"self_instrumentation_apm_endpoint" envconfig:"self_instrumentation_apm_endpoint"`
SelfInstrumentationApmHost string `yaml:"self_instrumentation_apm_host" envconfig:"self_instrumentation_apm_host"`

// SelfInstrumentationTelemetryEndpoint OpenTelemetry endpoint for self instrumentation
// Default: empty
Expand Down Expand Up @@ -1548,6 +1543,24 @@ func calculateCmdChannelStagingURL(licenseKey string) string {
return defaultCmdChannelStagingURL
}

func calculateSelfInstrumentationApmHost(licenseKey string, staging bool, fedramp bool) string {
if staging {
return defaultAPMCollectorHostStaging
}
if fedramp {
return defaultSecureFederalAPMCollectorHost
}
return calculateSelfInstrumentationApmProductionHost(licenseKey)
}

func calculateSelfInstrumentationApmProductionHost(licenseKey string) string {
// only EU supported
if license.IsRegionEU(licenseKey) {
return defaultAPMCollectorHostEu
}
return defaultAPMCollectorHost
}

func calculateDimensionalMetricURL(collectorURL string, licenseKey string, staging, fedramp bool) string {
if collectorURL != "" {
return collectorURL
Expand Down Expand Up @@ -1880,6 +1893,10 @@ func NormalizeConfig(cfg *Config, cfgMetadata config_loader.YAMLMetadata) (err e
cfg.MemProfileInterval = defaultMemProfileInterval
}

if cfg.SelfInstrumentationApmHost == "" {
cfg.SelfInstrumentationApmHost = calculateSelfInstrumentationApmHost(cfg.License, cfg.Staging, cfg.Fedramp)
}

return
}

Expand Down
32 changes: 18 additions & 14 deletions pkg/config/defaults.go
Expand Up @@ -15,20 +15,24 @@ const (
LogFormatJSON = "json"

// Non configurable stuff
defaultIdentityURLEu = "https://identity-api.eu.newrelic.com"
defaultIdentityStagingURLEu = "https://staging-identity-api.eu.newrelic.com"
defaultCmdChannelURLEu = "https://infrastructure-command-api.eu.newrelic.com"
defaultCmdChannelStagingURLEu = "https://staging-infrastructure-command-api.eu.newrelic.com"
defaultCmdChannelURL = "https://infrastructure-command-api.newrelic.com"
defaultCmdChannelStagingURL = "https://staging-infrastructure-command-api.newrelic.com"
defaultIdentityURL = "https://identity-api.newrelic.com"
defaultIdentityStagingURL = "https://staging-identity-api.newrelic.com"
baseCollectorURL = "https://%sinfra-api.%snewrelic.com"
baseDimensionalMetricURL = "https://%smetric-api.%snewrelic.com"
defaultSecureFederalURL = "https://gov-infra-api.newrelic.com"
defaultSecureFederalMetricURL = "https://gov-metric-api.newrelic.com"
defaultSecureFedralIdentityURL = "https://gov-identity-api.newrelic.com"
defaultSecureFedralCmdChannelURL = "https://gov-infrastructure-command-api.newrelic.com"
defaultIdentityURLEu = "https://identity-api.eu.newrelic.com"
defaultIdentityStagingURLEu = "https://staging-identity-api.eu.newrelic.com"
defaultCmdChannelURLEu = "https://infrastructure-command-api.eu.newrelic.com"
defaultCmdChannelStagingURLEu = "https://staging-infrastructure-command-api.eu.newrelic.com"
defaultCmdChannelURL = "https://infrastructure-command-api.newrelic.com"
defaultCmdChannelStagingURL = "https://staging-infrastructure-command-api.newrelic.com"
defaultIdentityURL = "https://identity-api.newrelic.com"
defaultIdentityStagingURL = "https://staging-identity-api.newrelic.com"
baseCollectorURL = "https://%sinfra-api.%snewrelic.com"
baseDimensionalMetricURL = "https://%smetric-api.%snewrelic.com"
defaultSecureFederalURL = "https://gov-infra-api.newrelic.com"
defaultSecureFederalMetricURL = "https://gov-metric-api.newrelic.com"
defaultSecureFedralIdentityURL = "https://gov-identity-api.newrelic.com"
defaultSecureFedralCmdChannelURL = "https://gov-infrastructure-command-api.newrelic.com"
defaultAPMCollectorHost = "collector.newrelic.com"
defaultAPMCollectorHostEu = "collector.eu.newrelic.com"
defaultSecureFederalAPMCollectorHost = "gov-collector.newrelic.com"
defaultAPMCollectorHostStaging = "staging-collector.newrelic.com"
)

// Default configurable values
Expand Down

0 comments on commit e2748d0

Please sign in to comment.