[outputs.application_insights] Added the ability to set the endpoint url (#7134)

This commit is contained in:
DM 2020-08-20 01:04:24 +03:00 committed by GitHub
parent 11afd42617
commit a03555ec5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -7,6 +7,9 @@ This plugin writes telegraf metrics to [Azure Application Insights](https://azur
[[outputs.application_insights]]
## Instrumentation key of the Application Insights resource.
instrumentation_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
## Regions that require endpoint modification https://docs.microsoft.com/en-us/azure/azure-monitor/app/custom-endpoints
# endpoint_url = "https://dc.services.visualstudio.com/v2/track"
## Timeout for closing (default: 5s).
# timeout = "5s"

View File

@ -24,6 +24,7 @@ type DiagnosticsMessageSubscriber interface {
type ApplicationInsights struct {
InstrumentationKey string
EndpointURL string
Timeout internal.Duration
EnableDiagnosticLogging bool
ContextTagSources map[string]string
@ -43,6 +44,9 @@ var (
sampleConfig = `
## Instrumentation key of the Application Insights resource.
instrumentation_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
## Regions that require endpoint modification https://docs.microsoft.com/en-us/azure/azure-monitor/app/custom-endpoints
# endpoint_url = "https://dc.services.visualstudio.com/v2/track"
## Timeout for closing (default: 5s).
# timeout = "5s"
@ -76,7 +80,7 @@ func (a *ApplicationInsights) Connect() error {
}
if a.transmitter == nil {
a.transmitter = NewTransmitter(a.InstrumentationKey)
a.transmitter = NewTransmitter(a.InstrumentationKey, a.EndpointURL)
}
if a.EnableDiagnosticLogging && a.diagMsgSubscriber != nil {

View File

@ -1,13 +1,21 @@
package application_insights
import "github.com/Microsoft/ApplicationInsights-Go/appinsights"
import (
"github.com/Microsoft/ApplicationInsights-Go/appinsights"
)
type Transmitter struct {
client appinsights.TelemetryClient
}
func NewTransmitter(ikey string) *Transmitter {
return &Transmitter{client: appinsights.NewTelemetryClient(ikey)}
func NewTransmitter(ikey string, endpointURL string) *Transmitter {
if len(endpointURL) == 0 {
return &Transmitter{client: appinsights.NewTelemetryClient(ikey)}
} else {
telemetryConfig := appinsights.NewTelemetryConfiguration(ikey)
telemetryConfig.EndpointUrl = endpointURL
return &Transmitter{client: appinsights.NewTelemetryClientFromConfig(telemetryConfig)}
}
}
func (t *Transmitter) Track(telemetry appinsights.Telemetry) {