[outputs.application_insights] Added the ability to set the endpoint url (#7134)
This commit is contained in:
parent
11afd42617
commit
a03555ec5a
|
|
@ -7,6 +7,9 @@ This plugin writes telegraf metrics to [Azure Application Insights](https://azur
|
||||||
[[outputs.application_insights]]
|
[[outputs.application_insights]]
|
||||||
## Instrumentation key of the Application Insights resource.
|
## Instrumentation key of the Application Insights resource.
|
||||||
instrumentation_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
|
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 for closing (default: 5s).
|
||||||
# timeout = "5s"
|
# timeout = "5s"
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ type DiagnosticsMessageSubscriber interface {
|
||||||
|
|
||||||
type ApplicationInsights struct {
|
type ApplicationInsights struct {
|
||||||
InstrumentationKey string
|
InstrumentationKey string
|
||||||
|
EndpointURL string
|
||||||
Timeout internal.Duration
|
Timeout internal.Duration
|
||||||
EnableDiagnosticLogging bool
|
EnableDiagnosticLogging bool
|
||||||
ContextTagSources map[string]string
|
ContextTagSources map[string]string
|
||||||
|
|
@ -43,6 +44,9 @@ var (
|
||||||
sampleConfig = `
|
sampleConfig = `
|
||||||
## Instrumentation key of the Application Insights resource.
|
## Instrumentation key of the Application Insights resource.
|
||||||
instrumentation_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
|
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 for closing (default: 5s).
|
||||||
# timeout = "5s"
|
# timeout = "5s"
|
||||||
|
|
@ -76,7 +80,7 @@ func (a *ApplicationInsights) Connect() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.transmitter == nil {
|
if a.transmitter == nil {
|
||||||
a.transmitter = NewTransmitter(a.InstrumentationKey)
|
a.transmitter = NewTransmitter(a.InstrumentationKey, a.EndpointURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.EnableDiagnosticLogging && a.diagMsgSubscriber != nil {
|
if a.EnableDiagnosticLogging && a.diagMsgSubscriber != nil {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,21 @@
|
||||||
package application_insights
|
package application_insights
|
||||||
|
|
||||||
import "github.com/Microsoft/ApplicationInsights-Go/appinsights"
|
import (
|
||||||
|
"github.com/Microsoft/ApplicationInsights-Go/appinsights"
|
||||||
|
)
|
||||||
|
|
||||||
type Transmitter struct {
|
type Transmitter struct {
|
||||||
client appinsights.TelemetryClient
|
client appinsights.TelemetryClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTransmitter(ikey string) *Transmitter {
|
func NewTransmitter(ikey string, endpointURL string) *Transmitter {
|
||||||
return &Transmitter{client: appinsights.NewTelemetryClient(ikey)}
|
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) {
|
func (t *Transmitter) Track(telemetry appinsights.Telemetry) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue