microsoft / ApplicationInsights-Go

Microsoft Application Insights SDK for Go
MIT License
157 stars 53 forks source link

Allow setting common arbitrary context properties #6

Closed lmolkova closed 6 years ago

lmolkova commented 7 years ago

All official AI SDKs allow setting arbitrary properties to the context either through TelemetryInititalizers or through TelemetryClient/TelemetryContext api.

E.g. in Node:

appInsights.defaultClient.commonProperties = {
    "Scope": process.env.APPINSIGHTS_APP_CONTEXT_SCOPE
};

Additionally, I'd suggest following .NET SDK approach (whatever will be decided in https://github.com/Microsoft/ApplicationInsights-dotnet/issues/630)

jjjordanmsft commented 7 years ago

Are you referring to default properties on the TelemetryContext (role name, role instance would fall into this bucket) or custom properties on all telemetry items? ApplicationInsights-Go has the former but not the latter. To set the role name+instance for all telemetry submitted, one would need to simply add:

client := appinsights.NewTelemetryClient("<ikey>")
client.Context().Cloud().SetRoleName("role-name")
client.Context().Cloud().SetRoleInstance("role-instance")

I assume that's what you meant as it is what the issue you linked refers to. Setting custom properties on all outgoing telemetry is not currently supported, but I can certainly see the use case for it. (We additionally want to set things like "Resource group" on all telemetry, and there is not a good place to put it in the TelemetryContext).

jjjordanmsft commented 7 years ago

Nevermind, after taking another look I see what you're driving at (the latter). I think that's a reasonable thing to add.