Skip to content

Commit

Permalink
[outputs.application_insights] Added the ability to set the endpoint …
Browse files Browse the repository at this point in the history
  • Loading branch information
Diabl0Man authored and idohalevi committed Sep 23, 2020
1 parent f2dcee3 commit a2908fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions plugins/outputs/application_insights/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion plugins/outputs/application_insights/application_insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type DiagnosticsMessageSubscriber interface {

type ApplicationInsights struct {
InstrumentationKey string
EndpointURL string
Timeout internal.Duration
EnableDiagnosticLogging bool
ContextTagSources map[string]string
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions plugins/outputs/application_insights/transmitter.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit a2908fb

Please sign in to comment.